̬̬̬̈̬̬̬̬̈̬̬̬̬̬̪쬪̬̬̬̪쬪 >?˻˻˻˻˻˻˻˻˻˻-- title: Purple rain demo -- author: Brian D Simonds 191brian@gmail.com -- desc: Demo of rain -- site: website link -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua function Rand(a, b) return math.random(a, b) end t=0 maxSpeed = 4 maxDrops = 400 drops = {} splashes = {} gravity = 0.04 wind = 0 function TIC() cls(11) line(0, 135, 239, 135, 1) line(0, 134, 239, 134, 1) UpdateDrops() ShowDrops() ShowSplashes() UpdateSplashes() t=t+1 -- set wind if t%200 == 0 then wind = Rand(-1,1) end end function BOOT() AddDrops() end function AddDrops() local obj = {} local i = 0 for i = 0, maxDrops - 1 do obj = { x = Rand(-150, 389), y = Rand(-250, -20), len = Rand(4, 10), ySpeed = 1 } table.insert(drops, obj) end end -- AddDrops function ShowDrops() local obj = {} for i, obj in ipairs(drops) do line(obj.x, obj.y, obj.x, obj.y + obj.len, 1) end end -- showdrops function AddSplash(objs) local obj = {} obj = { x = objs.x, y = objs.y + objs.len - 2, xSpeed = 0.75, ySpeed = -1.25, life = Rand(3,10) } table.insert(splashes, obj) obj = { x = objs.x, y = objs.y + objs.len - 2, xSpeed = -0.75, ySpeed = -1.25, life = Rand(3,10) } table.insert(splashes, obj) end -- addsplash function ShowSplashes() local obj = {} for i, obj in ipairs(splashes) do if obj.life == 1 then pix(obj.x, obj.y, 12) else pix(obj.x, obj.y, 1) end end end function UpdateSplashes() local obj = {} for i, obj in ipairs(splashes) do obj.life = obj.life - 1 if obj.life < 1 then table.remove(splashes, i) else obj.x = obj.x + obj.xSpeed obj.y = obj.y + obj.ySpeed obj.ySpeed = obj.ySpeed + gravity end end end function UpdateDrops() local obj = {} for i, obj in ipairs(drops) do obj.y = obj.y + obj.ySpeed obj.x = obj.x + wind if obj.y + obj.len > 133 then AddSplash(obj) end if obj.y > 133 then obj.x = Rand(-150, 389) obj.y = Rand(-250, -20) obj.ySpeed = 1 else obj.ySpeed = obj.ySpeed + gravity if obj.ySpeed > maxSpeed then obj.ySpeed = maxSpeed end end end end -- updatedrops