fractalkitty looking for math? fractalkitty.com

Genuary 2023

genuary11 - in our own time

#random#classes#interactive#animation#geometry#time#genuary

Obj

let sA = [];
let nS;
let pB = true;
let t = 0;
function setup() {
  cnv = createCanvas(500, 500);

  noFill();
  strokeWeight(this.random(0, 10));
  nS = floor(random(1, 15));
  for (let i = 0; i < nS; i++) {
    sA.push(new Obj());
  }
  angleMode(DEGREES);
}
function draw() {
  background(255);
  if (pB) {
    t = second();
  }
  translate(width / 2, height / 2);
  for (let i = 0; i < nS; i++) {
    sA[i].display();
  }
}

class Obj {
  constructor() {
    this.x = random(-width / 5, width / 5);
    this.y = random(-width / 5, width / 5);
    this.type = floor(random(0, 5.99));
    this.size1 = random(20, 200);
    this.size2 = random(20, 200);
    this.color = random(255);
    this.time = random(-3, 3);
  }
  display() {
    fill(this.color);
    push();
    rotate(t * this.time + this.x);
    if (this.type === 0) {
      rect(this.x, this.y, this.size1, this.size2);
    } else if (this.type === 1) {
      rect(this.x, this.y, this.size1 / 5, this.size2 / 5);
    } else if (this.type === 2) {
      circle(this.x, this.y, this.size1);
    } else if (this.type === 3) {
      ellipse(this.x, this.y, this.size1, this.size2);
    } else if (this.type === 4) {
      triangle(
        this.x,
        this.y,
        this.x + this.size1,
        this.y - this.size2,
        this.y + this.size2,
        this.x + this.size1
      );
    } else if (this.type === 5) {
      line(this.x, this.y, this.size1, this.size2);
    }
    pop();
  }
}

function mousePressed() {
  sA = [];
  t = 0;
  setup();
  draw();
}

function keyPressed() {
  pB = !pB;
}