Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monit = peripheral.wrap("top")
- monit.setTextScale(0.5)
- x, y = monit.getSize()
- arrayFW = {}
- targs = { ... }
- -- Constante --
- COLOR_ARRAY = {colors.white,colors.orange,colors.magenta,colors.lightBlue,colors.yellow,colors.lime,colors.pink,colors.cyan,colors.purple,colors.blue,colors.red}
- NB_FW = 15
- SPEED_MIN = 1
- SPEED_MAX = 3
- EXPLODE_MIN = 5
- EXPLODE_MAX = 12
- DISTANCE_MIN = EXPLODE_MAX
- DISTANCE_MAX = math.floor(y / 2)
- X_MIN = EXPLODE_MAX
- X_MAX = x - EXPLODE_MAX
- -- TEXT --
- TEXT1 ={
- ' ::::::::: :::::::: :::: ::: :::: ::: :::::::::: ::: :::: ::: :::: ::: :::::::::: :::::::::: :::',
- ' :+: :+: :+: :+: :+:+: :+: :+:+: :+: :+: :+: :+: :+:+: :+: :+:+: :+: :+: :+: :+: ',
- ' +:+ +:+ +:+ +:+ :+:+:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ :+:+:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ ',
- ' +#++:++#+ +#+ +:+ +#+ +:+ +#+ +#+ +:+ +#+ +#++:++# +#++:++#++: +#+ +:+ +#+ +#+ +:+ +#+ +#++:++# +#++:++# +#+ ',
- ' +#+ +#+ +#+ +#+ +#+ +#+#+# +#+ +#+#+# +#+ +#+ +#+ +#+ +#+#+# +#+ +#+#+# +#+ +#+ +#+ ',
- ' #+# #+# #+# #+# #+# #+#+# #+# #+#+# #+# #+# #+# #+# #+#+# #+# #+#+# #+# #+# ',
- '######### ######## ### #### ### #### ########## ### ### ### #### ### #### ########## ########## ### '
- }
- TEXT2 ={
- ' ## # # ###### ###### # ###### ###### ### ',
- ' ## # # ########## # ### ########## ########## ### ',
- ' ## # # # ########## ########## # #### ########## ########## # # ### ',
- '## # # # # # # # # # # # # # # # # ',
- ' # # ## ## # # # ## ## # # # # ',
- ' # # ## ## # # ## ## # # ### ',
- ' # ## ## ## # ####### ## ## # # ### '
- }
- TEXT3 = {
- '######## ####### ## ## ## ## ######## ### ## ## ## ## ######## ######## ####',
- '## ## ## ## ### ## ### ## ## ## ## ### ## ### ## ## ## ####',
- '## ## ## ## #### ## #### ## ## ## ## #### ## #### ## ## ## ####',
- '######## ## ## ## ## ## ## ## ## ###### ## ## ## ## ## ## ## ## ###### ###### ## ',
- '## ## ## ## ## #### ## #### ## ######### ## #### ## #### ## ## ',
- '## ## ## ## ## ### ## ### ## ## ## ## ### ## ### ## ## ####',
- '######## ####### ## ## ## ## ######## ## ## ## ## ## ## ######## ######## ####'
- }
- TEXT = TEXT3
- Y_TEXT = DISTANCE_MAX-math.floor(#TEXT/2)
- X_TEXT = math.floor(x / 2)-math.floor(#TEXT[1]/ 2)
- -- Methode --
- function DrawPixel(xp,yp,color)
- monit.setBackgroundColor(color)
- monit.setCursorPos(xp,yp)
- monit.write(' ')
- end
- function DrawPixelExplode(xp,yp,explodeBlow,color)
- monit.setBackgroundColor(color)
- monit.setCursorPos(xp,yp + (explodeBlow+1) )-- top
- monit.write(' ')
- monit.setCursorPos(xp,yp - (explodeBlow+1) )-- bottom
- monit.write(' ')
- monit.setCursorPos(xp + (explodeBlow+1) ,yp)-- est
- monit.write(' ')
- monit.setCursorPos(xp - (explodeBlow+1) ,yp)-- ouest
- monit.write(' ')
- monit.setCursorPos(xp + explodeBlow ,yp + explodeBlow)-- top/est
- monit.write(' ')
- monit.setCursorPos(xp - explodeBlow ,yp + explodeBlow)-- top/ouest
- monit.write(' ')
- monit.setCursorPos(xp + explodeBlow ,yp - explodeBlow)-- Bottom/est
- monit.write(' ')
- monit.setCursorPos(xp - explodeBlow ,yp - explodeBlow)-- Bottom/ouest
- monit.write(' ')
- end
- -- ****************** --
- --** Class FireWork **--
- -- ****************** --
- FireWork = {
- x = 0,
- y = y-1,
- ExplodeBlow = 0,
- xDeb = 1,
- yDeb = y-1,
- speed = 0,
- MaxDistance = 0;
- MaxExplode = 0;
- colorIndex = 1;
- new = function(self)
- local new = {}
- setmetatable(new, {__index = self})
- new:autoRandom()
- return new
- end,
- autoRandom = function(self)
- self.speed = math.random(SPEED_MIN,SPEED_MAX)
- self.xDeb = math.random(X_MIN,X_MAX)
- self.MaxDistance = math.random(DISTANCE_MIN,DISTANCE_MAX)
- self.MaxExplode = math.random(EXPLODE_MIN,EXPLODE_MAX)
- self.colorIndex = math.random(1,#COLOR_ARRAY)
- self.x = self.xDeb
- self.y = self.yDeb
- self.ExplodeBlow = 0
- end,
- checkIsExplode = function(self)
- return self.MaxDistance >= self.y
- end,
- checkIsfinish = function(self)
- return self.ExplodeBlow >= self.MaxExplode
- end,
- flyUp = function(self)
- -- On retire l'ancien pixel
- if self.y+self.speed <= self.yDeb then
- DrawPixel(self.x,self.y+self.speed,colors.black)
- end
- -- On ajoute le nouveau pixel
- DrawPixel(self.x,self.y,COLOR_ARRAY[self.colorIndex])
- -- On enregistre le deplacement
- self.y = self.y-self.speed
- end,
- explode = function(self)
- -- recentrage avant explosion
- if self.ExplodeBlow == 0 then
- DrawPixel(self.x,self.y+self.speed,colors.black)
- DrawPixel(self.x,self.y,COLOR_ARRAY[self.colorIndex])
- else
- -- supprimer le centre
- if self.ExplodeBlow == 1 then
- DrawPixel(self.x,self.y,colors.black)
- else -- supprimer toute l'explosion
- DrawPixelExplode(self.x,self.y,self.ExplodeBlow-1,colors.black)
- end
- -- On ajoute le pixel de l'explosion
- DrawPixelExplode(self.x,self.y,self.ExplodeBlow,COLOR_ARRAY[self.colorIndex])
- end
- -- On enregistre le deplacement de l'explosion
- self.ExplodeBlow = self.ExplodeBlow+1
- end,
- disipeExplode = function(self)
- DrawPixelExplode(self.x,self.y,self.ExplodeBlow-1,colors.black)
- end
- }
- -- init --
- monit.setBackgroundColor(colors.black)
- monit.clear()
- math.randomseed(os.time())
- for i=1,NB_FW do
- arrayFW[i] = FireWork:new()
- end
- -- Boucle du program --
- while true do
- for i=1, #arrayFW do
- local aFW = arrayFW[i]
- if aFW:checkIsExplode() then
- if aFW:checkIsfinish() then
- -- Si on est a la fin de l'explosion on reste le FireWork
- aFW:disipeExplode()
- aFW:autoRandom()
- else
- -- Si il a pas fini on continue l'explosion
- aFW:explode()
- end
- else
- -- le FireWork continue son chemin
- aFW:flyUp()
- end
- end
- monit.setBackgroundColor(colors.black)
- for i=1,#TEXT do
- monit.setCursorPos(X_TEXT,Y_TEXT+i)
- monit.write(TEXT[i])
- end
- sleep(0.2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement