Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --snowflakes
- function setup()
- --put anywhere in setup
- flakes = {}
- for i = 1, 20 do
- flakes[i] = {cx=math.random(WIDTH),
- cy=math.random(HEIGHT),
- l=math.random(3,30),
- r=math.random(60),
- w=math.random(20)+3}
- end
- end
- function draw()
- --this section for demo only
- sprite("SpaceCute:Background",WIDTH/2,HEIGHT/2)
- sprite("Small World:Church",100,100)
- sprite("Small World:Court",200,300)
- sprite("Small World:Explosion",300,500)
- sprite("Small World:Tower",400,150)
- --place at end of draw loop
- stroke(255, 255, 255, 26)
- for k, v in pairs(flakes) do
- strokeWidth(flakes[k].w)
- draw_flake(flakes[k])
- flakes[k].cy = flakes[k].cy - math.random()
- --borrowed from bit invader
- sideMove = vec2( math.sin(flakes[k].cy * 0.02), 0 )
- flakes[k].cx = flakes[k].cx + sideMove.x
- flakes[k].r = flakes[k].r + math.random()
- if (flakes[k].cy + flakes[k].l) < 0 then
- flakes[k].l = math.random(3,30)
- flakes[k].cy = HEIGHT + flakes[k].l
- flakes[k].cx = math.random(WIDTH)
- end
- end
- end
- --required
- function draw_flake(fl)
- local f = vec2(0,fl.l)
- f = f:rotate(math.rad(fl.r))
- for i = 1, 6 do
- line(fl.cx,fl.cy,fl.cx+f.x,fl.cy+f.y)
- f = f:rotate(math.rad(60))
- end
- end
- --alternatives: convert this to a class, isolate with pushStyle and pushMatrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement