Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --@author
- --@shared
- --@client
- --[[
- function cerp(xd, yd, dd, x)
- local i = 1
- while xd[i] < x do
- i = i + 1
- local t = (x - xd[i-1]) / (xd[i] - xd[i-1])
- local a = dd[i-1]*(xd[i]-xd[i-1]) - (yd[i]-yd[i-1])
- local b = -dd[i ]*(xd[i]-xd[i-1]) + (yd[i]-yd[i-1])
- return (1-t)*yd[i-1] + t*yd[i] + t*(1-t)*(a*(1-t)+b*t)
- end
- end
- --]]
- function cerp(p1, p2, p3, p4, x)
- local a = 2*p2 - 2*p3 + p1 + p4
- local b = -3*p2 + 3*p3 - 2*p1 - p4
- local c = p1
- local d = p2
- return a*x^3 + b*x^2 + c*x + d
- end
- function cerp(v0, v1, v2, v3, x)
- local v0, v1, v2, v3 = v0 or 0, v1 or 0, v2 or 0, v3 or 0
- local a = (v3 - v2) - (v0 - v1)
- local b = (v0 - v1) - a
- local c = v2 - v0
- local d = v1
- return a*x^3 + b*x^2 + c*x + d
- end
- point = {Vector(0, 0), Vector(100, 256), Vector(200, 256), Vector(300, 500), Vector(400, 100), Vector(500, 500)}
- render.createRenderTarget("test")
- hook.add("render", "", function()
- local x, y = render.cursorPos(player())
- x, y = x or 0, y or 0
- point[2] = Vector(x, y)
- render.selectRenderTarget("test")
- render.setColor(Color(0, 0, 0, 255))
- render.drawRect(0, 0, 1024, 1024)
- render.setColor(Color(255))
- for i=1, 50 do
- local x1 = cerp(point[1], point[2], point[3], point[4], (1/50)*i-(1/50)).x
- local y1 = cerp(point[1], point[2], point[3], point[4], (1/50)*i-(1/50)).y
- local x2 = cerp(point[1], point[2], point[3], point[4], (1/50)*(i+1)-(1/50)).x
- local y2 = cerp(point[1], point[2], point[3], point[4], (1/50)*(i+1)-(1/50)).y
- render.drawLine(x1*2, y1*2, x2*2, y2*2)
- x1 = cerp(point[2], point[3], point[4], point[5], (1/50)*i-(1/50)).x
- y1 = cerp(point[2], point[3], point[4], point[5], (1/50)*i-(1/50)).y
- x2 = cerp(point[2], point[3], point[4], point[5], (1/50)*(i+1)-(1/50)).x
- y2 = cerp(point[2], point[3], point[4], point[5], (1/50)*(i+1)-(1/50)).y
- render.drawLine(x1*2, y1*2, x2*2, y2*2)
- x1 = cerp(point[3], point[4], point[5], point[6], (1/50)*i-(1/50)).x
- y1 = cerp(point[3], point[4], point[5], point[6], (1/50)*i-(1/50)).y
- x2 = cerp(point[3], point[4], point[5], point[6], (1/50)*(i+1)-(1/50)).x
- y2 = cerp(point[3], point[4], point[5], point[6], (1/50)*(i+1)-(1/50)).y
- render.drawLine(x1*2, y1*2, x2*2, y2*2)
- end
- render.selectRenderTarget(nil)
- render.setRenderTargetTexture("test")
- render.drawTexturedRect(0, 0, 512, 512)
- for k, v in pairs(point) do
- render.drawRect(v.x, v.y, 10, 10)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement