xxxxxxxxxx
142
// Define an array to hold mover objects
let movers = [];
// Number of mover objects to create
let moversQuantity = 100;
// Variables to control animation
let t; // Time variable
let rotationang; // Rotation angle variable for one of the shapes
function setup() {
createCanvas(400, 400);
// Initialize time and rotation angle
t = 0;
rotationang = 0;
// Generate a random scale factor for shapes
let shapeScale = random(0.2, 2);
// Create an array of mover objects with random positions and sizes
for (i = 0; i < moversQuantity; i++) {
movers[i] = new Mover(
random(width),
random(height),
random(0.005, 5 * shapeScale)
);
// Give each mover a random vertical velocity
movers[i].vel.y = random(-2, 2);
}
}
function draw() {
background(0,65);
push();
// Translate the origin to the center of the canvas
translate(width / 2, height / 2);
// Draw a dynamic shape with changing fill and stroke colors
fill(255 * cos(t / 75));
// noFill();
stroke(255 * sin(t / 600*sin(t/100)));
strokeWeight(0.3);
// stroke(255);
beginShape();
for (let x = 0; x <= TWO_PI; x += PI / 30) {
for (let o = 0; o <= TWO_PI; o += PI / 3) {
vertex(
(200) * cos(t / 70 + x - o) * cos(x),
(200) * sin(t / 30 - x + o / 2) * sin(x)
);
}
}
endShape();
pop();
// Loop through the mover objects
for (let i = 0; i < movers.length; i++) {
// Attract each mover to other movers
for (let o = 0; o < movers.length; o++) {
if (i !== o) {
movers[o].attract(movers[i]);
}
}
// Render each mover
movers[i].render();
}
push();
translate(width / 2, height / 2);
// Drawing Shapes using the same basic structure of the beginShape() function, a for loop, and varying uses of the sine * cosine functions to draw verticies.
fill(255, 120*cos(t/80));
strokeWeight(1);
beginShape();
for (let x = 0; x <= TWO_PI; x += PI / 30) {
vertex(50 * cos(x), 50 * sin(x));
}
endShape();
fill(8, 9);
beginShape();
for (let x = 0; x <= TWO_PI; x += PI / 70) {
vertex(
300 * cos(x) * (noise(t / 30) * random(0.9, 1.1)),
300 * sin(x) * noise(t / 60 + 686798)
);
}
endShape();
strokeWeight(0.3);
stroke(255, 40 * noise(t / 100));
noFill();
stroke(255 * sin(t / 66) + 1, 255 * sin(t / 22) + 1, 255 * sin(t / 11) + 1);
strokeWeight(2 * sin(t / 30) + 1);
beginShape();
for (let x = 0; x <= TWO_PI; x += PI / 100) {
vertex(
100 * sin(t / 40 + x * TWO_PI) * cos(x),
100 * sin(t / 10 + x * TWO_PI) * sin(x)
);
}
endShape();
fill(255 * cos(t / 12));
stroke(255 * sin(t / 12));
strokeWeight(1);
beginShape();
for (let x = 0; x <= TWO_PI; x += PI / 30) {
vertex(50 * sin(t / 300 + x) * cos(x), 50 * sin(t / 30 + x) * sin(x));
}
endShape();
fill(200, 255, 200, 255 * sin(t / 50));
stroke(255 * sin(t / 28), 255 * sin(t / 100));
strokeWeight(2 * sin(t / 5));
beginShape();
rotationang += 0.005;
rotate(rotationang);
for (let x = 0; x < TWO_PI; x += 0.5) {
for (let y = 0; y < TWO_PI; y += 0.5) {
vertex(100 * sin(t / 5) * sin(t / 20 + x), 100 * sin(t / 20 + y));
}
}
endShape();
fill(255 * cos(t / 6));
stroke(255 * sin(t / 6));
strokeWeight(1);
beginShape();
for (let x = 0; x <= TWO_PI; x += PI / 30) {
vertex(100 * sin(t / 30 + x) * cos(x), 100 * sin(t / 30 + x * 2) * sin(x));
}
endShape();
t++;
pop();
}