fractalkitty looking for math? fractalkitty.com

100 days of code

eyeOfPappusChain

#trig#interactive#animation#math#geometry

cSwitchrunSwitchpChain

let R=1;
let cSwitch=false;
let runSwitch=true;
let p=6;
function setup(){
  createCanvas(600,600);
  angleMode(DEGREES);
  stroke(255);
  strokeWeight(0.001)
}
function draw(){
  background(0);
  translate(width/2,width/2);
  scale(400,400);
  for(let i=0;i<p;i++){
    push()
    rotate(360/p*i);
    translate(0.5,0.5);
    pChain();
    pop();
  }
  
  pChain();
  if (t%90==0){
    cSwitch=!cSwitch; 
  }
}
function mousePressed(){
  p=p+1
  if (p>25){
    p=0;
  }
}
function pChain(){
  fill(255,255,255,20)
  if (cSwitch){
    fill(0,100,200,20);
  } 
  circle(0,0,R);
  fill (0,100,200,20);
  if (cSwitch){
    fill(255,255,255,20);
  }
  t=frameCount/10;
    rotate(t*4)
  CB=sin(t);
  circle(R/2-CB/2,0,CB);
  AC=R-CB
  circle(-R/2+AC/2,0,AC)
  n=0
  r=AC/R
  for(let i=1;i<50;i++){
    n=n+1
    xn=-0.5+(r*(1+r))/(2*(n*n*(1-r)*(1-r)+r));
    yn=(r*n*(1-r))/(n*n*pow(1-r,2)+r);
    rn=((1-r)*r)/(2*(n*n*(1-r)*(1-r)+r));
    circle(xn,yn,2*rn)
    circle(xn,-yn,2*rn)
  }
}