Advertisement
Symmetryc

Circle Animation

Jun 21st, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. -- Circle Loading Animation, By Symmetryc
  2.  
  3. -- # Configuration # --
  4. local back_color = colors.white
  5. local dither_color = colors.lightBlue
  6. local dither_char = "#"
  7. local dither_len = 10
  8. local solid_color = colors.lightBlue
  9. local solid_len = dither_len * 3
  10. local speed = 7
  11. local radius = 10
  12. local thickness = 2
  13. local size_x, size_y = term.getSize()
  14. local center_x, center_y = size_x / 2, size_y / 2
  15. local y_comp = 2 / 3
  16. local text = "<Loading Text>"
  17. local text_color = colors.cyan
  18. local text_back = back_color
  19. local text_x, text_y = center_x - #text / 2, center_y
  20.  
  21. -- # Code # --
  22. local x, y, n
  23. local sin, cos = math.sin, math.cos
  24. local pi = math.pi
  25. local up = math.ceil
  26. local draw_pixel = function(back, text, char, from, to)
  27.     term.setBackgroundColor(back)
  28.     term.setTextColor(text)
  29.     for i = from, to do
  30.         n = pi * i / 180
  31.         for j = radius, radius + thickness do
  32.             x = center_x + j * sin(n)
  33.             y = center_y + j * y_comp * cos(n)
  34.             term.setCursorPos(up(x > center_x and x - 1 or x), up(y))
  35.             term.write(char)
  36.         end
  37.     end
  38. end
  39.  
  40. term.setBackgroundColor(back_color)
  41. term.clear()
  42. term.setCursorPos(up(text_x), up(text_y))
  43. term.setTextColor(text_color)
  44. term.setBackgroundColor(text_back)
  45. term.write(text)
  46. local inc
  47. while true do
  48.     for i = 1, 360, speed do
  49.         draw_pixel(back_color, back_color, " ", i - speed, i)
  50.         inc = i
  51.         draw_pixel(back_color, dither_color, dither_char, inc + 1, inc + dither_len)
  52.         inc = inc + dither_len
  53.         draw_pixel(solid_color, solid_color, " ", inc + 1, inc + solid_len)
  54.         inc = inc + solid_len
  55.         draw_pixel(back_color, dither_color, dither_char, inc + 1, inc + dither_len)
  56.         os.queueEvent("circle")
  57.         os.pullEvent("circle")
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement