fractalkitty looking for math? fractalkitty.com

100 days of code

spiralinski_Day30

#random#trig#physics#classes#animation#fractal#spiral

tArraySiermakeFractal

let tArray = [];
let p;
let n=243;
let s = 32,t=0,cnt=0;
function setup() {
  createCanvas(500, 510);
  fill(0);
  makeFractal();
  angleMode(DEGREES)
  noStroke()
}
function draw() {
  translate(width/2,width/2);
  scale(1,-1)
  print(cnt)
  if(t>=360 && cnt<20){
    background(255,255,255,10)
    t=360;
    for(let i=0;i<n;i++){
      tArray[i].displayS()
    }
    frameCount=360;
    cnt = cnt+1
  }
  if (cnt>=20){
    cnt=0;
    frameCount=0;
  }
  if (cnt==0){
    fill(0+100*sin(frameCount))
    background(255,255,255,4)
    t = frameCount/3;
    for (let i=0;i<n;i++){
    tArray[i].move()
    tArray[i].displayS()
    }
  }
}

class Sier{
  constructor(x,y){
    this.x = x
    this.y = y
    this.vx = random(-1,1)
    this.vy = random(-5,5)
    this.x1 = x;
    this.y1 = y;
    this.r = random(-200,200)
  }
  displayS(){
    push()
    rotate(t*4)
triangle(this.x1,this.y1,this.x1+width/s,this.y1,this.x1+width/(s*2),this.y1+width/s)
    pop()
  }
  move(){
    this.x1 = this.x*cos(t)+this.vx*this.r*sin(t)*cos(t)+this.vy*50*sin(t)*sin(t)*cos(t)-this.r*sin(t)*sin(t)*sin(t)*cos(t)+this.r*sin(t)*cos(t)/2
    this.y1 = this.y*cos(t)+this.vy*this.r*sin(t)*cos(t)+this.vy*this.r*sin(t)*cos(t)+100*sin(t)*cos(t)+this.r*sin(t)/10
  }
}

