fractalkitty looking for math? fractalkitty.com

early works

packing play

#trig#interactive#animation#study#geometry#scrap

cSwitchrunSwitchpChainpolygonangle

let R=1;
let cSwitch=false;
let runSwitch=true;
let p=0;
function setup(){
  createCanvas(windowWidth,windowHeight);
  angleMode(DEGREES);
  stroke(255);
  strokeWeight(0.001)
}
function draw(){
  background(0);
  translate(width/2,height/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,50)
  if (cSwitch){
    fill(0,200,200,30);
  } 
  circle(0,0,R);
  polygon(0,0,R/2,6)
  fill (0,200,200,50);
  if (cSwitch){
    fill(255,255,255,10);
  }
  t=frameCount/10;
    rotate(t*4)
  CB=sin(t);
  circle(R/2-CB/2,0,CB);
  polygon(R/2-CB/2,0,CB/2,6)
  AC=R-CB
  circle(-R/2+AC/2,0,AC)
  polygon(-R/2+AC/2,0,AC/2,6)
  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)
    polygon(xn,yn,rn,6)
    circle(xn,-yn,2*rn)
    polygon(xn,-yn,rn,6)
  }
}
function polygon(x, y, radius, npoints) {
  let angle = 360 / npoints;
  beginShape();
  for (let a = 0; a < 360; a += angle) {
    let sx = x + cos(a) * radius;
    let sy = y + sin(a) * radius;
    vertex(sx, sy);
  }
  endShape(CLOSE);
}