Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. --@name Render_SpherifyDots
  2. --@author BodyulCG
  3. --@client
  4.  
  5. local rtRes = 1024
  6. local rtCenter = rtRes / 2
  7.  
  8. local n = 23
  9. local radius = 200
  10. local lineHeight = 150
  11. local dotSize = 2
  12. local spacing = (radius * 2) / n
  13. local offsetX, offsetY = 0, 0
  14.  
  15. local function updateOffset()
  16. local curX, curY = render.cursorPos(player())
  17.  
  18. if curX != nil then
  19. curX, curY = curX * 2 - rtCenter, curY * 2 - rtCenter
  20. offsetX = math.mod(offsetX + curX / 30, spacing)
  21. offsetY = math.mod(offsetY + curY / 30, spacing)
  22. end
  23. end
  24.  
  25. local function drawNGon(x, y, r, sides, outline)
  26. if outline then
  27. local prevPos
  28. for i = 0, sides do
  29. local ang = math.rad(360.0 / sides * i)
  30. local newPos = {x = math.cos(ang) * r + x, y = math.sin(ang) * r + y}
  31. if prevPos != nil then render.drawLine(prevPos.x, prevPos.y, newPos.x, newPos.y) end
  32. prevPos = newPos
  33. end
  34. else
  35. local verts = {}
  36. for i = 0, sides - 1 do
  37. local ang = math.rad(360.0 / sides * i)
  38. verts[i+1] = {x = math.cos(ang) * r + x, y = math.sin(ang) * r + y}
  39. end
  40. render.drawPoly(verts)
  41. end
  42. end
  43.  
  44. local function draw()
  45. render.setColor(Color(255, 255, 255, 20))
  46. drawNGon(rtCenter, rtCenter, radius, 50, true)
  47.  
  48. for i = -1, n do
  49. for j = -1, n do
  50. local x = i * spacing - radius + rtCenter - offsetX
  51. local y = j * spacing - radius + rtCenter - offsetY
  52.  
  53. local vec = Vector(x - rtCenter, y - rtCenter)
  54. local lengthVec = vec:getLength2D()
  55. local spherifyDir = Vector(x - rtCenter, y - rtCenter) / lengthVec
  56.  
  57. local t1 = 1.0 / radius * math.clamp(lengthVec, 0, radius)
  58. local x1 = math.lerp(t1, x - rtCenter, spherifyDir.x * radius) + rtCenter
  59. local y1 = math.lerp(t1, y - rtCenter, spherifyDir.y * radius) + rtCenter
  60. local rSize = dotSize * (1.0 - t1)
  61.  
  62. render.drawRect(x1 - rSize, y1 - rSize, rSize * 2 + 1, rSize * 2 + 1)
  63.  
  64. local t2 = -math.cos(math.pi * t1 * 2) / 2 + 0.5
  65. local x2 = math.lerp(t2, x1 - rtCenter, spherifyDir.x * (radius + lineHeight)) + rtCenter
  66. local y2 = math.lerp(t2, y1 - rtCenter, spherifyDir.y * (radius + lineHeight)) + rtCenter
  67.  
  68. render.setColor(Color(0, 255, 50))
  69. render.drawLine(x1, y1, x2, y2)
  70. end
  71. end
  72. end
  73.  
  74. local fps = 60
  75. local dt = 1.0 / fps
  76. local oldClock = os.clock()
  77.  
  78. render.createRenderTarget("RT")
  79. hook.add("render", "", function()
  80. if (os.clock() - oldClock) > dt then
  81. render.selectRenderTarget("RT")
  82. render.clear(Color(5, 5, 5))
  83.  
  84. --render.setColor(Color(20, 20, 20, 15))
  85. --render.drawRect(0, 0, rtRes, rtRes)
  86.  
  87. updateOffset()
  88. draw()
  89.  
  90. render.selectRenderTarget()
  91.  
  92. oldClock = os.clock()
  93. end
  94.  
  95. render.setRenderTargetTexture("RT")
  96. render.setRGBA(255, 255, 255, 255)
  97. render.drawTexturedRect(0, 0, 512, 512)
  98. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement