let img1, img2;
let m;
let lineGroup1;
let nSymmetry;
function preload() {
img1 = loadImage("/assets/correspondence.jpg");
img2 = loadImage("/assets/star.png");
}
function setup() {
createCanvas(600, 600);
strokeWeight(0.25);
angleMode(DEGREES);
stroke(255);
imageMode(CENTER);
m1 = random(0.5, 1);
nLines = int(random(10, 30));
lineGroup1 = [];
for (let i = 0; i < nLines; i++) {
lineGroup1[i] = random(-width * 2, width * 2, 2);
}
nSymmetry = int(random(5, 12));
}
function draw() {
translate(width / 2, height / 2);
t1 = frameCount / 5;
rotate(-t1 / 2);
m = m1 + m1 * sin(t1 / 2);
image(img1, 0, 0, 900, 900);
strokeWeight(0.8);
image(img2, 0, 0, 200, 200);
theta = atan(m);
stroke(225, 240, 255, 100);
fill(225, 240, 255, 50);
for (let j = 0; j < nSymmetry; j++) {
push();
rotate((360 / nSymmetry) * j);
line(-width * 4, 0, width * 4, 0);
for (let i = 0; i < lineGroup1.length; i++) {
y1 = lineGroup1[i] + 200 * sin(t1);
line(-width / 2, y1, width / 2, m * width + y1);
circle(-y1 / m + -width / 2, 0, 2);
if (theta <= 0) {
arc(
-y1 / m + -width / 2,
0,
50 + 150 * sin(t1),
50 + 150 * sin(t1),
theta,
0
);
} else {
arc(
-y1 / m + -width / 2,
0,
50 + 150 * sin(t1),
50 + 150 * sin(t1),
0,
theta
);
}
}
pop();
}
portHole();
}
function portHole() {
push();
noStroke();
fill(0);
beginShape();
for (let i = 0; i <= 180; i++) {
x = 280 * cos(i);
y = 280 * sin(i);
vertex(x, y);
}
vertex(-width, 0);
vertex(-width, height);
vertex(width, height);
vertex(width, 0);
endShape(CLOSE);
beginShape();
for (let i = 180; i <= 360; i++) {
x = 280 * cos(i);
y = 280 * sin(i);
vertex(x, y);
}
vertex(width, 0);
vertex(width, -height);
vertex(-width, -height);
vertex(-width, 0);
endShape(CLOSE);
stroke(4, 112, 179);
strokeWeight(1);
noFill();
pop();
}
function keyPressed() {
setup();
draw();
}