fractalkitty looking for math? fractalkitty.com

100 days of code

areasBetween

#random#trig#classes#interactive#animation#math#codepen-challenge

gArrayGplot

let r = 2,
  g = 0,
  b = 36;
let s;
let gArray = [];
function setup() {
  createCanvas(windowWidth, windowHeight);
  s = int(random(20, 300));
  background(0, 35, 46);
  noStroke();
  for (let i = 0; i < 30; i++) {
    gArray.push(new Gplot(-height / 2 + i * 45));
  }
  angleMode(DEGREES);
}
function draw() {
  background(0, 35, 46);
  translate(width / 2, height / 2);
  for (let i = 0; i < 30; i++) {
    fill(0 + i * 10, 35 + i * 10, 46 + i * 10);
    push();
    translate(50 * sin((i * frameCount) / 50), 50 * cos((i * frameCount) / 10));
    rotate((i * frameCount) / 30 + frameCount / 30);
    gArray[i].display();
    pop();
  }
}

class Gplot {
  constructor(y) {
    this.x = [];
    this.y = [];
    this.x[0] = -width / 2;
    this.y[0] = y;
    this.step = width / s;
    for (let i = 1; i < s; i++) {
      this.x[i] = this.x[i - 1] + this.step + i / 200;
      this.y[i] = this.y[i - 1] + random(-3 - i / 20, 5 + i / 20);
    }
  }
  display() {
    beginShape();
    for (let i = 0; i < s; i++) {
      vertex(this.x[i], this.y[i]);
    }
    for (let i = s - 1; i >= 0; i--) {
      vertex(this.x[i], this.y[i] + 100 * sin(i * 3) * cos(i * 5));
    }
    endShape(CLOSE);
  }
}
function mousePressed() {
  gArray = [];
  s = int(random(20, 400));
  for (let i = 0; i < 30; i++) {
    gArray.push(new Gplot(-height / 2 + i * 45));
  }
}