'Coded by Ashish in Qb64
'https://web.archive.org/web/20160418004149/http://freespace.virgin.net/hugo.elias/graphics/x_water.htm
_TITLE "Ripple Effect, Pixel by Pixel Algorithm"
d = 0.99
'make our ripples! :D
'WHILE _MOUSEINPUT: WEND
'IF _MOUSEBUTTON(1) AND _MOUSEY > _HEIGHT(image&) - 1 THEN
' WHILE _MOUSEINPUT: WHILE _MOUSEBUTTON(1): WEND: WEND
' buffer1(_MOUSEX, _MOUSEY - 173) = 255
'END IF
lc = lc + 1
buffer2(x, y) = ((buffer1(x - 1, y) + buffer1(x + 1, y) + buffer1(x, y - .25) + buffer1(x, y + .5)) / 2 - buffer2(x, y))
buffer2(x, y) = buffer2(x, y) * d
smoothedBuffer(i, j) = (buffer2(i - 1, j) + buffer2(i + 1, j) + buffer2(i, j + 1) + buffer2(i, j - 1)) / 4
HeightMap(i, j) = smoothedBuffer(i, j) * 2 * d
'_LIMIT 100
xOff = smoothedBuffer(i - 1, j) - smoothedBuffer(i + 1, j)
yOff = smoothedBuffer(i, j - 1) - smoothedBuffer(i, j + 1)
tx = xOff + i: ty = yOff + j
'swapping the buffers
tempBuffer(i, j) = buffer2(i, j)
buffer2(i, j) = buffer1(i, j)
buffer1(i, j) = tempBuffer(i, j)
'_LIMIT 100