xxxxxxxxxx
49
/*
Based on the lissajous curve example from Code as a Creative Medium
https://github.com/CodeAsCreativeMedium/exercises/blob/main/09_curves/06_lissajous/lissajous_js/lissajous_js.js
Lissajous curve:
https://en.wikipedia.org/wiki/Lissajous_curve
*/
let t = 0;
let z1 = 0;
let z2 = 0;
let toggle = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
stroke(255);
strokeWeight(8);
}
function draw() {
background(0, 5);
let minDimension = min(width, height);
let radius = (minDimension * 3) / 8;
x = cos((2 * t) / 5) * radius + width / 2;
y = sin((2 * t) / 5) * radius + height / 2;
if (toggle) {
z1 = y;
z2 = x;
} else {
z1 = x;
z2 = y;
}
point(z1, z2);
point(z1 + 20, z2 + 20);
t += 0.1;
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
background(0);
}
function mousePressed() {
toggle = !toggle;
}