Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --@name Render_SpherifyDots
- --@author BodyulCG
- --@client
- local rtRes = 1024
- local rtCenter = rtRes / 2
- local n = 23
- local radius = 200
- local lineHeight = 150
- local dotSize = 2
- local spacing = (radius * 2) / n
- local offsetX, offsetY = 0, 0
- local function updateOffset()
- local curX, curY = render.cursorPos(player())
- if curX != nil then
- curX, curY = curX * 2 - rtCenter, curY * 2 - rtCenter
- offsetX = math.mod(offsetX + curX / 30, spacing)
- offsetY = math.mod(offsetY + curY / 30, spacing)
- end
- end
- local function drawNGon(x, y, r, sides, outline)
- if outline then
- local prevPos
- for i = 0, sides do
- local ang = math.rad(360.0 / sides * i)
- local newPos = {x = math.cos(ang) * r + x, y = math.sin(ang) * r + y}
- if prevPos != nil then render.drawLine(prevPos.x, prevPos.y, newPos.x, newPos.y) end
- prevPos = newPos
- end
- else
- local verts = {}
- for i = 0, sides - 1 do
- local ang = math.rad(360.0 / sides * i)
- verts[i+1] = {x = math.cos(ang) * r + x, y = math.sin(ang) * r + y}
- end
- render.drawPoly(verts)
- end
- end
- local function draw()
- render.setColor(Color(255, 255, 255, 20))
- drawNGon(rtCenter, rtCenter, radius, 50, true)
- for i = -1, n do
- for j = -1, n do
- local x = i * spacing - radius + rtCenter - offsetX
- local y = j * spacing - radius + rtCenter - offsetY
- local vec = Vector(x - rtCenter, y - rtCenter)
- local lengthVec = vec:getLength2D()
- local spherifyDir = Vector(x - rtCenter, y - rtCenter) / lengthVec
- local t1 = 1.0 / radius * math.clamp(lengthVec, 0, radius)
- local x1 = math.lerp(t1, x - rtCenter, spherifyDir.x * radius) + rtCenter
- local y1 = math.lerp(t1, y - rtCenter, spherifyDir.y * radius) + rtCenter
- local rSize = dotSize * (1.0 - t1)
- render.drawRect(x1 - rSize, y1 - rSize, rSize * 2 + 1, rSize * 2 + 1)
- local t2 = -math.cos(math.pi * t1 * 2) / 2 + 0.5
- local x2 = math.lerp(t2, x1 - rtCenter, spherifyDir.x * (radius + lineHeight)) + rtCenter
- local y2 = math.lerp(t2, y1 - rtCenter, spherifyDir.y * (radius + lineHeight)) + rtCenter
- render.setColor(Color(0, 255, 50))
- render.drawLine(x1, y1, x2, y2)
- end
- end
- end
- local fps = 60
- local dt = 1.0 / fps
- local oldClock = os.clock()
- render.createRenderTarget("RT")
- hook.add("render", "", function()
- if (os.clock() - oldClock) > dt then
- render.selectRenderTarget("RT")
- render.clear(Color(5, 5, 5))
- --render.setColor(Color(20, 20, 20, 15))
- --render.drawRect(0, 0, rtRes, rtRes)
- updateOffset()
- draw()
- render.selectRenderTarget()
- oldClock = os.clock()
- end
- render.setRenderTargetTexture("RT")
- render.setRGBA(255, 255, 255, 255)
- render.drawTexturedRect(0, 0, 512, 512)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement