fractalkitty looking for math? fractalkitty.com

Coded Poems

mathober day-28: hypotraceable

#trig#vectors#image#animation#accumulates#poem#mathober

img1img2starpath1path2path3path4pathStraightlineDrawpathsgeometriesstars


let img1, img2;
let t, a, b, p;

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

function setup() {
  createCanvas(600, 600);
  strokeWeight(0.5);
  angleMode(DEGREES);
  stroke(80, 68, 97);
  imageMode(CENTER);
  noFill();
  p = 15;
}

function draw() {
  translate(width / 2, height / 2);
  t = frameCount / 6;
  push();
  rotate(-t / 4);
  image(img1, 0, 0, 900, 900);
  pop();
  a = 200;
  b = 120;
  c = sqrt(a * a - b * b);
  geometries();
  paths();
  stars();
}

function star(x, y) {
  if (x === 0) {
    image(img2, x, y, 120, 120);
  } else {
    image(img2, x, y, 60, 60);
  }
}
function path1() {
  let n = 20;
  for (let i = 0; i < n; i++) {
    image(img2, a * cos((i * 360) / n - t), b * sin((i * 360) / n - t), p, p);
  }
}
function path2() {
  n = 7;
  for (let i = 0; i < n; i++) {
    image(
      img2,
      c - 35 + (d1 / 2) * cos(-45 - (((i * 180) / n + t) % 180)),
      (d1 / 2) * sin(-45 - (((i * 180) / n + t) % 180)),
      p * 2,
      p
    );
  }
  for (let i = 0; i < n; i++) {
    image(
      img2,
      -c + 35 + (d1 / 2) * cos(-225 - (((i * 180) / n + t) % 180)),
      (d1 / 2) * sin(-225 - (((i * 180) / n + t) % 180)),
      p * 2,
      p
    );
  }
}
function path3() {
  n = 8;
  for (let i = 0; i < n; i++) {
    image(
      img2,
      c - 35 + (d1 / 1.8 / 2) * cos(-45 - ((i * 360) / n + t)),
      (d1 / 1.8 / 2) * sin(-45 - ((i * 360) / n + t)),
      p * 2,
      p
    );
  }
  for (let i = 0; i < n; i++) {
    image(
      img2,
      -c + 35 + (d1 / 1.8 / 2) * cos(-225 - ((i * 360) / n + t)),
      (d1 / 1.8 / 2) * sin(-225 - ((i * 360) / n + t)),
      p * 2,
      p
    );
  }
}
function path4() {
  n = 6;
  for (let i = 0; i < n; i++) {
    image(
      img2,
      200 + 200 * cos(130 + (((i * 56) / n + t) % 56)),
      -100 + 200 * sin(130 + (((i * 56) / n + t) % 56)),
      p * 2,
      p
    );
    image(
      img2,
      -200 + 200 * cos(-50 + (((i * 56) / n + t) % 56)),
      +100 + 200 * sin(-50 + (((i * 56) / n + t) % 56)),
      p * 2,
      p
    );
  }
}
function pathStraight() {
  n = 4;
  ta = 1;
  p2 = createVector(0, -b);
  p1 = createVector(c - 35 + (d1 / 2) * cos(-135), (d1 / 2) * sin(-135));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = 1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  p1 = createVector(0, -b);
  p2 = createVector(-c + 35 + (d1 / 2) * cos(-45), (d1 / 2) * sin(-45));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = 1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  p2 = createVector(0, b);
  p1 = createVector(-c + 35 + (d1 / 2) * cos(45), (d1 / 2) * sin(45));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = -1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  p1 = createVector(0, b);
  p2 = createVector(c - 35 + (d1 / 2) * cos(135), (d1 / 2) * sin(135));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = -1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  n = 3;
  ta = 0.2;
  p1 = createVector(c - 35 + (d1 / 1.8 / 2) * cos(0), (d1 / 1.8 / 2) * sin(0));
  p2 = createVector(c - 35 + (d1 / 2) * cos(45), (d1 / 2) * sin(45));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = -1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  translate(-2 * (c - 35), 0);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();
  ta = 1;
  p2 = createVector(
    c - 35 + (d1 / 1.8 / 2) * cos(90),
    (d1 / 1.8 / 2) * sin(90)
  );
  p1 = createVector(c - 35 + (d1 / 2) * cos(45), (d1 / 2) * sin(45));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = 1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  translate(-2 * (c - 35), 0);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();
  ta = 1;
  p1 = createVector(
    c - 35 + (d1 / 1.8 / 2) * cos(90),
    (d1 / 1.8 / 2) * sin(90)
  );
  p2 = createVector(c - 35 + (d1 / 2) * cos(135), (d1 / 2) * sin(135));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = 1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  translate(-2 * (c - 35), 0);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();
  ta = 0.2;
  p2 = createVector(
    c - 35 + (d1 / 1.8 / 2) * cos(180),
    (d1 / 1.8 / 2) * sin(180)
  );
  p1 = createVector(c - 35 + (d1 / 2) * cos(135), (d1 / 2) * sin(135));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = -1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  translate(-2 * (c - 35), 0);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();

  ta = 0.2;
  p1 = createVector(
    c - 35 + (d1 / 1.8 / 2) * cos(180),
    (d1 / 1.8 / 2) * sin(180)
  );
  p2 = createVector(c - 35 + (d1 / 2) * cos(225), (d1 / 2) * sin(225));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = 1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  translate(-2 * (c - 35), 0);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();
  ta = 1;
  p2 = createVector(
    c - 35 + (d1 / 1.8 / 2) * cos(270),
    (d1 / 1.8 / 2) * sin(270)
  );
  p1 = createVector(c - 35 + (d1 / 2) * cos(225), (d1 / 2) * sin(225));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = -1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  translate(-2 * (c - 35), 0);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();
  ta = 1;
  p1 = createVector(
    c - 35 + (d1 / 1.8 / 2) * cos(270),
    (d1 / 1.8 / 2) * sin(270)
  );
  p2 = createVector(c - 35 + (d1 / 2) * cos(-45), (d1 / 2) * sin(-45));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = -1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  translate(-2 * (c - 35), 0);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();
  ta = 0.2;
  p2 = createVector(c - 35 + (d1 / 1.8 / 2) * cos(0), (d1 / 1.8 / 2) * sin(0));
  p1 = createVector(c - 35 + (d1 / 2) * cos(-45), (d1 / 2) * sin(-45));
  line(p1.x, p1.y, p2.x, p2.y);
  dir = 1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  translate(-2 * (c - 35), 0);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();
  ta = 1;
  p1 = createVector(c - 35 + (d1 / 1.8 / 2) * cos(0), (d1 / 1.8 / 2) * sin(0));
  p2 = createVector(
    c - 35 + (d1 / 1.8 / 2) * cos(180),
    (d1 / 1.8 / 2) * sin(180)
  );
  line(p1.x, p1.y, p2.x, p2.y);
  dir = 1;
  m = (p1.y - p2.y) / (p1.x - p2.x);
  lineDraw();
  push();
  scale(-1, 1);
  line(p1.x, p1.y, p2.x, p2.y);
  lineDraw();
  pop();

  function lineDraw() {
    for (let i = 0; i < n; i++) {
      x1 =
        p1.x -
        ((p1.x - p2.x) / n) * i -
        ((dir * (ta * t)) % ((p1.x - p2.x) / n));
      y1 = m * (x1 - p2.x) + p2.y;
      image(img2, x1, y1, p * 2, p);
    }
  }
}

