# Violent water

I was trying to make water but I was doing it wrong so I decided to just leave it as this, its pretty fun and sort of resembles some sort of fluid, not sure which one, anyway take a look!

``````
-- water

-- Use this function to perform your initial setup
function setup()
p={}
w={}
wm={}
local amount = 50
for i=1,amount do
w[i] = physics.body(CIRCLE,10)
w[i].x = math.random(100,700)
w[i].y = math.random(100,700)
wm[i] = {}
wm[i][1] = mesh()
wm[i][1]:setRectTex(0,0,1,1)
end
local verts = {vec2(0,0),vec2(WIDTH,0),vec2(WIDTH,HEIGHT),vec2(0,HEIGHT),vec2(0,0)}
floor = physics.body(CHAIN,false,unpack(verts))
end

function touched(t)
local tpos = vec2(t.x,t.y)
if t.state == MOVING then
for i = 1,#w do
if tpos:dist(w[i].position) < 50 then
w[i]:applyForce(vec2(t.deltaX,t.deltaY)*10)
end
end
end
end

function sign(x,am)
if x == nil then return end
if x > am then return 1 elseif x < am then return -1 elseif x < -am and x > am then return 0 end
end

-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)

-- This sets the line thickness
strokeWidth(5)

physics.gravity(Gravity)

for a=1,#w do
--ellipse(w[a].x,w[a].y,30)
wm[a][1]:draw()
wm[a][1]:setRect(wm[a][2],w[a].x,w[a].y,40,40,0)
if w[a].x < 40 then w[a]:applyForce(vec2(50-w[a].linearVelocity.x/4,0)) end
if w[a].x > WIDTH-40 then w[a]:applyForce(vec2(-50-w[a].linearVelocity.x/4,0)) end
if w[a].y < 40 then w[a]:applyForce(vec2(0,50-w[a].linearVelocity.y/4)) end
if w[a].y > HEIGHT-40 then w[a]:applyForce(vec2(0,-50-w[a].linearVelocity.y/4)) end
for b=1,#w do
if w[a] ~= w[b] and w[a].position:dist(w[b].position) < 40 then
w[a]:applyForce((vec2(w[a].x+math.random(-10,10),w[a].y)-w[b].position):normalize()*(100-w[a].position:dist(w[b].position)*2) - w[a].linearVelocity/120)
w[b]:applyForce((vec2(w[b].x+math.random(-10,10),w[b].y)-w[a].position):normalize()*(100-w[a].position:dist(w[b].position)*2) - w[b].linearVelocity/120)
end
end
end
end
``````