Advertisement
adriweb

Untitled

Mar 4th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Localized math functions for faster access
  2. local mathfloor = math.floor
  3. local mathsqrt = math.sqrt
  4. local mathsin = math.sin
  5.  
  6. -- Globals
  7. screen1 = {}
  8. screen2 = {}
  9. screen3 = {}
  10. screenlist = {}
  11. screencount = 0
  12. pallet = {}
  13. plasma = {}
  14. w = platform.window:width()
  15. h = platform.window:height()
  16. tsize = 5
  17.  
  18. function on.arrowDown()
  19.     if tsize > 1 then tsize = tsize - 1 end
  20. end
  21. function on.arrowUp()
  22.     if tsize < 15 then tsize = tsize + 1 end
  23. end
  24.  
  25. function on.resize(ww,hh)
  26.     timer.stop()
  27.     w,h = ww,hh
  28.     init()
  29. end
  30.  
  31. function on.paint(gc)
  32.     local time = timer.getMilliSecCounter() / 10
  33.     local x,y = 0,0
  34.     while (x < w) do
  35.         while (y < h) do
  36.             local color = pallet[mathfloor((plasma[x][y] + time) % 256)]
  37.             gc:setColorRGB(color.r, color.g, color.b)
  38.             gc:fillRect(x, y, tsize, tsize)
  39.             y = y + tsize
  40.         end
  41.         x = x + tsize
  42.         y = 0
  43.     end
  44.     screencount = (screencount + 1) % 3
  45.     timer.start(0.01)
  46. end
  47.  
  48.  
  49. function dist(a, b, c, d)
  50.     return mathsqrt(((a - c) * (a - c) + (b - d) * (b - d)))
  51. end
  52.  
  53. function on.timer()
  54.     timer.stop()
  55.     platform.window:invalidate()
  56. end
  57.  
  58. function init()
  59.     pallet = {}
  60.     plasma = {}
  61.    
  62.     local r,g,b = 0,0,0
  63.     for i = 0, 256 do
  64.         pallet[i] = { r = mathfloor(128.0 + 128 * mathsin(3.1416 * i / 16.0)),
  65.                       g = mathfloor(128.0 + 128 * mathsin(3.1416 * i / 128.0)),
  66.                       b = 0 }
  67.     end
  68.  
  69.     for a = 0, w do
  70.         plasma[a] = {}
  71.         for b = 0, h do
  72.             plasma[a][b] = mathfloor(128.0 + (128.0 * mathsin(a / 16.0)) + 128.0 + (128.0 * mathsin(b / 16.0))) / 2
  73.         end
  74.     end
  75.    
  76.     timer.start(0.01)
  77. end
  78.  
  79. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement