Whitemambaa

Splash 3.0

Jul 2nd, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.84 KB | None | 0 0
  1. --By xXxMoNkEyMaNxXx (Whitemambaa)
  2. local arg={
  3.         monitor=term,
  4.         speed=14,
  5.         length=6,
  6.         rolloff=1.1,
  7.         damping=6,
  8. }
  9. local argtypes={
  10.         monitor="peripheral",
  11.         speed="number",
  12.         length="number",
  13.         rolloff="number",
  14.         damping="number",
  15. }
  16. for parameter,value in table.concat({...}," "):gmatch'%-([%w_]+) ([^ ]+)' do
  17.         local argtype=argtypes[parameter]
  18.         if argtype=="string" then
  19.                 arg[parameter]=tostring(value) or arg[parameter]
  20.         elseif argtype=="number" then
  21.                 arg[parameter]=tonumber(value) or arg[parameter]
  22.         elseif argtype=="boolean" then
  23.                 arg[parameter]=value=="true" or arg[parameter]
  24.         elseif argtype=="peripheral" then
  25.                 arg[parameter]=peripheral.wrap(value) or arg[parameter]
  26.         end
  27. end
  28.  
  29. arg.monitor.setTextScale(0.5)
  30.  
  31. local next=next
  32. local time=os.time
  33. local tick=os.clock
  34.  
  35. local pi=math.pi
  36. local max=math.max
  37. local min=math.min
  38. local sin=math.sin
  39. local sqrt=math.sqrt
  40. local ceil=math.ceil
  41. local floor=math.floor
  42.  
  43. local match=string.match
  44.  
  45. local remove=table.remove
  46.  
  47. local pull=os.pullEvent
  48. local setAlarm=os.setAlarm
  49.  
  50. local paint=arg.monitor.write
  51. local setPos=arg.monitor.setCursorPos
  52. local setBGC=arg.monitor.setBackgroundColour
  53.  
  54. --local palette={colours.lightBlue,colours.cyan,colours.blue,colours.black,colours.grey,colours.lightGrey,colours.white}
  55. local palette={colours.white,colours.lightGrey,colours.grey,colours.black,colours.blue,colours.cyan,colours.lightBlue}
  56.  
  57. local size={arg.monitor.getSize()}
  58. local gridsize={1.1,0.7}
  59. local maxAge=(sqrt(size[1]*size[1]+size[2]*size[2])+arg.length)/arg.speed
  60. local splashes={}
  61.  
  62. local damping=arg.damping
  63. local rolloff=arg.rolloff
  64.  
  65. --[[
  66. --wave function
  67. local function wave(x)
  68.         return sin(2*pi*x)--4*(x-x*x)*
  69. end
  70.  
  71. --damping coefficient
  72. local function damp(x)
  73.         return damping^-x
  74. end
  75.  
  76. --rolloff coefficient
  77. local function fade(x)
  78.         return rolloff^-x
  79. end
  80. --]]
  81.  
  82. local function draw(t)
  83.         local radii={}
  84.         for i=1,#splashes do
  85.                 radii[i]=(t-splashes[i].t)*arg.speed
  86.         end
  87.         for x=1,size[1] do
  88.                 for y=1,size[2] do
  89.                         local sum=0.5
  90.                         for i=1,#splashes do
  91.                                 local s=splashes[i]
  92.                                 local dx,dy=(s[1]-x)/gridsize[1],(s[2]-y)/gridsize[2]
  93.                                 local r=sqrt(dx*dx+dy*dy)
  94.                                 local d=(radii[i]-r)/arg.length
  95.                                 if d>=0 then
  96.                                         sum=sum+sin(2*pi*x)*damping^-x*rolloff^-x--wave(d)*damp(d)*fade(r)
  97.                                 end
  98.                         end
  99.                         setPos(x,y)
  100.                         setBGC(palette[max(1,min(#palette,ceil(#palette*sum)))])
  101.                         paint' '
  102.                 end
  103.         end
  104. end
  105.  
  106. do
  107.         arg.monitor.clear()
  108.         local message="Click Anywhere!"
  109.         setPos(floor((size[1]-#message)/2),floor(size[2]/2-0.5))
  110.         paint(message)
  111. end
  112.  
  113. local enabled=true
  114. while enabled do
  115.         local event={pull()}
  116.         local now=tick()
  117.         for i=#splashes,1,-1 do
  118.                 if now-splashes[i].t>=maxAge then
  119.                         remove(splashes,i)
  120.                 end
  121.         end
  122.         if event[1]=="mouse_click" or event[1]=="monitor_touch" then
  123.                 if #splashes==0 then
  124.                         setAlarm((time()+0.001)%24)
  125.                 end
  126.                 splashes[#splashes+1]={event[3],event[4],t=now}
  127.         end
  128.         if #splashes>0 then
  129.                 draw(now)
  130.                 if event[1]=="alarm" then
  131.                         setAlarm((time()+0.001)%24)
  132.                 end
  133.         end
  134. end
Advertisement
Add Comment
Please, Sign In to add comment