fractalkitty looking for math? fractalkitty.com

Genuary 2022

Ersatz Fidenza

#random#trig#classes#interactive#math#flow-field#genuary

fArrayamp1amp2amp3cVarmodeFmaker

let t = 0;
let fArray = [];
let amp1, amp2, amp3;
let cVar;
let mode = 0;
let rm;
function setup() {
  createCanvas(windowWidth, windowHeight);
  fill(0);
  angleMode(DEGREES);
  stroke(0);
  background(255);
  cVar = random(0, 100);
  n = int(random(50, 300));
  if (mode === 4) {
    n = n * 6;
  }
  for (i = 0; i < n; i++) {
    fArray.push(
      new Fmaker(
        random(-width / 2 - 100, width / 3),
        -height / 2 + random(-200, height + 200)
      )
    );
    rm = random(0.99, 1.01);
  }
  amp1 = random(-50, 50);
  amp2 = random(-100, 100);
  amp3 = random(-100, 100);
  loop();
}

function draw() {
  translate(width / 2, height / 2);
  t = frameCount;
  if (t < width / 2) {
    for (let i = 0; i < n; i++) {
      fArray[i].move();
      fArray[i].display();
    }
  } else {
    noLoop();
  }
}

class Fmaker {
  constructor(x, y) {
    this.t = random(-520, 520);
    this.r = random(0, width);
    this.x1 = x;
    this.y1 = y;
    this.stop = random(20, width);
    this.x = x;
    this.y = y;
    this.h = random(-20, 20);
    this.c1 = color(
      random(0, 200),
      random(10, 200),
      random(20, 250),
      random(50, 250)
    );
    this.c2 = color(
      random(0, 200),
      random(10, 200),
      random(20, 250),
      random(50, 250)
    );
    this.c3 = color(
      random(0, 200),
      random(10, 200),
      random(20, 250),
      random(50, 250)
    );
    this.c4 = color(
      random(0, 200),
      random(10, 200),
      random(20, 250),
      random(50, 250)
    );
    this.c5 = color(
      random(0, 200),
      random(100, 200),
      random(100, 250),
      random(50, 250)
    );
  }
  move() {
    if (this.x < this.x1 + this.stop) {
      strokeWeight(1);
      if (mode === 0 || mode === 2) {
        this.x++;
        this.y =
          this.y1 +
          amp1 * sin(this.x) * cos(this.x) -
          amp2 * cos(this.x / 2) +
          amp3 * cos(this.x / 4);
      } else if (mode === 1) {
        this.t += 0.2;
        this.h = 2;
        push();
        this.x = this.r * sin(this.t / 2);
        this.y = this.r * cos(this.t / 2);
        pop();
        this.r = this.r * rm;
      } else if (mode === 3) {
        this.h = 2;
        this.x++;
        this.y = this.y1;
      } else if (mode === 4) {
        this.h = 1;
        this.t += 0.15;
        this.x =
          this.r * 2 * sin(this.t / 10) * cos(this.t / 2) -
          (this.r / 4) * cos(this.t / 2) * cos(this.t / 3);
        this.y =
          this.r * 2 * cos(this.t / 3) +
          (this.r / (int(amp1 % 5) + 1)) *
            cos(this.t / 5 - amp1) *
            sin(-this.t / 6);
      } else {
        this.x = this.y;
        this.y++;
      }
    }
  }
  display() {
    noStroke();
    if (this.x <= this.x1 + this.stop / 7) {
      stroke(this.c1);
    } else if (this.x < this.x1 + this.stop / 5) {
      stroke(this.c2);
    } else if (this.x < this.x1 + this.stop / 3) {
      stroke(this.c3);
    } else if (this.x < this.x1 + this.stop / 1.5) {
      stroke(this.c4);
    } else if (this.x < this.x1 + this.stop / 1.2) {
      stroke(this.c5);
    } else {
      noStroke();
    }
    push();
    if (mode === 1 || mode === 2) {
      rotate(this.t);
    }

    line(this.x, this.y, this.x, this.y + this.h);
    pop();
  }
}

function windowResized() {
  mousePressed();
}

function mousePressed() {
  frameCount = 0;
  fArray = [];
  setup();
  draw();
}

function keyPressed() {
  if (mode < 4) {
    mode++;
  } else {
    mode = 0;
  }
  mousePressed();
}