# Grass and wind

Just something I made while I was bored, enjoy!

``````
-- 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)
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
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)
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
``````

Cool little program! I can think of many uses for this, thx for posting!

Here’s an updated version, grass tips used to stay at one level on the y axis now it bends down with the ‘wind’:

``````-- grass

-- Use this function to perform your initial setup
function setup()
displayMode(FULLSCREEN)
p = {}
vel = {}
count = 252
v = {}
m = mesh()
width = WIDTH/18-12
r = {}
local x = 1
local y = 1
p[y] = {}
for i = 1,count do
if x <= 20 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)
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,count do
if x <= 20 then
x = x + 1
else
x = 1
y = y + 1
end
if vec2(tpos.x,0):dist(vec2(x*width,0)) < 150 then
local mlt = (vec2(tpos.x,0):dist(vec2(x*width,0)))/1500
v[i] = v[i] + (vec2(t.deltaX*(y/4),-math.abs(v[i].x)*0.6))*mlt
end
end
end

function angleOfPoint( pt )
local x, y = pt.x, pt.y
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)
local x = 1
local y = 1
for i = 1,count do
if x <= 20 then
x = x + 1
vel[i] = vel[i] + (vec2(x*width,y*30-30)-p[y][x])/100
--vel[i] = vel[i] + vec2(Gravity.x,Gravity.y)
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,50,(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

end
m:draw()
end
``````