Advertisement
billysback

WaterSim

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