xxxxxxxxxx
49
/*
----- Coding Tutorial by Patt Vira -----
Name: Chladni Patterns (Basic)
Video Tutorial: https://youtu.be/J-siGcsK2k8
Connect with Patt: @pattvira
https://www.pattvira.com/
----------------------------------------
*/
let cols, rows; let size = 1;
let m = 5; let n = 4; let threshold = 0.05;
function setup() {
createCanvas(400, 400);
cols = width/size;
rows = height/size;
}
function draw() {
background(220);
noStroke();
for (let i=0; i<cols; i++) {
for (let j=0; j<rows; j++) {
let x = map(i, 0, cols, 0, 1);
let y = map(j, 0, rows, 0, 1);
let val = chladni(x, y);
if (abs(val) < threshold) {
fill(0);
} else {
fill(255);
}
rect(i*size, j*size, size, size);
}
}
noLoop();
}
function chladni(x, y) {
let L = 1;
return cos(n * PI * x / L) * cos(m * PI * y / L) -
cos(m * PI * x / L) * cos(n * PI * y / L);
}