function paths() {
  path1();
  path2();
  path3();
  path4();
  pathStraight();
}
function geometries() {
  d1 = 150;
  ellipse(0, 0, 2 * a, 2 * b);
  circle(c - 35, 0, d1);
  circle(-c + 35, 0, d1);
  circle(c - 35, 0, d1 / 1.8);
  circle(-c + 35, 0, d1 / 1.8);
  circle(200, -100, 400);
  circle(-200, 100, 400);
}

function stars() {
  star(0, b);
  star(0, -b);

  star(c - 35 + (d1 / 2) * cos(45), (d1 / 2) * sin(45));
  star(c - 35 + (d1 / 2) * cos(-45), (d1 / 2) * sin(-45));
  star(c - 35 + (d1 / 2) * cos(135), (d1 / 2) * sin(135));
  star(c - 35 + (d1 / 2) * cos(225), (d1 / 2) * sin(225));
  star(-c + 35 + (d1 / 2) * cos(45), (d1 / 2) * sin(45));
  star(-c + 35 + (d1 / 2) * cos(-45), (d1 / 2) * sin(-45));
  star(-c + 35 + (d1 / 2) * cos(135), (d1 / 2) * sin(135));
  star(-c + 35 + (d1 / 2) * cos(225), (d1 / 2) * sin(225));

  star(c - 35 + (d1 / 1.8 / 2) * cos(0), (d1 / 1.8 / 2) * sin(0));
  star(c - 35 + (d1 / 1.8 / 2) * cos(90), (d1 / 1.8 / 2) * sin(90));
  star(c - 35 + (d1 / 1.8 / 2) * cos(180), (d1 / 1.8 / 2) * sin(180));
  star(c - 35 + (d1 / 1.8 / 2) * cos(270), (d1 / 1.8 / 2) * sin(270));
  star(-c + 35 + (d1 / 1.8 / 2) * cos(0), (d1 / 1.8 / 2) * sin(0));
  star(-c + 35 + (d1 / 1.8 / 2) * cos(90), (d1 / 1.8 / 2) * sin(90));
  star(-c + 35 + (d1 / 1.8 / 2) * cos(180), (d1 / 1.8 / 2) * sin(180));
  star(-c + 35 + (d1 / 1.8 / 2) * cos(270), (d1 / 1.8 / 2) * sin(270));
}