fractalkitty looking for math? fractalkitty.com

100 days of code

dayNight

#trig#animation#codepen-challenge

hillspHole

let c = 250;
function setup() {
  cnv = createCanvas(500, 500);
}
function draw() {
  t = frameCount / 1.5;
  background(0 + c * sin(t + 90), 255 + c * sin(t + 90), 251 + c * sin(t + 90));
  translate(width / 2, height / 2);
  scale(1, -1);
  angleMode(DEGREES);
  fill(255, 251, 0);
  circle(160 * sin(t), 160 * cos(t), 150);
  fill(251 + c * sin(t + 90), 0 + c * sin(t + 90), 255 + c * sin(t + 90));
  hills(70, 100, t / 5, 0.3);
  fill(255 + c * sin(t + 90), 251 + c * sin(t + 90), 0 + c * sin(t + 90));
  hills(40, 50, t / 3, 0.5);
  fill(0 + c * sin(t + 90), 255 + c * sin(t + 90), 251 + c * sin(t + 90));
  hills(25, 22, t / 2, 0.8);
  fill(251 + c * sin(t + 90), 0 + c * sin(t + 90), 255 + c * sin(t + 90));
  hills(0, 20, t, 0.9);
  fill(255 + c * sin(t + 90), 251 + c * sin(t + 90), 0 + c * sin(t + 90));
  hills(-50, 22, t * 1.5, 1);
  fill(0 + c * sin(t + 90), 255 + c * sin(t + 90), 251 + c * sin(t + 90));
  hills(-100, 10, t * 2, 1.5);
  pHole();
}

function hills(center, a, t, p) {
  beginShape();
  for (let i = -180; i < 181; i++) {
    x = (i * width) / 360;
    y =
      center +
      a * sin(p * (i + t)) * cos(p * (i + t)) -
      a * sin(p * (i + t)) * sin(p * (i + t));
    vertex(x, y);
  }
  vertex(width / 2, -width / 2);
  vertex(-width / 2, -width / 2);
  endShape(CLOSE);
}

function pHole() {
  fill(0);
  noStroke();
  beginShape();
  for (let i = 0; i <= 180; i++) {
    x = 250 * cos(i);
    y = 250 * sin(i);
    vertex(x, y);
  }
  vertex(-width / 2, 0);
  vertex(-width / 2, height / 2);
  vertex(width / 2, height / 2);
  vertex(width / 2, 0);
  endShape(CLOSE);
  beginShape();
  for (let i = 180; i <= 360; i++) {
    x = 250 * cos(i);
    y = 250 * sin(i);
    vertex(x, y);
  }
  vertex(width / 2, 0);
  vertex(width / 2, -height / 2);
  vertex(-width / 2, -height / 2);
  vertex(-width / 2, 0);
  endShape(CLOSE);
  stroke(4, 112, 179);
  strokeWeight(1);
  noFill();
}