fractalkitty looking for math? fractalkitty.com

borbs

Defuse the Budgie

#trig#image#sound#interactive#animation#animals#music

vibeplanetssynthisPlaying

let vibe;
let planets;
let synth;
let isPlaying = false;

function preload() {
  vibe = loadImage("/assets/vibebudgie.png");
  synth = loadSound("/assets/synth2.m4a");
}

function setup() {
  w = min(windowWidth, windowHeight);
  createCanvas(w, w);
  planets = [];
  noStroke();
  m = round(max(windowWidth, windowHeight));
  imageMode(CENTER);
  synth.setLoop(true);

}

function draw() {
  if (isPlaying) {
    t = frameCount / 50;
  } else {
    t = 0;
    frameCount = 0;
  }

  n = 100;
  translate(width / 2, height / 2);
  background(201, 0, 188);

  strokeWeight(4);
  noFill();
  for (let i = 0; i < m * 1.8; i += 4) {
    stroke(201 - i / 2, 0, 188 - i / 4);

    circle(0, 0, i * 2);
  }
  tint(255, 50 * abs(cos(t / 5)));
  push();
  scale(cos(t / 5), cos(t / 5));
  image(vibe, 0, -w / 6, w * 1.8, w * 2);
  pop();

  stroke(
    17 + abs(cos(t / 4)) * 150,
    abs(cos(t / 4)) * 150,
    66 + abs(cos(t / 4)) * 150,
    50
  );
  strokeWeight(2);

  for (let i = 0; i < n; i += 0.2) {
    line(
      0,
      0,
      -width * 20 + (i * width * 150) / n + ((200 * t) % ((width * 300) / n)),
      height / 2
    );
    line(
      0,
      0,
      -width * 20 + (i * width * 150) / n + ((-200 * t) % ((width * 300) / n)),
      -height / 2
    );
  }
  for (let i = 1; i < 100; i += 10) {
    arc(0, 0, i * 20, i * 10, PI / 100, PI - PI / 100);
    arc(0, 0, i * 20, i * 10, PI / 100 + PI, -PI / 100);
  }
  stroke(255);
  if (!isPlaying) {
    triangle(-w / 3, -w / 3, -w / 3, w / 3, w / 3, 0);
  }
}
function windowResized() {
  setup();
  draw();
}

function mousePressed() {
  if (isPlaying) {
    synth.stop();
  } else {
    synth.play();
  }
  isPlaying = !isPlaying;
}