fractalkitty looking for math? fractalkitty.com

100 days of code

trackingLight

#trig#classes#animation#accumulates#parametric

Building

let p = []
n = 25;
let t=0;
let x,y;

function setup() {
  createCanvas(windowWidth, windowHeight);
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < n; j++) {
      p.push(new Building(-width / 2 + i * width / n+width/(2*n), -height / 2 + j * height / n+height/(2*n)));
    }
  }
  fill(255)
  angleMode(DEGREES)
  stroke(255)
  strokeWeight(0.1)
}

function draw() {
  t=frameCount
  translate(width / 2, height / 2);
  x=200*sin(t)-100*cos(t/2)*sin(t)+100*sin(t)*sin(t);
  y=200*cos(t)+150*sin(t)*sin(t);
  for (let i = 0; i < n * n; i++) {
    dy=(p[i].y-y);
    dx=(p[i].x-x);
    tx = -dx/30
    ty =- dy/30
    p[i].display(tx,ty);
  }
  noStroke()
  fill(255,255,255)
  circle(x,y,15)
}

class Building {
  constructor(a, b) {
    this.x = a;
    this.y = b;

  }
  display(g,h) {
    for(let k=1;k<14;k++){
      fill(k*22,k*25,k*35,30)
      ellipse(this.x+k*g, this.y + k*h, width / (k/2 * n), height / (k/2 * n));
    }
  }
}