Advertisement
lord_thekenny

Bonne annee :3

Sep 14th, 2021
1,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.75 KB | None | 0 0
  1. monit = peripheral.wrap("top")
  2. monit.setTextScale(0.5)
  3. x, y = monit.getSize()
  4. arrayFW = {}
  5. targs = { ... }
  6.  
  7. -- Constante --
  8. COLOR_ARRAY = {colors.white,colors.orange,colors.magenta,colors.lightBlue,colors.yellow,colors.lime,colors.pink,colors.cyan,colors.purple,colors.blue,colors.red}
  9. NB_FW = 15
  10. SPEED_MIN = 1
  11. SPEED_MAX = 3
  12. EXPLODE_MIN = 5
  13. EXPLODE_MAX = 12
  14. DISTANCE_MIN = EXPLODE_MAX
  15. DISTANCE_MAX = math.floor(y / 2)
  16. X_MIN = EXPLODE_MAX
  17. X_MAX = x - EXPLODE_MAX
  18.  
  19. -- TEXT --
  20. TEXT1 ={  
  21. '      :::::::::   ::::::::  ::::    ::: ::::    ::: ::::::::::           :::     ::::    ::: ::::    ::: :::::::::: :::::::::: :::',
  22. '     :+:    :+: :+:    :+: :+:+:   :+: :+:+:   :+: :+:                :+: :+:   :+:+:   :+: :+:+:   :+: :+:        :+:        :+: ',
  23. '    +:+    +:+ +:+    +:+ :+:+:+  +:+ :+:+:+  +:+ +:+               +:+   +:+  :+:+:+  +:+ :+:+:+  +:+ +:+        +:+        +:+  ',
  24. '   +#++:++#+  +#+    +:+ +#+ +:+ +#+ +#+ +:+ +#+ +#++:++#         +#++:++#++: +#+ +:+ +#+ +#+ +:+ +#+ +#++:++#   +#++:++#   +#+   ',
  25. '  +#+    +#+ +#+    +#+ +#+  +#+#+# +#+  +#+#+# +#+              +#+     +#+ +#+  +#+#+# +#+  +#+#+# +#+        +#+        +#+    ',
  26. ' #+#    #+# #+#    #+# #+#   #+#+# #+#   #+#+# #+#              #+#     #+# #+#   #+#+# #+#   #+#+# #+#        #+#                ',
  27. '#########   ########  ###    #### ###    #### ##########       ###     ### ###    #### ###    #### ########## ########## ###      '
  28. }
  29.  
  30. TEXT2 ={
  31. '      ## #   #   ######     ######                 #          ######     ######                         ### ',
  32. '    ##   #   #                       ##########    #   ###                        ########## ########## ### ',
  33. '  ## #   #   # ########## ##########         #     ####     ########## ##########         #          #  ### ',
  34. '##   #   #   # #        # #        #        #      #        #        # #        #        #          #    #  ',
  35. '     #      #         ##         ##      # #       #               ##         ##      # #        # #        ',
  36. '     #     #        ##         ##         #        #             ##         ##         #          #     ### ',
  37. '     #   ##       ##         ##            #        #######    ##         ##            #          #    ### '
  38. }
  39.  
  40. TEXT3 = {
  41. '########   #######  ##    ## ##    ## ########       ###    ##    ## ##    ## ######## ######## ####',
  42. '##     ## ##     ## ###   ## ###   ## ##            ## ##   ###   ## ###   ## ##       ##       ####',
  43. '##     ## ##     ## ####  ## ####  ## ##           ##   ##  ####  ## ####  ## ##       ##       ####',
  44. '########  ##     ## ## ## ## ## ## ## ######      ##     ## ## ## ## ## ## ## ######   ######    ## ',
  45. '##     ## ##     ## ##  #### ##  #### ##          ######### ##  #### ##  #### ##       ##           ',
  46. '##     ## ##     ## ##   ### ##   ### ##          ##     ## ##   ### ##   ### ##       ##       ####',
  47. '########   #######  ##    ## ##    ## ########    ##     ## ##    ## ##    ## ######## ######## ####'
  48. }
  49.  
  50. TEXT = TEXT3
  51.  
  52. Y_TEXT = DISTANCE_MAX-math.floor(#TEXT/2)
  53. X_TEXT = math.floor(x / 2)-math.floor(#TEXT[1]/ 2)
  54.  
  55. -- Methode --
  56. function DrawPixel(xp,yp,color)
  57.     monit.setBackgroundColor(color)
  58.     monit.setCursorPos(xp,yp)
  59.     monit.write(' ')
  60. end
  61.  
  62. function DrawPixelExplode(xp,yp,explodeBlow,color)
  63.     monit.setBackgroundColor(color)
  64.     monit.setCursorPos(xp,yp + (explodeBlow+1) )-- top
  65.     monit.write(' ')
  66.     monit.setCursorPos(xp,yp - (explodeBlow+1) )-- bottom
  67.     monit.write(' ')
  68.     monit.setCursorPos(xp + (explodeBlow+1) ,yp)-- est
  69.     monit.write(' ')
  70.     monit.setCursorPos(xp - (explodeBlow+1) ,yp)-- ouest
  71.     monit.write(' ')
  72.     monit.setCursorPos(xp + explodeBlow ,yp + explodeBlow)-- top/est
  73.     monit.write(' ')
  74.     monit.setCursorPos(xp - explodeBlow ,yp + explodeBlow)-- top/ouest
  75.     monit.write(' ')
  76.     monit.setCursorPos(xp + explodeBlow ,yp - explodeBlow)-- Bottom/est
  77.     monit.write(' ')
  78.     monit.setCursorPos(xp - explodeBlow ,yp - explodeBlow)-- Bottom/ouest
  79.     monit.write(' ')
  80. end
  81.  
  82. -- ****************** --
  83. --** Class FireWork **--
  84. -- ****************** --
  85. FireWork = {
  86.     x = 0,
  87.     y = y-1,
  88.     ExplodeBlow = 0,
  89.     xDeb = 1,
  90.     yDeb = y-1,
  91.     speed = 0,
  92.     MaxDistance = 0;
  93.     MaxExplode = 0;
  94.     colorIndex = 1;
  95.     new = function(self)
  96.         local new = {}
  97.         setmetatable(new, {__index = self})
  98.         new:autoRandom()
  99.         return new
  100.     end,
  101.     autoRandom = function(self)
  102.         self.speed = math.random(SPEED_MIN,SPEED_MAX)
  103.         self.xDeb = math.random(X_MIN,X_MAX)
  104.         self.MaxDistance = math.random(DISTANCE_MIN,DISTANCE_MAX)
  105.         self.MaxExplode = math.random(EXPLODE_MIN,EXPLODE_MAX)
  106.         self.colorIndex = math.random(1,#COLOR_ARRAY)
  107.         self.x = self.xDeb
  108.         self.y = self.yDeb
  109.         self.ExplodeBlow = 0
  110.     end,
  111.     checkIsExplode = function(self)
  112.         return self.MaxDistance >= self.y
  113.     end,
  114.     checkIsfinish = function(self)
  115.         return self.ExplodeBlow >= self.MaxExplode
  116.     end,
  117.     flyUp = function(self)
  118.         -- On retire l'ancien pixel
  119.         if self.y+self.speed <= self.yDeb then
  120.             DrawPixel(self.x,self.y+self.speed,colors.black)
  121.         end
  122.  
  123.         -- On ajoute le nouveau pixel
  124.         DrawPixel(self.x,self.y,COLOR_ARRAY[self.colorIndex])
  125.  
  126.         -- On enregistre le deplacement
  127.         self.y = self.y-self.speed
  128.     end,
  129.     explode = function(self)
  130.         -- recentrage avant explosion
  131.         if self.ExplodeBlow == 0 then
  132.             DrawPixel(self.x,self.y+self.speed,colors.black)
  133.             DrawPixel(self.x,self.y,COLOR_ARRAY[self.colorIndex])
  134.         else
  135.             -- supprimer le centre
  136.             if self.ExplodeBlow == 1 then
  137.                 DrawPixel(self.x,self.y,colors.black)
  138.             else -- supprimer toute l'explosion
  139.                 DrawPixelExplode(self.x,self.y,self.ExplodeBlow-1,colors.black)
  140.             end
  141.  
  142.             -- On ajoute le pixel de l'explosion
  143.             DrawPixelExplode(self.x,self.y,self.ExplodeBlow,COLOR_ARRAY[self.colorIndex])
  144.         end
  145.  
  146.         -- On enregistre le deplacement de l'explosion
  147.         self.ExplodeBlow = self.ExplodeBlow+1
  148.     end,
  149.     disipeExplode = function(self)
  150.         DrawPixelExplode(self.x,self.y,self.ExplodeBlow-1,colors.black)
  151.     end
  152. }
  153.  
  154. -- init --
  155. monit.setBackgroundColor(colors.black)
  156. monit.clear()
  157. math.randomseed(os.time())
  158. for i=1,NB_FW do
  159.     arrayFW[i] = FireWork:new()
  160. end
  161.  
  162. -- Boucle du program --
  163. while true do
  164.     for i=1, #arrayFW do
  165.         local aFW = arrayFW[i]
  166.         if aFW:checkIsExplode() then
  167.             if aFW:checkIsfinish() then
  168.                 -- Si on est a la fin de l'explosion on reste le FireWork
  169.                 aFW:disipeExplode()
  170.                 aFW:autoRandom()
  171.             else
  172.                 -- Si il a pas fini on continue l'explosion
  173.                 aFW:explode()
  174.             end
  175.         else
  176.             -- le FireWork continue son chemin
  177.             aFW:flyUp()
  178.         end
  179.     end
  180.  
  181.     monit.setBackgroundColor(colors.black)
  182.     for i=1,#TEXT do
  183.         monit.setCursorPos(X_TEXT,Y_TEXT+i)
  184.         monit.write(TEXT[i])
  185.     end
  186.    
  187.     sleep(0.2)
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement