Advertisement
LDDestroier

CC circle screensaver (actual circles)

Feb 18th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.47 KB | None | 0 0
  1. --[[
  2.  pastebin get rXQhBupz circle
  3.  std ld circle-scr circle
  4.  std pb rXQhBupz circle
  5. --]]
  6.  
  7. local sizediv = 1
  8. local bigno = 16
  9. local yieldNotSleep = true
  10.  
  11. local tArg = {...}
  12.  
  13. if tArg[1] == "blittle" then
  14.     sizediv = tArg[2] or sizediv
  15.     bigno = tArg[3] or bigno
  16.     if not fs.exists("blittle") then
  17.         local prog = http.get("http://pastebin.com/raw/ujchRSnU")
  18.         if not prog then
  19.             error("Could not get BLittle API.")
  20.         end
  21.         local file = fs.open("blittle","w")
  22.         file.write(prog.readAll())rXQhBupz
  23.         file.close()
  24.         print("Wrote to 'blittle'")
  25.     end
  26. else
  27.     sizediv = tonumber(tArg[1]) or sizediv
  28.     bigno = tonumber(tArg[2]) or bigno
  29. end
  30.  
  31. if term.current().setTextScale then term.current().setTextScale(0.5) end
  32.  
  33. if (fs.exists("blittle") or blittle) and tArg[1] == "blittle" then
  34.     os.loadAPI("blittle")
  35.     local mon = blittle.createWindow()
  36.     term.redirect(mon)
  37.     scr_x, scr_y = term.getSize()
  38. end
  39.  
  40. local scr_x, scr_y = term.getSize()
  41. local mx,my = scr_x/2,scr_y/2
  42.  
  43. local exitOnMouse = true
  44. local exitOnButton = true
  45.  
  46. local yield = function()
  47.     os.queueEvent("yield")
  48.     os.pullEvent("yield")
  49. end
  50.  
  51. local grayOut = function(color)
  52.     local c = _G.colors
  53.     local grays = {
  54.         [c.white] = c.white,
  55.         [c.orange] = c.lightGray,
  56.         [c.magenta] = c.lightGray,
  57.         [c.lightBlue] = c.lightGray,
  58.         [c.yellow] = c.white,
  59.         [c.lime] = c.lightGray,
  60.         [c.pink] = c.white,
  61.         [c.gray] = c.gray,
  62.         [c.lightGray] = c.lightGray,
  63.         [c.cyan] = c.gray,
  64.         [c.purple] = c.gray,
  65.         [c.blue] = c.gray,
  66.         [c.brown] = c.gray,
  67.         [c.green] = c.gray,
  68.         [c.red] = c.gray,
  69.         [c.black] = c.black,
  70.     }
  71.     local newColor = grays[color] or 1
  72.     return newColor
  73. end
  74.  
  75. local CTB = function(_color) --Color To Blit
  76.     local blitcolors = {
  77.         [colors.white] = "0",
  78.         [colors.orange] = "1",
  79.         [colors.magenta] = "2",
  80.         [colors.lightBlue] = "3",
  81.         [colors.yellow] = "4",
  82.         [colors.lime] = "5",
  83.         [colors.pink] = "6",
  84.         [colors.gray] = "7",
  85.         [colors.lightGray] = "8",
  86.         [colors.cyan] = "9",
  87.         [colors.purple] = "a",
  88.         [colors.blue] = "b",
  89.         [colors.brown] = "c",
  90.         [colors.green] = "d",
  91.         [colors.red] = "e",
  92.         [colors.black] = "f",
  93.     }
  94.     return blitcolors[_color]
  95. end
  96.  
  97. local getColor = function(num)
  98.     if term.isColor() then
  99.         return 2^(math.floor(num)%16)
  100.     else
  101.         return grayOut(2^(math.floor(num)%16))
  102.     end
  103. end
  104.  
  105. local spaces = string.rep(" ", scr_x)
  106. local render = function(dist,xshift,yshift)
  107.     local lines = {}
  108.     term.current().setVisible(false)
  109.     for y = 1, scr_y do
  110.         local line = {}
  111.         for x = 1, scr_x do
  112.             local thing = (math.sqrt((((x+xshift)-mx)^2)+(((y+yshift)-my)^2))+((dist/bigno)*(16*sizediv)))/sizediv
  113.             line[x] = CTB(getColor(thing))
  114.         end
  115.         lines[y] = table.concat(line)
  116.     end
  117.     for y = 1, scr_y do
  118.         term.setCursorPos(1,y)
  119.         term.blit(spaces, spaces, lines[y])
  120.     end
  121.     term.current().setVisible(true)
  122. end
  123.  
  124. local doAnimation = function()
  125.     local mult = 0
  126.     while true do
  127.         for a = 1, bigno do
  128.             render(a, (math.sin((a+(bigno*mult))/20)*(mx*0.8))+(math.cos((a+(bigno*mult))/30)*(mx/12)), ((math.cos((a+(bigno*mult))/20)*my)+(math.sin((a+(bigno*mult))/35)*(my/9))))
  129.             if yieldNotSleep then
  130.                 yield()
  131.             else
  132.                 sleep(0)
  133.             end
  134.         end
  135.         mult = mult + 1
  136.     end
  137. end
  138.  
  139. local waitForInput= function()
  140.     while true do
  141.         local evt = os.pullEvent()
  142.         if (evt == "char" and exitOnButton) or (evt == "mouse_click" and exitOnMouse) then
  143.             return
  144.         end
  145.     end
  146. end
  147.  
  148. parallel.waitForAny(waitForInput,doAnimation)
  149. term.setBackgroundColor(colors.black)
  150. term.clear()
  151. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement