fractalkitty looking for math? fractalkitty.com

weekly creative coding

annoyingz catz (TURNZ BACKZ)

#random#trig#vectors#classes#color#sound#interactive#animation#accumulates#animals#wcc

noizcatznCatzeyezmooncraterzstarztimezmakezSkyconjureCatzcatplayNoizezCat

let noiz = [];
let catz = [];
let nCatz, eyez;
let moon;
let craterz = [];
let starz = [];
let timez;
function preload() {
  userStartAudio();
  for (let i = 1; i < 10; i++) {
    noiz[i - 1] = loadSound(
      "/assets/Catz" + i + ".m4a"
    );
  }
}
function setup() {
  cnvz = createCanvas(600, 200);
  nCatz = 9;
  background(0);
  angleMode(DEGREES);
  noStroke();
  for (let i = 0; i < nCatz; i++) {
    catz.push(new Cat(i));
  }
  moon = createVector(0, random(-height / 2.5, -height / 4));
  for (let i = 0; i < 10; i++) {
    craterz[i] = createVector(
      random(-(100 - 255 / 4) / 2, (100 - 255 / 4) / 2),
      random(0, 360),
      random(5, 15)
    );
  }
  for (let i = 0; i < 1000; i++) {
    starz[i] = createVector(
      random(-width, width),
      random(0, 360),
      random(0.5, 2)
    );
  }
}
function draw() {
  timez = frameCount / 2;
  translate(width / 2, height / 2);
  eyez = map(mouseX - width / 2, 0 - width / 2, width - width / 2, -3, 3);
  makezSky();
  fill(20);
  rect(-width, 0, width * 2, height);
  conjureCatz();
  playNoizez();
}
function makezSky() {
  for (let i = 0; i < starz.length; i++) {
    fill(255);
    circle(
      starz[i].x * cos(starz[i].y),
      starz[i].x * sin(starz[i].y),
      starz[i].z
    );
  }
  for (let i = 230; i <= 255; i++) {
    fill(i);
    circle(moon.x, moon.y, 100 - i / 4);
  }
  for (let i = 0; i < craterz.length; i++) {
    fill(200, 200, 200, 30);
    circle(
      moon.x + craterz[i].x * sin(craterz[i].y),
      moon.y + craterz[i].x * cos(craterz[i].y),
      craterz[i].z
    );
  }
}
function conjureCatz() {
  for (let i = 0; i < nCatz; i++) {
    push();
    translate(catz[i].x, height / 4 - catz[i].hz);
    cat(
      catz[i].wz,
      catz[i].hz,
      catz[i].earz,
      catz[i].tailz1,
      catz[i].tailz2,
      catz[i].tailz3,
      catz[i].tailLength,
      catz[i].eyeColor,
      catz[i].noseColor,
      catz[i].catColor,
      catz[i].isMeowz,
      i
    );
    pop();
  }
}
function cat(w, h, e, t1, t2, t3, l, c, n, b, s, num) {
  fill(b);
  rect(0, 0, w, h, 20, 20, 5, 5);

  triangle(e / 2, e, 5, 20, w, 20);
  triangle(-e / 2 + w, e, w - 5, 20, 0, 20);
  for (let i = 0; i < l; i++) {
    circle(
      w - 5 - (t1 * sin(i * t2)) / t3 + i * t2,
      h - 5 + t1 * sin(i * t2) - t3 * cos(t3 * i) * sin(i),
      h / 10
    );
  }

  fill(c);
  circle(10, 0 + 15, 7);
  fill(0);
  ellipse(10 + eyez, 0 + 15, 2, 7);
  fill(c);
  circle(w - 10, 0 + 15, 7);
  fill(0);
  ellipse(w - 10 + eyez, 0 + 15, 2, 7);
  push();
  stroke(b);
  line(w / 2, 20, w - e, 20);
  line(w / 2, 20, w - e, 20 - e);
  line(w / 2, 20, w - e, 20 - e * 2);
  line(w / 2, 20, e, 20);
  line(w / 2, 20, e, 20 - e);
  line(w / 2, 20, e, 20 - e * 2);
  pop();
  fill(n);
  ellipse(w / 2, 20, 5, 2);
  fill(0);
  if (s) {
    circle(w / 2, 25, 2 * sin(timez * 3));
  }
}
function playNoizez() {
  for (let i = 0; i < 9; i++) {
    if (catz[i].isMeowz) {
      if (!noiz[i].isPlaying()) {
        noiz[i].play();
      }
    } else {
      noiz[i].pause();
    }
  }
}
class Cat {
  constructor(i) {
    this.wz = random(40, 60);
    this.hz = random(50, 100);
    this.earz = random(-2, -10);
    this.tailz1 = random(-5, 5);
    this.tailz2 = pow(-1, int(random(-2, 2)));
    this.tailz3 = random(-5, 5);
    this.tailLength = random(50, 100);
    this.eyeColor = color(random(100, 200), random(100, 200), random(100, 200));
    this.noseColor = color(random(50, 100), random(10, 20), random(0, 20));
    this.catColor = color(random(20, 90));
    this.x = -width / 2 + (width / nCatz) * i;
    this.isMeowz = false;
  }
}
function mousePressed() {
  for (let i = 0; i < 9; i++) {
    if (
      mouseX - width / 2 > catz[i].x - 10 &&
      mouseX - width / 2 < catz[i].x + catz[i].wz + 10
    ) {
      catz[i].isMeowz = !catz[i].isMeowz;
    }
  }
}