xxxxxxxxxx
let rows, cols, scale;
function setup() {
createCanvas(1500, 500);
colorMode(HSB);
scale = max(width, height) / 50;
rows = ceil(height / scale);
cols = ceil(width / scale);
generateField();
}
let field = [];
function generateField() {
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
if (field[i] === undefined) field[i] = [];
let v = createVector(i + j, j - i - 10);
v = createVector(2 * i + 4 * j, j - i - i - 10);
field[i][j] = v;
}
}
}
function draw() {
background([273, 9, 25]);
noStroke();
let basecolor = color([54,20,100,0.5]);
push();
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
const v = field[i][j];
const fc = color([273, 0, map(sin(v.heading()), -1, 1, 0, 60)]);
fill(fc);
rect(i * scale, j * scale, scale, scale);
}
push();
stroke([0, 0, 90, 0.2]);
line(i * scale, 0, i * scale, height);
pop();
}
pop();
strokeWeight(2);
stroke(basecolor);
fill(basecolor);
push();
translate(0, height / 2);
for (let x = -50; x <= width + 50; x += 20) {
push();
let y = pow(sin(x),11)/(pow(sin(x),4) + pow(cos(x),3));
y = (height * 0.24) * y;
const s = map((x / width), 0, 1, 0.1, 0.8) * scale;
fill(basecolor);
if (y > 0) {
noFill()
}
circle(x, y, s);
pop()
}
pop();
noFill()
strokeWeight(8);
stroke([0, 0, 90]);
rect(0, 0, width, height);
noLoop()
}