function makeFractal(){
  for (let i=0;i<32;i++){  
    p = new Sier(-width/2+i*width/s,-width/2 +0)
    tArray.push(p);
    if(i%2==0){
      p = new Sier(-width/2+width/(s*2)+i*width/s,-width/2+width/s +0);
      tArray.push(p);
    }
    if(i%4==0){
      p = new Sier(-width/2+2*width/(s*2)+i*width/s,-width/2+2*width/s +0);
      tArray.push(p);
      p = new Sier(-width/2+2*width/(s*2)+(i+1)*width/s,-width/2+2*width/s +0);
      tArray.push(p);
      p = new Sier(-width/2+3*width/(s*2)+i*width/s,-width/2+3*width/s +0);
      tArray.push(p);
      
    }
    if(i%8==0){
      for(let j=0;j<4;j++){
        p = new Sier(-width/2+4*width/(s*2)+(i+j)*width/s,-width/2+4*width/s +0);
        tArray.push(p);
        if(j%2==0){
          p = new Sier(-width/2 +5*width/(s*2)+(i+j)*width/s,-width/2 +5*width/s +0);
          tArray.push(p);
          if(j==0){
            p = new Sier(-width/2+6*width/(s*2)+(i+j)*width/s,-width/2+6*width/s +0);
            tArray.push(p);
            p = new Sier(-width/2+6*width/(s*2)+(i+j+1)*width/s,-width/2+6*width/s +0);
            tArray.push(p);
            p = new Sier(-width/2+7*width/(s*2)+(i+j)*width/s,-width/2+7*width/s +0);
          tArray.push(p);
          }
        } 
      }  
    }
    if(i<8 ||(i >15&&i<24)){
      p = new Sier(-width/2+8*width/(s*2)+(i)*width/s,-width/2+8*width/s +0);
      tArray.push(p);
      if(i%2==0){
        p = new Sier(-width/2+9*width/(s*2)+i*width/s,-width/2+9*width/s +0);
        tArray.push(p);
      }
      if(i%4==0){
        p = new Sier(-width/2+10*width/(s*2)+i*width/s,-width/2+10*width/s +0);
        tArray.push(p);
        p = new Sier(-width/2+10*width/(s*2)+(i+1)*width/s,-width/2+10*width/s +0);
        tArray.push(p);
        p = new Sier(-width/2+11*width/(s*2)+i*width/s,-width/2+11*width/s +0);
        tArray.push(p); 
      }
      if(i%8==0){
        for(let j=0;j<4;j++){
          p = new Sier(-width/2+12*width/(s*2)+(i+j)*width/s,-width/2+12*width/s +0);
          tArray.push(p);
          if(j%2==0){
            p = new Sier(-width/2+13*width/(s*2)+(i+j)*width/s,-width/2+13*width/s +0);
            tArray.push(p);
            if(j==0){
              p = new Sier(-width/2+14*width/(s*2)+(i+j)*width/s,-width/2+14*width/s +0);
              tArray.push(p);
              p = new Sier(-width/2+14*width/(s*2)+(i+j+1)*width/s,-width/2+14*width/s +0);
              tArray.push(p);
              p = new Sier(-width/2+15*width/(s*2)+(i+j)*width/s,-width/2+15*width/s +0);
            tArray.push(p);
            }
          }
        }
      }
      
    }
    if(i<16){
      p = new Sier(-width/2+16*width/(s*2)+(i)*width/s,-width/2+16*width/s);
      tArray.push(p);
      if(i%2==0){
        p = new Sier(-width/2+17*width/(s*2)+i*width/s,-width/2+17*width/s);
        tArray.push(p);
      }
      if(i%4==0){
        p = new Sier(-width/2+18*width/(s*2)+i*width/s,-width/2+18*width/s);
        tArray.push(p);
        p = new Sier(-width/2+18*width/(s*2)+(i+1)*width/s,-width/2+18*width/s +0);
        tArray.push(p);
        p = new Sier(-width/2+19*width/(s*2)+i*width/s,-width/2+19*width/s);
        tArray.push(p); 
      }
      if(i%8==0){
        for(let j=0;j<4;j++){
          p = new Sier(-width/2+20*width/(s*2)+(i+j)*width/s,-width/2+20*width/s +0);
          tArray.push(p);
          if(j%2==0){
            p = new Sier(-width/2+21*width/(s*2)+(i+j)*width/s,-width/2+21*width/s +0);
            tArray.push(p);
            if(j==0){
              p = new Sier(-width/2+22*width/(s*2)+(i+j)*width/s,-width/2+22*width/s +0);
              tArray.push(p);
              p = new Sier(-width/2+22*width/(s*2)+(i+j+1)*width/s,-width/2+22*width/s +0);
              tArray.push(p);
              p = new Sier(-width/2+23*width/(s*2)+(i+j)*width/s,-width/2+23*width/s +0);
            tArray.push(p);
            }
          }
        } 
      }
      
    }
    if(i<8){
       p = new Sier(-width/2+24*width/(s*2)+(i)*width/s,-width/2+24*width/s +0);
      tArray.push(p);
      if(i%2==0){
        p = new Sier(-width/2+25*width/(s*2)+i*width/s,-width/2+25*width/s +0);
        tArray.push(p);
      }
      if(i%4==0){
        p = new Sier(-width/2+26*width/(s*2)+i*width/s,-width/2+26*width/s +0);
        tArray.push(p);
        p = new Sier(-width/2+26*width/(s*2)+(i+1)*width/s,-width/2+26*width/s +0);
        tArray.push(p);
        p = new Sier(-width/2+27*width/(s*2)+i*width/s,-width/2+27*width/s +0);
        tArray.push(p); 
      }
      
    }
    if(i<4){
      p = new Sier(-width/2+28*width/(s*2)+(i)*width/s,-width/2+28*width/s +0);
      tArray.push(p);
      if(i%2==0){
        p = new Sier(-width/2+29*width/(s*2)+i*width/s,-width/2+29*width/s +0);
        tArray.push(p);
      }
      if(i%4==0){
        p = new Sier(-width/2+30*width/(s*2)+i*width/s,-width/2+30*width/s +0);
        tArray.push(p);
        p = new Sier(-width/2+30*width/(s*2)+(i+1)*width/s,-width/2+30*width/s +0);
        tArray.push(p);
        p = new Sier(-width/2+31*width/(s*2)+i*width/s,-width/2+31*width/s +0);
        tArray.push(p); 
      }
    }
    
  }

}