fractalkitty looking for math? fractalkitty.com

Coded Poems

mathober day-20: Sequence

#random#trig#vectors#image#interactive#animation#accumulates#poem#number-theory#time#mathober

img1img2nPolygonspointstDraw


let img1, img2;
let nPolygons = 5;
let points;

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

function setup() {
  createCanvas(600, 600);
  points = [];
  nPolygons = int(random(4, 40));
  strokeWeight(0.25);
  angleMode(DEGREES);
  stroke(255);
  imageMode(CENTER);
}

function draw() {
  translate(width / 2, height / 2);
  t1 = frameCount / 15;
  rotate(t1);
  image(img1, 0, 0, 800, 800);
  noFill();
  r = 250;
  p1 = createVector(r * cos(0), r * sin(0));
  p2 = createVector(r * cos(120), r * sin(120));
  p3 = createVector(r * cos(240), r * sin(240));
  points[0] = [];
  points[0][0] = p1;
  points[0][1] = p2;
  points[0][2] = p3;
  cnt = 1;
  triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);

  tDraw(p1, p2, p3, 1);
  for (let i = 1; i < 15; i++) {
    circle(points[i][0].x, points[i][0].y, 1);
    tDraw(p1, points[i][0], points[i][1], i + 1);
  }
}

function tDraw(c1, c2, c3, n) {
  p31 = createVector(c1.x - (c1.x - c3.x) / 2, c1.y - (c1.y - c3.y) / 2);
  p32 = createVector(c1.x - (c1.x - c2.x) / 2, c1.y - (c1.y - c2.y) / 2);
  p33 = createVector(c2.x - (c2.x - c3.x) / 2, c2.y - (c2.y - c3.y) / 2);
  fill(255, 255, 255, 80 + abs(sin(t1)));
  push();
  rotate((t1 * p32.y) / 100);
  triangle(p31.x, p31.y, p32.x, p32.y, p33.x, p33.y);
  pop();
  points[n] = [];
  points[n][0] = p31;
  points[n][1] = p32;
  points[n][2] = p33;
}

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