fractalkitty looking for math? fractalkitty.com

Genuary 2024

10,000 petals

#random#trig#vectors#interactive#animation#accumulates#polar#plants#genuary

petalborder


function setup() {
  cnv = createCanvas(600, 600);
  rectMode(CENTER);
  angleMode(DEGREES);
  cnt = 0;
  background(255);
  ni = random([4, 5, 10, 20, 25, 40, 50, 100]);
}

function draw() {
  translate(width / 2, height / 2);
  t = frameCount;
  pos = createVector(
    random(-width / 3.5, width / 3.5),
    random(-height / 3.5, height / 3.5)
  );
  angle = random(360);
  sc = randomGaussian(0, 0.15);
  r1 = random(-20, 20);
  g1 = random(-20, 20);
  b1 = random(-20, 20);
  if (cnt < 10000) {
    for (let i = 0; i < ni; i++) {
      push();

      rotate((360 / ni) * i);
      translate(pos.x, pos.y);
      rotate(180);
      scale(sc);
      petal(r1, g1, b1);
      pop();
    }
    cnt += ni;
  }
  border();
}

function petal(r, g, b) {
  noStroke();
  push();
  scale(0.5);
  for (let i = 0; i < 18; i++) {
    push();
    fill(r + 153 + i * 3, g + 24 + i * 6, b + 75 + i * 6);
    translate(0, i * 5);
    ellipse(0, 0, 50 * sin(i * 10));
    pop();
  }
  pop();
}

function border() {
  noFill();
  stroke(163, 51, 96);
  strokeWeight(4);
  rect(0, 0, width - 20, height - 20);
}

function mousePressed() {
  frameCount = 0;
  setup();
  draw();
}

function keyPressed() {
  save(cnv, "ten-thousand-petals", "jpg");
}