Just something I made while I was bored, enjoy!
Video: http://youtu.be/_qRmXAsD0EA
-- grass
-- Use this function to perform your initial setup
function setup()
p = {}
vel = {}
v = {}
m = mesh()
width = WIDTH/15-10
r = {}
local x = 1
local y = 1
p[y] = {}
for i = 1,207 do
if x <= 15 then
x = x + 1
p[y][x] = vec2(x*width,y*30-30)
else
x = 1
y = y + 1
p[y] = {}
end
v[i] = vec2(0,0)
vel[i] = vec2(0,0)
r[i] = m:addRect(1,1,1,1)
end
m:setColors(30,180,30,255)
end
function touched(t)
tpos = vec2(t.x,t.y)
local x = 0
local y = 1
for i = 1,207 do
if x <= 15 then
x = x + 1
else
x = 1
y = y + 1
end
--if tpos:dist(p[i]) < 300 then
--v[i] = v[i] + vec2(t.deltaX*(300-tpos:dist(p[i]))/100,0)*(i/100)
if vec2(tpos.x,0):dist(vec2(x*width,0)) < 150 then
v[i] = v[i] + (vec2(t.deltaX*(y/3),0))*(vec2(tpos.x,0):dist(vec2(x*width,0)))/1500
end
--end
end
end
function angleOfPoint( pt )
local x, y = pt.x, pt.y
local radian = math.atan2(y,x)
local angle = radian*180/math.pi
if angle < 0 then angle = 360 + angle end
return angle
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(90, 168, 230, 255)
-- This sets the line thickness
strokeWidth(5)
stroke(30,180,30, 255)
fill(30,180,30,255)
rect(-5,-5,WIDTH+10,20)
-- Do your drawing here
local x = 1
local y = 1
for i = 1,207 do
if x <= 15 then
x = x + 1
vel[i] = vel[i] + (vec2(x*width,y*30-30)-p[y][x])/100
p[y][x] = p[y][x] + vel[i]/2
local ang = 0
if y > 1 then
ang = angleOfPoint(p[y][x]-p[y-1][x])+90
end
m:setRect(r[i],p[y][x].x,p[y][x].y,30-y*2,45,(ang)/57.3)
else
x = 1
y = y + 1
end
vel[i] = vel[i] + (v[i]/5000)*i
v[i] = v[i]*0.95
vel[i] = vel[i]*0.95
--rect(p[i-1].x,p[i-1].y,20,30)
end
m:draw()
end