Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Main
- displayMode(FULLSCREEN)
- supportedOrientations(PORTRAIT)
- function setup()
- print("Hello World!")
- t=Trees()
- mx = 0
- my = 0
- lt = ElapsedTime
- end
- function draw()
- background(25, 32, 26, 255)
- t:draw()
- t:move(mx,my)
- fill(195, 39, 39, 255)
- --text(1/(ElapsedTime - lt),100,100)
- lt = ElapsedTime
- end
- function touched(touch)
- if touch.state == BEGAN then
- if touch.x > WIDTH/2 + WIDTH/4 then
- mx = mx - 1
- elseif touch.x < WIDTH/2 - WIDTH/4 then
- mx = mx + 1
- end
- if touch.y > HEIGHT/2 + HEIGHT/4 then
- my = my - 1
- elseif touch.y < HEIGHT/2 - HEIGHT/4 then
- my = my + 1
- end
- end
- end
- --# Tree
- Tree = class()
- function Tree:init()
- self.x = math.random(WIDTH+200)-100
- self.y = math.random(HEIGHT+200)
- self.tl = 16
- self.tw = 8
- self.tb = self.tw * 1.2
- self.lw = 32
- end
- function Tree:drawTrunk()
- stroke(125, 81, 37, 255)
- fill(125, 81, 37, 255)
- strokeWidth(self.tw)
- local v1 = vec2(self.x,self.y)
- local v2 = vec2(WIDTH/2,HEIGHT/2)
- local v3 = v2 - v1
- local v4 = v3:normalize()
- local d = v1:dist(v2)
- local ttx = self.x-(v4.x*(d/self.tl))
- local tty = self.y-(v4.y*(d/self.tl))
- line(self.x,self.y,ttx,tty)
- ellipse(self.x,self.y,self.tb,self.tb)
- end
- function Tree:drawLeaves()
- noStroke()
- fill(39, 133, 29, 127 + 64)
- local v1 = vec2(self.x,self.y)
- local v2 = vec2(WIDTH/2,HEIGHT/2)
- local v3 = v2 - v1
- local v4 = v3:normalize()
- local d = v1:dist(v2)
- local ttx = self.x-(v4.x*(d/self.tl))
- local tty = self.y-(v4.y*(d/self.tl))
- ellipse(ttx,tty,self.lw,self.lw)
- end
- --# Trees
- Trees = class()
- function Trees:init(n)
- if n == nil then self.n = 128 else self.n = n end
- self.t = {}
- for i = 1, self.n do
- self.t[i] = Tree()
- end
- end
- function Trees:draw()
- for i = 1, self.n do
- self.t[i]:drawTrunk()
- end
- for i = 1, self.n do
- self.t[i]:drawLeaves()
- end
- end
- function Trees:move(x,y)
- for i = 1, self.n do
- self.t[i].x = self.t[i].x + x
- self.t[i].y = self.t[i].y + y
- if self.t[i].y < -100 then
- self.t[i].x = math.random(WIDTH+200)-100
- self.t[i].y = HEIGHT + 100
- elseif self.t[i].y > HEIGHT + 100 then
- self.t[i].x = math.random(WIDTH+200)-100
- self.t[i].y = -100
- elseif self.t[i].x < -100 then
- self.t[i].y = math.random(HEIGHT+200)-100
- self.t[i].x = WIDTH + 100
- elseif self.t[i].x > WIDTH + 100 then
- self.t[i].y = math.random(HEIGHT+200)-100
- self.t[i].x = -100
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement