int cols; int rows; float[][] current; float[][] previous; float damping = 0.99; void setup() { size(600, 400); cols = width; rows = height; current = new float[cols][rows]; previous = new float[cols][rows]; } void mouseMoved() { previous[mouseX][mouseY] = 2055; } void keyPressed() { save("output.png"); } void draw() { background(0); int x = (int)random(0,(int)width); int y = (int)random(0,(int)height); previous[x][y] = random(2000); loadPixels(); for ( int i = 1; i < cols-1; i++ ) { for ( int 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])/2.0 - current[i][j]; current[i][j] = current[i][j]*damping; int index = i + j * cols; pixels[index] = color(100-current[i][j]); } } updatePixels(); float[][] temp = previous; previous = current; current = temp; }