xxxxxxxxxx
82
let flowers = [];
let offset = 1000;
let increment = 0.008;
function keyPressed() {
if (key === ' ') {
save("test.svg");
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
angleMode(DEGREES);
background(0, 0);
// Create a single flower at the center of the canvas
flowers.push(new Flower(width / 2, height / 2));
}
function draw() {
background(0, 8);
for (let flower of flowers) {
flower.update();
flower.display();
}
}
class Flower {
constructor(x, y) {
this.pos = createVector(x, y);
this.symmetry = int(random(4, 16)); // Adjusted to max at 16
this.angle = 360 / this.symmetry;
this.xoff = random(0, 1000);
this.yoff = this.xoff + offset;
this.mx = map(noise(this.xoff), 0, 1, -width*0.6, width*0.6); // Adjusted range
this.my = map(noise(this.yoff), 0, 1, -height*0.6, height*0.6); // Adjusted range
this.px = this.mx;
this.py = this.my;
this.timer = 0;
}
update() {
this.px = this.mx;
this.py = this.my;
this.mx = map(noise(this.xoff), 0, 1, -width*0.8, width*0.8);
this.my = map(noise(this.yoff), 0, 1, -height*0.8, height*0.8);
this.xoff += increment;
this.yoff += increment;
this.timer++;
// Change symmetry based on timer
if (this.timer % 300 === 0) {
increment = random(0.01, 0.02);
offset = random(0, 1000);
this.symmetry = int(random(4, 16));
this.angle = 360 / this.symmetry;
}
}
display() {
push();
translate(this.pos.x, this.pos.y);
let col = color(map(this.timer % 300, 0, 255, 100, 255),
map(sin(this.timer * 0.05), -1, 1, 100, 255),
map(cos(this.timer * 0.05), -1, 1, 100, 255));
stroke(col);
let sw = 2;
strokeWeight(sw);
for (let i = 0; i < this.symmetry; i++) {
rotate(this.angle);
line(this.mx, this.my, this.px, this.py);
push();
scale(1, -1);
line(this.mx, this.my, this.px, this.py);
pop();
}
pop();
}
}