fractalkitty looking for math? fractalkitty.com

Genuary 2022

stretchy bike

#random#trig#vectors#animation#math#genuary

starsnstarsyposdrawStars

let a = 20;
let t = 0;
let stars = [];
let nstars = 2000;
function setup() {
  createCanvas(800, 80);
  drawStars(0, nstars);
}

function draw() {
  background(20);
  drawStars(1, nstars);
  t = frameCount;
  fill(0, 80, 20);
  beginShape();
  vertex(0, height);
  for (let i = 0; i < width; i++) {
    x = i;
    y = ypos(i);
    vertex(x, y);
  }
  vertex(width, height);
  endShape();
  stroke(150);
  strokeWeight(0.5);
  for (let i = 0; i < 4; i++) {
    line(
      width / 2 + 5 * sin((i * PI) / 4 - t / 6),
      ypos(width / 2) - 5 + 5 * cos((i * PI) / 4 - t / 6),
      width / 2 + 5 * sin((i * PI) / 4 + PI - t / 6),
      ypos(width / 2) - 5 + 5 * cos((i * PI) / 4 + PI - t / 6)
    );
    line(
      width / 2 + 10 + 5 * sin((i * PI) / 4 - t / 6),
      ypos(width / 2 + 10) - 5 + 5 * cos((i * PI) / 4 - t / 6),
      width / 2 + 10 + 5 * sin((i * PI) / 4 + PI - t / 6),
      ypos(width / 2 + 10) - 5 + 5 * cos((i * PI) / 4 + PI - t / 6)
    );
  }
  noFill();
  circle(width / 2, ypos(width / 2) - 5, 10);
  circle(width / 2 + 10, ypos(width / 2 + 10) - 5, 10);

  line(
    width / 2,
    ypos(width / 2) - 10,
    width / 2 + 10,
    ypos(width / 2 + 10) - 10
  );
  stroke(60, 130, 190);
  strokeWeight(1);
  line(
    width / 2 + 10,
    ypos(width / 2 + 10) - 10,
    width / 2 + 5,
    ypos(width / 2 + 10) - 12
  );
  line(
    width / 2 + 5,
    ypos(width / 2 + 5) - 18,
    width / 2 + 5,
    ypos(width / 2 + 5) - 10
  );
  line(
    width / 2 + 5,
    ypos(width / 2 + 5) - 18,
    width / 2 + 8,
    ypos(width / 2 + 8) - 10
  );
  line(
    width / 2 + 5,
    ypos(width / 2 + 5) - 10,
    width / 2 + 7,
    ypos(width / 2 + 7) - 3 * sin(t / 3) - 7
  );
  line(
    width / 2 + 7,
    ypos(width / 2 + 7) - 3 * sin(t / 3) - 7,
    width / 2 + 5 + 2 * sin(t / 3),
    ypos(width / 2 + 5) + 2 * cos(t / 3) - 2
  );
  fill(60, 130, 190);
  circle(width / 2 + 5, ypos(width / 2 + 5) - 18, 4);

  stroke(0);
}

function ypos(i) {
  y =
    a * sin(i / 50 + t / 50) * cos(i / 20 + t / 20) +
    5 * sin(i / 20 + t / 20) * sin(i / 10 + t / 10) -
    4 * sin(i / 10 + t / 10) * sin(i / 30 + t / 30) +
    40;
  return y;
}

function drawStars(k, nstars) {
  if (k === 0) {
    for (let i = 0; i < nstars; i++) {
      stars[i] = createVector(random(-800, 800), random(-800, 800));
    }
  }
  push();
  stroke(255);
  rotate(t / 2000);
  for (let i = 0; i < nstars; i++) {
    point(stars[i].x, stars[i].y);
  }
  pop();
}