Advertisement
LDDestroier

CC circle screensaver test

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