serafim7

скринсейвер SpaceX [OpenComputers]

Dec 26th, 2020 (edited)
996
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 1 0
  1. --https://github.com/IgorTimofeev/OpenComputers-1/tree/master/SpaceX
  2. --https://i.imgur.com/2VikNSK.gif
  3.  
  4. local component = require("component")
  5. local event = require("event")
  6. local gpu = component.gpu
  7. local w, h = gpu.getResolution()
  8. local depth = gpu.getDepth()
  9.  
  10. local starAmount = 100;
  11. local braille = {"⠁", "⠈", "⠂", "⠐", "⠄", "⠠", "⡀", "⢀", "⠛", "⣤"}
  12.  
  13. local stars = {}
  14. local i, rotationAngle, targetX, targetY, startWay, x, y, xmod, ymod, prevX, prevY, color
  15.  
  16. local function clearScreen()
  17.   gpu.setBackground(0x000000)
  18.   gpu.setForeground(0xFFFFFF)
  19.   gpu.fill(1, 1, w, h, " ")
  20. end
  21.  
  22. clearScreen()
  23. while true do
  24.   while #stars < starAmount do
  25.     rotationAngle = math.random(6265) / 1000
  26.     targetX = math.ceil(math.cos(rotationAngle) * w * 0.75 + w / 2)
  27.     targetY = math.ceil(math.sin(rotationAngle) * w * 0.375 + h / 2)
  28.     startWay = math.random()
  29.     table.insert(stars, {
  30.       targetX = targetX,
  31.       targetY = targetY,
  32.       startX = math.ceil((targetX - w / 2) * startWay + w / 2),
  33.       startY = math.ceil((targetY - h / 2) * startWay + h / 2),
  34.       prevX = -1,
  35.       prevY = -1,
  36.       way = 0.01,
  37.       speed = math.random(25, 75) / 1000 + 1,
  38.     })
  39.   end
  40.   i = 1
  41.   while i <= #stars do
  42.     x = (stars[i].targetX - stars[i].startX) * stars[i].way + stars[i].startX
  43.     y = (stars[i].targetY - stars[i].startY) * stars[i].way + stars[i].startY
  44.     xmod = math.floor(x * 2) % 2
  45.     ymod = math.floor(y * 4) % 4
  46.     x = math.floor(x)
  47.     y = math.floor(y)
  48.     if x > w or x <= 0 or y > h or y <= 0 then
  49.       gpu.set(stars[i].prevX, stars[i].prevY, " ")
  50.       table.remove(stars, i)
  51.     else
  52.       prevX = stars[i].prevX
  53.       prevY = stars[i].prevY
  54.       color = math.floor(stars[i].way * 1024)
  55.       if depth == 4 then
  56.         if color > 63 then
  57.           color = 255
  58.         end
  59.       else
  60.         if color > 255 then
  61.           color = 255
  62.         end
  63.       end
  64.       gpu.setForeground(math.floor(color + color * 0x100 + color * 0x10000), false)
  65.       if prevX ~= x or prevY ~= y then
  66.         gpu.set(prevX, prevY, " ")
  67.       end
  68.       stars[i].prevX = x
  69.       stars[i].prevY = y
  70.       stars[i].way = stars[i].way * stars[i].speed
  71.       if gpu.get(x, y) == " " then
  72.         if stars[i].way < 0.3 then
  73.            if xmod == 0 and ymod == 0 then gpu.set(x, y, braille[1])
  74.            elseif xmod == 1 and ymod == 0 then gpu.set(x, y, braille[2])
  75.            elseif xmod == 0 and ymod == 1 then gpu.set(x, y, braille[3])
  76.            elseif xmod == 1 and ymod == 1 then gpu.set(x, y, braille[4])
  77.            elseif xmod == 0 and ymod == 2 then gpu.set(x, y, braille[5])
  78.            elseif xmod == 1 and ymod == 2 then gpu.set(x, y, braille[6])
  79.            elseif xmod == 0 and ymod == 3 then gpu.set(x, y, braille[7])
  80.            elseif xmod == 1 and ymod == 3 then gpu.set(x, y, braille[8])
  81.            end
  82.         else
  83.           if ymod < 2 then
  84.             gpu.set(x, y, braille[9])
  85.           else
  86.             gpu.set(x, y, braille[10])
  87.           end
  88.         end
  89.       end
  90.       i = i + 1
  91.     end
  92.   end
  93.   local eventType, _, _, _ = event.pull(0)
  94.   if eventType == "touch" or eventType == "key_down" then
  95.     clearScreen()
  96.     break
  97.   end
  98. end
Add Comment
Please, Sign In to add comment