fractalkitty looking for math? fractalkitty.com

Coded Poems

mathober day-30: Removable

#random#trig#image#interactive#animation#accumulates#poem#mathober

img1img2img3holespointsfunc


let img1, img2, img3;
let a, b, c, d;

let holes = [];
let points = [];

function preload() {
  img1 = loadImage("/assets/remove2.jpg");
  img3 = loadImage("/assets/remove1.png");
  img2 = loadImage("/assets/star.png");
}

function setup() {
  createCanvas(600, 600);
  strokeWeight(0.5);
  angleMode(DEGREES);
  stroke(80, 68, 97);
  imageMode(CENTER);
  fill(200, 200, 255, 10);
  a = [];
  b = [];
  c = [];
  d = [];
  for (let i = 0; i < 10; i++) {
    a[i] = random(-1, 1);
    b[i] = random(-160, 160);
    c[i] = random(-1, 1);
    d[i] = random(-160, 160);
  }

  for (let i = 0; i < random(3, 10); i++) {
    holes[i] = int(random(-width / 2, width / 2));
    points[i] = int(random(-width / 3, width / 3));
  }
}

function draw() {
  t1 = frameCount;
  translate(width / 2, height / 2);
  push();
  rotate(t1 / 30);
  image(img1, 0, 0, 900, 900);
  pop();
  push();

  for (let i = 0; i < a.length; i++) {
    rotate(-t1 / 30 - i * 10);
    func(a[i], b[i], c[i], d[i]);
  }
  pop();

  image(img3, 0, 0, 600, 600);
}

function func(a, b, c, d) {
  fill(255);
  beginShape();
  noFill();
  stroke(255);
  for (let i = -width / 2; i < width / 2; i++) {
    vertex(i, f(i, a, b, c, d));
  }
  endShape();
  for (let i = -width / 2; i < width / 2; i++) {
    for (let j = 0; j < holes.length; j++) {
      if (holes[j] == i) {
        fill(45, 74, 79);
        stroke(255);
        circle(i, f(i, a, b, c, d), 7);

        image(img2, i, f(i, a, b, c, d) + points[j] * sin(t1), 50, 50);
      }
    }
  }
}

function f(x, a, b, c, d) {
  return (
    (b * a * sin(a * x + b) +
      c * d * cos(x * c + d + b - t1 / 3) * sin(a * c + d + t1 / 5) +
      b * cos(a * t1) * sin(t1)) *
    sin(t1)
  );
}

function keyPressed() {
  setup();
  draw();
}