Hi there,
I'm remaking my DarkRP Printer addon I made a few months ago ([URL="https://facepunch.com/showthread.php?t=1527161"]https://facepunch.com/showthread.php?t=1527161[/URL]), and I was wondering how I would lerp the circle? I want it so that instead of just changing it's angle immediately, it gradually works it's way up to that point.
Here's some of the code I'm working with:
[B]The circle function:[/B]
[CODE]
local function draw_circle(x, y, radius, seg, ang)
local cir = {}
table.insert(cir, {x = x, y = y, u = 0.5, v = 0.5})
for i = 0, (ang / 5) do
local a = math.rad(( i / (ang / 5)) * - ang)
table.insert(cir, {x = x + math.sin(a) * radius, y = y + math.cos(a) * radius, u = math.sin(a) / 2 + 0.5, v = math.cos(a) / 2 + 0.5})
end
draw.NoTexture()
surface.DrawPoly(cir)
end
[/CODE]
[B]How I'm using it:[/B]
[CODE]
local money = (self:GetNextPrint() * self.sharpCFG.PrintRate) / (self.sharpCFG.MaxAmount / 72)
local lerp = Lerp(10 * FrameTime(), 0, money)
surface.SetDrawColor(0, 120, 215, 75)
draw_circle(Width / 2, 137, 73, 20, lerp)
[/CODE]
Instead of the circle being smoothed out, it just glitches out a bit.
[I]I don't know how much code you might need in order to help me out, so if you need anything just let me know![/I] :smile:
I don't think Lerp works without a variable outside the drawing function... you need some kind of thing to continuously update or it will just be created with the same number each time
[CODE]function draw.PartialCircle( x, y, radius, seg , percent )
local cir = {}
percent = percent or 0
percent = percent / 100.0
table.insert( cir, { x = x, y = y, u = 0.5, v = 0.5 } )
for i = 0, seg do
local a = math.rad( ((( i / seg ) * -360) * percent ) + 180)
table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 } )
end
local a = math.rad( 0 )
surface.DrawPoly( cir )
end[/CODE]
This is the same as the above function except you can pass a percent value (between 0 and 100) and it will draw a circle with that percent, then you can just lerp the percent value like you would lerp any other standard value.
[QUOTE=0V3RR1D3;51454038][CODE]function draw.PartialCircle( x, y, radius, seg , percent )
local cir = {}
percent = percent or 0
percent = percent / 100.0
table.insert( cir, { x = x, y = y, u = 0.5, v = 0.5 } )
for i = 0, seg do
local a = math.rad( ((( i / seg ) * -360) * percent ) + 180)
table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 } )
end
local a = math.rad( 0 )
surface.DrawPoly( cir )
end[/CODE]
This is the same as the above function except you can pass a percent value (between 0 and 100) and it will draw a circle with that percent, then you can just lerp the percent value like you would lerp any other standard value.[/QUOTE]
I tried your code, and it's doing the same thing. The circle is just "twitching." Here's a GIF to show you what I mean ([URL="https://gyazo.com/8c36eb232882f908ca7a3db2447161df"]https://gyazo.com/8c36eb232882f908ca7a3db2447161df[/URL]).
I just realized I made a mistake, but now it's giving me a different result ([URL="https://gyazo.com/f9ac3df2ed47c59169ff439ddb60d56a"]https://gyazo.com/f9ac3df2ed47c59169ff439ddb60d56a[/URL])
Here's my code, I forgot to include it:
[CODE]
local smoothCircle = 0 -- This is outside of the ENT:Draw function
smoothCircle = Lerp(0.5 * FrameTime(), smoothCircle, self:GetMoney())
surface.SetDrawColor(0, 120, 215, 75)
draw_circle(Width / 2, 137, 73, 20, smoothCircle) -- I renamed your function because I was too lazy to go back and change everything :P
[/CODE]
[editline]1st December 2016[/editline]
Nevermind, I figured it out. Thanks!
[editline]1st December 2016[/editline]
Actually, I should've asked before I marked as solved but, is there a way I can make your circle function be as smooth as the one I had before? (I'm talking about the "edges" of the circle)
[editline]1st December 2016[/editline]
Figured that out too xD! Thanks!
Sorry, you need to Log In to post a reply to this thread.