Advertisement
Marech

Monitor_Animation

Jul 30th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. local X, Y, DIRECTION, LONGUEUR, COULEUR = 1, 2, 3, 4, 5
  2. local NORD, EST, SUD, OUEST = 1, 2, 3, 4
  3.  
  4. term.clear()
  5. term.setBackgroundColor(1)
  6. term.setTextColor(32768)
  7. term.clear()
  8. term.setCursorPos(1,1)
  9.  
  10. local monitor = peripheral.wrap( "top" )
  11. local W, H = monitor.getSize()
  12. local lines = { }
  13.  
  14. function createLine(lines)
  15.     direction = math.random(1,4)
  16.     if direction == NORD then
  17.         x = math.random(1,W)
  18.         y = H
  19.     elseif direction == EST then
  20.         x = 1
  21.         y = math.random(1,H)
  22.     elseif direction == SUD then
  23.         x = math.random(1,W)
  24.         y = 1
  25.     elseif direction == OUEST then
  26.         x = W
  27.         y = math.random(1,H)
  28.     end
  29.    
  30.     line = {x, y, direction, math.random(2,6), math.random(1,32769)}
  31.     -- line = {2, 10, 1, 2, colors.black}
  32.     table.insert(lines, line)
  33. end
  34.  
  35. function moveLines(lines)
  36.     for i, l in ipairs(lines) do
  37.         if l[DIRECTION] == NORD then
  38.             if inBounds(l[X],l[Y]-l[LONGUEUR]) then
  39.                 paintutils.drawPixel(l[X],l[Y], colors.white)
  40.                 paintutils.drawPixel(l[X],l[Y]-l[LONGUEUR], l[COULEUR])
  41.                 l[Y] = l[Y]-1
  42.             elseif inBounds(l[X],l[Y]-l[LONGUEUR]) == false and l[LONGUEUR]>1 then
  43.                 l[LONGUEUR] = l[LONGUEUR]-1
  44.                 paintutils.drawPixel(l[X],l[Y], colors.white)
  45.                 paintutils.drawPixel(l[X],l[Y]-l[LONGUEUR], l[COULEUR])
  46.                 l[Y] = l[Y]-1
  47.             else
  48.                 table.remove(lines,i)
  49.             end
  50.         elseif l[DIRECTION] == EST then
  51.             if inBounds(l[X]+l[LONGUEUR],l[Y]) then
  52.                 paintutils.drawPixel(l[X],l[Y], colors.white)
  53.                 paintutils.drawPixel(l[X]+l[LONGUEUR],l[Y], l[COULEUR])
  54.                 l[X] = l[X]+1
  55.             elseif inBounds(l[X]+l[LONGUEUR],l[Y]) == false and l[LONGUEUR]>1 then
  56.                 l[LONGUEUR] = l[LONGUEUR]-1
  57.                 paintutils.drawPixel(l[X],l[Y], colors.white)
  58.                 paintutils.drawPixel(l[X]+l[LONGUEUR],l[Y], l[COULEUR])
  59.                 l[X] = l[X]+1
  60.             else
  61.                 table.remove(lines,i)
  62.             end
  63.         elseif l[DIRECTION] == SUD then
  64.             if inBounds(l[X],l[Y]-l[LONGUEUR]) then
  65.                 paintutils.drawPixel(l[X],l[Y], colors.white)
  66.                 paintutils.drawPixel(l[X],l[Y]+l[LONGUEUR], l[COULEUR])
  67.                 l[Y] = l[Y]+1
  68.             elseif inBounds(l[X],l[Y]+l[LONGUEUR]) == false and l[LONGUEUR]>1 then
  69.                 l[LONGUEUR] = l[LONGUEUR]-1
  70.                 paintutils.drawPixel(l[X],l[Y], colors.white)
  71.                 paintutils.drawPixel(l[X],l[Y]+l[LONGUEUR], l[COULEUR])
  72.                 l[Y] = l[Y]+1
  73.             else
  74.                 table.remove(lines,i)
  75.             end
  76.         elseif l[DIRECTION] == OUEST then
  77.             if inBounds(l[X]-l[LONGUEUR],l[Y]) then
  78.                 paintutils.drawPixel(l[X],l[Y], colors.white)
  79.                 paintutils.drawPixel(l[X]-l[LONGUEUR],l[Y], l[COULEUR])
  80.                 l[X] = l[X]-1
  81.             elseif inBounds(l[X]-l[LONGUEUR],l[Y]) == false and l[LONGUEUR]>1 then
  82.                 l[LONGUEUR] = l[LONGUEUR]-1
  83.                 paintutils.drawPixel(l[X],l[Y], colors.white)
  84.                 paintutils.drawPixel(l[X]-l[LONGUEUR],l[Y], l[COULEUR])
  85.                 l[X] = l[X]-1
  86.             else
  87.                 table.remove(lines,i)
  88.             end
  89.         end
  90.    
  91.     end
  92.  
  93.        
  94. end
  95.  
  96. function inBounds(x,y)
  97.     if x>=0 and x<=W+1 and y>=0 and y<=H+1 then
  98.         return true
  99.     end
  100.     return false
  101. end
  102.  
  103. createLine(lines)
  104. createLine(lines)
  105. createLine(lines)
  106. createLine(lines)
  107.  
  108. while table.getn(lines) ~= 0 do
  109.     if table.getn(lines) < 40 then 
  110.         createLine(lines)
  111.     end
  112.     moveLines(lines)
  113.     sleep(0.01)
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement