fractalkitty looking for math? fractalkitty.com

100 days of code

polygonMitosis

#trig#animation#math#geometry

dancePpolygonangle

let n=0;
let d=true;
function setup(){
  createCanvas(windowWidth,windowHeight);
  stroke(255);
  strokeWeight(3)
}
function draw(){
  background(0,100,150);
  translate(width/2,height/2);
  push()
  rotate(frameCount/500)
  danceP()
  pop()
  push()
    scale(1/3,1/3);
    translate(-width/1.1,-height/1.1)
    danceP()
  pop()
  push()
    scale(1/3,1/3);
    translate(width/1.1,height/1.1)
    danceP()
  pop()
  if (d==true){
    n=n+0.01
  }
  if (d==false){
    n=n-0.01
  }
  if (n>50){
    d=false;
  }
  if (n<0){
    d=true;
  }
}
function danceP(){
  for(let i=0;i<n;i++){
    push() 
    fill(255,255,255,2)
    rotate(i*(TWO_PI)/n);
    translate(width/8,0);
    polygon(0,0,width/8,n)
    pop()
  }
}
function polygon(x, y, radius, npoints) {
  let angle = TWO_PI / npoints;
  beginShape();
  for (let a = 0; a < TWO_PI; a += angle) {
    let sx = x + cos(a) * radius;
    let sy = y + sin(a) * radius;
    vertex(sx, sy);
  }
  endShape(CLOSE);
}