fractalkitty looking for math? fractalkitty.com

Mathober 2023

mathober day-2: Symmedial

#random#trig#vectors#image#interactive#animation#poem#math#geometry#symmetry#polar#mathober

img1pt1pt2pt3




let img1;
let pt1, pt2, pt3;
let r;
function preload() {
  img1 = loadImage("/assets/sky2.jpg");
}
function setup() {
  createCanvas(600, 600);
  angle1 = random(PI / 6 - PI / 10, PI / 6 + PI / 10);
  angle2 = random(PI - PI / 10, PI + PI / 10);
  angle3 = random((10 * PI) / 6 - PI / 10, (10 * PI) / 6 + PI / 10);
  strokeCap(ROUND);
}
function draw() {
  translate(width / 2, height / 2);
  background(0);
  t1 = frameCount / 2000;
  t2 = TWO_PI * 4 * sin(t1);
  r = 100 + 50 * sin(t2);
  pt1 = createVector(r * cos(angle1 + 2 * t2), r * sin(angle1 + 2 * t2));
  pt2 = createVector(r * cos(angle2 + t2), r * sin(angle2 + t2));
  pt3 = createVector(r * cos(angle3 + t2), r * sin(angle3 + t2));
  m = createVector(pt2.x - (pt2.x - pt3.x) / 2, pt2.y - (pt2.y - pt3.y) / 2);
  m1 = -pt2.x / pt2.y;
  m2 = -pt3.x / pt3.y;
  px = (-m2 * pt3.x + m1 * pt2.x - pt2.y + pt3.y) / (m1 - m2);
  py = m1 * (px - pt2.x) + pt2.y;
  pm = (pt1.y - py) / (pt1.x - px);
  pmI = -1 / pm;
  Sx = (pm * pt1.x - pt1.y) / (pm - pmI);
  Sy = pm * (Sx - pt1.x) + pt1.y;
  image(img1, -width / 2, -height / 2, 600, 600);
  push();
  translate(-Sx, -Sy);
  noFill();
  stroke(
    250 * abs(sin(t2 / 3)),
    250 * abs(sin(t2 / 3)),
    250 * abs(sin(t2 / 3)),
    50
  );
  strokeWeight(1);
  fill(255, 255, 255, 10);
  triangle(pt1.x, pt1.y, pt2.x, pt2.y, pt3.x, pt3.y);
  noFill();
  circle(0, 0, r * 2);
  line(pt1.x, pt1.y, m.x, m.y);
  line(0, 0, pt2.x, pt2.y);
  line(0, 0, pt3.x, pt3.y);
  line(0, 0, px, py);
  line(pt2.x, pt2.y, px, py);
  line(pt3.x, pt3.y, px, py);
  circle(Sx, Sy, 2);
  circle(px, py, 2);
  line(px, py, pt1.x, pt1.y);
  line(0, 0, Sx, Sy);
  pop();
}

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