Advertisement
billysback

Water Sim

Sep 13th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. local width, height = term.getSize()
  2. local llvls = {}
  3.  
  4. local damt = 4
  5. local dskip = 5
  6. local dmax = 35
  7.  
  8. local dith = 30
  9. local dithd = damt
  10. local function getDither()
  11.     dith = dith + dithd
  12.     if dith >= dmax then dithd = -(damt) end
  13.     if dith <= -(dmax) then dithd = damt end
  14.     if dith <= dskip and dith >= -(dskip) then
  15.         if dithd == -(damt) then dith = -(dskip)-1
  16.         elseif dithd == damt then dith = dskip+1 end
  17.     end
  18.     return dith/10
  19. end
  20.  
  21. local stcmax = 115
  22. local stcmin = 75
  23. local stcamt = 2
  24.  
  25. local stc = stcmin
  26. local stcd = stcamt
  27. local function getStretch()
  28.     stc = stc + stcd
  29.     if stc >= stcmax then stcd = -(stcamt) end
  30.     if stc <= stcmin then stcd = stcamt end
  31.     return math.max( (stc/10) - 0.5 )
  32. end
  33.  
  34. local offset = 0
  35. local function draw()
  36.     offset = offset + 0.75
  37.     offset = (offset%width)
  38.     local dither = getDither()
  39.     local stretch = getStretch()
  40.     for x=1,width do
  41.         local lvl = math.max((math.sin((x-offset)/stretch)*(dither))-0.5) + math.floor(height/2)
  42.         local llvl = llvls[x]
  43.         if llvl == nil then llvl = 1 end
  44.         for y=1,height do
  45.             term.setCursorPos(x, y)
  46.             if y >= lvl then term.setBackgroundColor(colors.lightBlue)
  47.             else term.setBackgroundColor(colors.white) end
  48.             if y >= llvl then
  49.                 term.setBackgroundColor(colors.blue)
  50.             end
  51.             term.write(" ")
  52.         end
  53.         llvls[x] = lvl
  54.     end
  55. end
  56.  
  57. local pause = 0.05
  58.  
  59. local on = true
  60. local timer = os.startTimer(pause)
  61. while on do
  62.     local event, p1 = os.pullEvent()
  63.     if event == "timer" and p1 == timer then
  64.         draw()
  65.         timer = os.startTimer(pause)
  66.     elseif event == "key" then
  67.         if p1 == 29 then
  68.             on = false
  69.         end
  70.     end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement