xxxxxxxxxx
42
/*
Based on Moiré Patterns from Code as a Creative Medium
https://github.com/CodeAsCreativeMedium/exercises/blob/main/02_iteration/14_moire_patterns/moire_js/moire_js.js
*/
let angle = 0;
let numLines = 80;
let spacing = 250;
function setup() {
createCanvas(windowWidth, windowHeight);
stroke(255);
strokeWeight(2);
smooth();
}
function draw() {
background(0);
for (let i = 0; i < numLines; i += 2) {
let x = map(i, 0, numLines - 1, width / 2 - spacing, width / 2 + spacing);
line(x, 0, x, height);
}
let mx = -mouseX / 200.0;
angle = 0.95 * angle + 0.05 * mx;
push();
translate(width * 0.6, height / 2);
rotate(angle);
for (let i = 0; i < numLines; i++) {
let x = map(i, 0, numLines - 1, -spacing, spacing);
line(x, -height * 0.4, x, height * 0.4);
}
pop();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}