Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Water FX

edited May 2012 in Code Sharing Posts: 154

Code:

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

tileSize = WIDTH/24
noiseScale = 1/5
noisePos = vec2(0,0)
noiseSpeed = 0.2

function setup()
    parameter("noiseScale", 1/30, 1, 1/5)    
    parameter("noiseSpeed", 0.05, 1, 0.2)

    tiles = {}
    for x = 1, WIDTH/tileSize do
        tiles[x] = {}
        for y = 1, HEIGHT/tileSize do
            tiles[x][y] = noise(x * noiseScale, y * noiseScale)
        end
    end
end

function moveNoise()
    for x,column in ipairs(tiles) do
        for y,value in ipairs(column) do
            tiles[x][y] = noise(x * noiseScale + noisePos.x, y * noiseScale + noisePos.y)
        end
    end
end

function draw()
    background(0, 164, 255, 255)
    
    for x,column in ipairs(tiles) do
        for y,value in ipairs(column) do
            fill((value+1)*0.5*255,100)
            rect((x-1)*tileSize, (y-1)*tileSize, tileSize, tileSize)
        end
    end
    
    noisePos = noisePos + vec2(0.5,0.3) * noiseSpeed
    moveNoise()
end

Tagged:

Comments

Sign In or Register to comment.