fractalkitty looking for math? fractalkitty.com

100 days of code

butterflyCurve_Day28

#trig#animation#math#polar#parametric

let r=70,
    a=4,
    b=0.01;
function setup() {
  createCanvas(800, 800);
  angleMode(DEGREES);
  strokeWeight(0.1);
}

function draw() {
  translate(width/2,width/2);
  scale(1,-1);
  background(150,150,200,15);
  time=frameCount/10;
  b = 0.5*sin(time)+12*cos(time)*cos(time)*cos(time)*cos(time);
  a = 0.5*sin(time)+4*cos(time)*cos(time)*cos(time)*cos(time);
  fill(200,100,50,2);
  beginShape();
    for (let i=0;i<360;i++){
      t=i;
      x = sin(t)*(exp(cos(t))-2*cos(4*t)+pow(sin(1/12*t),5));
      y = cos(t)*(exp(cos(t))-2*cos(4*t)+pow(sin(1/12*t),5));
      vertex(r*x,r*y-70);
    }
  endShape(CLOSE);
  stroke(255)
  fill(252, 186, 3,5)
  for(let j=1;j<35;j++){
    r=r-2;
    beginShape();
    for (let i=0;i<360;i++){
      t=i;
      x = sin(t)*(exp(cos(t))-2*cos(a*t)+pow(sin(1/b*t),5));
      y = cos(t)*(exp(cos(t))-2*cos(a*t)+pow(sin(1/b*t),5));
      vertex(r*x,r*y-70);
    }
    endShape(CLOSE);
  }
  r = 80;
  push()
  scale(-1,1);
  for(let j=1;j<35;j++){
    r=r-2;
    beginShape();
    for (let i=0;i<360;i++){
      t=i;
      x = sin(t)*(exp(cos(t))-2*cos(a*t)+pow(sin(1/b*t),5));
      y = cos(t)*(exp(cos(t))-2*cos(a*t)+pow(sin(1/b*t),5));
      vertex(r*x,r*y-70);
    }
    endShape(CLOSE);
  }
  pop()
  r = 80;
}