i tried to mix up a few example codes, so here it is… noise + 3d/mesh…
it’s not so fast and im not so good at optimizing, but here it is…
http://www.youtube.com/watch?v=F4YYTO5atkA&sns=em
-- Water Test
function setup()
local vertices = {}
resolution = 19 -- decrease for more fps, increase for slowlyness :D
displayMode(FULLSCREEN)
t=0
Size=150
parameter("Speed",0,5,1.5)
parameter("CamHeight", -1000, 1000, 19.5)
parameter("Angle",-360, 360, -30)
parameter("FieldOfView", 10, 140, 90)
parameter("NoiseScale", 0,1,0.23)
parameter("Scale2", 1,100,15)
the3DViewMatrix = viewMatrix()
watch ("fps")
fpscount=0
fpsamount = 0
for i=1,resolution do
vertices[i] ={}
for j=1,resolution do
vertices[i][j] = vec3(-75 +i*Size/resolution,0,-75+j*Size/resolution)
end
end
cubeverts = {}
for i=1,(resolution-1) do
for j=1,(resolution-1) do
table.insert(cubeverts, vertices[i][j])
table.insert(cubeverts, vertices[i+1][j])
table.insert(cubeverts, vertices[i][j+1])
table.insert(cubeverts, vertices[i+1][j])
table.insert(cubeverts, vertices[i][j+1])
table.insert(cubeverts, vertices[i+1][j+1])
end
end
ms = mesh()
ms.vertices = cubeverts
print("Using "..table.maxn(cubeverts).." vertices")
-- init colortable
triCol = {}
for i=1,((resolution-1)*(resolution-1)*6) do
tst = math.random(0,255)
table.insert(triCol, i, color(tst, tst, 255, 255) )
end
ms.colors = triCol
end
function draw()
perspective(FieldOfView, WIDTH/HEIGHT)
-- Position the camera up and back, look at origin
camera(0,CamHeight,-10, 10,0,10, 0,1,0)
-- This sets a dark background color
background(40, 40, 50)
translate(50,-Size/2,70)
rotate(Angle,0,1,0)
counter = 0
for i=1,(resolution-1) do
for j=1,(resolution-1) do
counter = counter + 1
if counter > 2 and j> 1 and i>1 then
ms:vertex(counter, ms:vertex(counter).x, ms:vertex(counter-2).y, ms:vertex(counter).z)
else
ms:vertex(counter, ms:vertex(counter).x,noise((i+t)*NoiseScale,(j+t)*NoiseScale)*Scale2, ms:vertex(counter).z)
end
if counter > 2 then
newcol = (ms:vertex(counter).y)*10
ms:color(counter, color(newcol, newcol, 255+newcol))
end
counter = counter + 1
if counter > 2 and j> 1 and i>1 then
ms:vertex(counter, ms:vertex(counter).x, ms:vertex(counter-2).y, ms:vertex(counter).z)
else
ms:vertex(counter, ms:vertex(counter).x,noise((i+t+1)*NoiseScale,(j+t)*NoiseScale)*Scale2, ms:vertex(counter).z)
end
newcol = (ms:vertex(counter).y)*10
ms:color(counter, color(newcol, newcol, 255+newcol))
counter = counter + 1
ms:vertex(counter, ms:vertex(counter).x,noise((i+t)*NoiseScale,(j+t+1)*NoiseScale)*Scale2, ms:vertex(counter).z)
newcol = (ms:vertex(counter).y)*10
ms:color(counter, color(newcol, newcol, 255+newcol))
counter = counter + 1
if counter > 2 and j> 1 and i>1 then
ms:vertex(counter, ms:vertex(counter).x, ms:vertex(counter-2).y, ms:vertex(counter).z)
else
ms:vertex(counter, ms:vertex(counter).x,noise((i+t+1)*NoiseScale,(j+t)*NoiseScale)*Scale2, ms:vertex(counter).z)
end
newcol = (ms:vertex(counter).y)*10
ms:color(counter, color(newcol, newcol, 255+newcol))
counter = counter + 1
ms:vertex(counter, ms:vertex(counter).x,noise((i+t)*NoiseScale,(j+t+1)*NoiseScale)*Scale2, ms:vertex(counter).z)
newcol = (ms:vertex(counter).y)*10
ms:color(counter, color(newcol, newcol, 255+newcol))
counter = counter + 1
ms:vertex(counter, ms:vertex(counter).x,noise((i+t+1)*NoiseScale,(j+t+1)*NoiseScale)*Scale2, ms:vertex(counter).z)
newcol = (ms:vertex(counter).y)*10
ms:color(counter, color(newcol, newcol, 255+newcol))
end
end
ms:draw()
t = t + (DeltaTime*Speed)
fpscount = fpscount + 1
fpsamount = fpsamount + DeltaTime
if fpscount == 10 then
fps = fpsamount /10
fps = 1/fps
fpsamount =0
fpscount=0
end
end
function touched()
if CurrentTouch.state==BEGAN then
if displayMode() == FULLSCREEN then
displayMode(STANDARD)
else
displayMode(FULLSCREEN)
end
end
end