xxxxxxxxxx
53
let cols, rows,
current = [],
previous = [],
damping = 0.99;
function mouseDragged() {
current[mouseX][mouseY] = 500 // Increased initial disturbance value
}
function setup() {
pixelDensity(1)
createCanvas(800, 800)
cols = width
rows = height
for (let i = 0; i < cols; i++) {
current[i] = []
previous[i] = []
for (let j = 0; j < rows; j++) {
current[i][j] = 0
previous[i][j] = 0
}
}
previous[100][100] = 500 // Increased initial disturbance value
}
function draw() {
background(255) // Pure white background
loadPixels()
for (let i = 1; i < cols - 1; i++) {
for (let j = 1; j < rows - 1; j++) {
current[i][j] =
(previous[i - 1][j] + previous[i + 1][j] +
previous[i][j - 1] + previous[i][j + 1] +
previous[i - 1][j - 1] + previous[i - 1][j + 1] +
previous[i + 1][j - 1] + previous[i + 1][j + 1]
) / 4 - current[i][j];
current[i][j] = current[i][j] * damping;
let index = (i + j * cols) * 4;
// Invert the values to get white ripples
let val = 255 - Math.abs(current[i][j]);
pixels[index + 0] = val;
pixels[index + 1] = val;
pixels[index + 2] = val;
pixels[index + 3] = 255;
}
}
updatePixels()
//swap buffers
let temp = previous
previous = current
current = temp
}