fractalkitty looking for math? fractalkitty.com

weekly creative coding

poured over and filtered

#noise#random#trig#vectors#classes#interactive#spiral#symmetry#polar#wcc

nf1nf2nArraynoiseCircletheta

let nf1, nf2;
let d;
let nArray = [];
let t = 0;
let cnt;
function setup() {
  nf1 = random([-1, 1]) * random(0.0007, 0.01);
  nf2 = random(20, 100) * random([-1, 1]);
  w = min(windowWidth, windowHeight) * 0.9;
  cnv = createCanvas(windowWidth, windowHeight);
  background(179, 140, 89);
  noCursor();
  d = w * 0.8;
  circ = { x: 0, y: 0, r: random(w / 3, w / 2) / 2 };
  nArray.push(new noiseCircle(circ.r, circ.x, circ.y));
  noStroke();
  describe(
    "a spiral of grounds of coffee moving and fading in patterns where the closest seem blurred and the center is in focus and gets too small to see. It makes a spiral mandala. The background is tan coffee filter and the drawing is coffee colored. "
  );
}
function draw() {
  background(179, 140, 89, 2);
  translate(width / 2, height / 2);
  nArray[0].move();
  if (frameCount > 800) {
    noLoop();
  }
}

class noiseCircle {
  constructor(r, x, y) {
    this.x = x;
    this.y = y;
    this.p = [];
    this.r = r;
    this.n = 0;
    this.t = 0;
    this.np = 500;
    for (let i = 0; i < this.np; i++) {
      let theta = random(0, TWO_PI);
      if (i % 10 === 0) {
        this.p[i] = createVector(
          randomGaussian(0, d / 5) + this.r * sin(theta),
          randomGaussian(0, d / 5) + this.r * cos(theta)
        );
      } else {
        this.p[i] = createVector(
          randomGaussian(0, d / 50) + this.r * sin(theta),
          randomGaussian(0, d / 50) + this.r * cos(theta)
        );
      }
    }
  }
  move() {
    strokeWeight(this.r / 300);
    push();
    translate(this.x, this.y);
    fill(
      64 * sin(this.t / 800),
      39 * sin(this.t / 800),
      7 * sin(this.t / 800),
      cos(t) * 2
    );
    this.t++;
    for (let i = 0; i < this.np; i++) {
      this.n =
        noise(nf1 * this.p[i].x * cos(t), nf1 * this.p[i].y * cos(t)) * nf2;

      this.p[i].add(
        cos(this.n) * sin(this.n / 2 + random(-d * 2, d * 2)),
        sin(this.n) * cos(this.n / 2)
      );
      for (let sc = 1; sc < 40; sc += 1.5) {
        push();
        scale(2 / sqrt(sc * 1.5), 2 / sqrt(sc * 1.5));
        rotate(((PI * 2) / 20) * sc);
        circle(
          this.p[i].x,
          this.p[i].y,
          1 +
            cos(t) *
              4 *
              cos(t / 2 - (this.p[i].y * this.p[i].x) / (nf2 * nf2)) -
            3 * cos(t / 3)
        );
        pop();
      }
    }
    pop();
  }
}

function keyPressed() {
  if (keyCode === 32) {
    nArray = [];
    t = 0;
    cnt = 0;
    cBool = true;
    frameCount = 0;
    setup();
    loop();
    draw();
  }
  if (keyCode === 83) {
    save(cnv, "filtered", "png");
  }
}