xxxxxxxxxx
74
let flowers = [];
function keyPressed() {
if (key === ' ') {
save("test.svg");
}
}
function setup() {
createCanvas(windowWidth, windowHeight,SVG);
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() {
for (let flower of flowers) {
flower.update();
flower.display();
}
}
class Flower {
constructor(x, y) {
this.pos = createVector(x, y);
this.symmetry = 6
this.angle = 360 / this.symmetry;
this.xoff = random(0, 1000);
this.yoff = this.xoff + 1000;
this.mx = map(noise(this.xoff), 0, 1, -width / 2, width / 2); // Updated range
this.my = map(noise(this.yoff), 0, 1, -height / 2, height / 2); // Updated range
this.px = this.mx;
this.py = this.my;
this.growthStopped = false;
this.timer = 0;
}
update() {
if (!this.growthStopped) {
this.px = this.mx;
this.py = this.my;
this.mx = map(noise(this.xoff), 0, 1, -width / 2, width / 2); // Updated range
this.my = map(noise(this.yoff), 0, 1, -height / 2, height / 2); // Updated range
this.xoff += 0.02;
this.yoff += 0.02;
this.timer++;
if (this.timer > 200) {
this.growthStopped = true;
}
}
}
display() {
push();
translate(this.pos.x, this.pos.y);
stroke(0); // Solid white
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();
}
}