Trying to draw a part of a circle using surface.DrawLine(), Trying to draw it in a specific pattern that my vocabulary cant explain ;_;
[lua]
function PartialCircle()
local w = ScrW()
local h = ScrH()
surface.SetDrawColor(Color(0,150,0))
for deg = 1,360 do
surface.DrawLine(w/2,h/2,w/2+math.sin(deg)*40,h/2+math.cos(deg)*40)
end
end
hook.Add("HUDPaint","PartialCircle",PartialCircle)
[/lua]
this draws a full circle, but if i draw up to 180 degrees it still draws a full circle, with 50% lines, am i failing my maths? Please help
math.sin and math.cos assume the angle is in radians. If you loop from 1 to pi it should draw correctly.
[editline]14th August 2013[/editline]
You might want to loop from 1 to 180 and use math.rad to convert to radians instead.
Thanks, Works perfectly now, Is there a better way to do this tho? I can see small spaces between the lines
and its not that fast
I guess you want to fill a circle, right?
Then you should take a close look at this function:
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index4287.html[/url]
(especially combined with the second example)
It should be like this then (only copied from maurits.tv):
[CODE]
local sin,cos,rad = math.sin,math.cos,math.rad; --Only needed when you constantly calculate a new polygon, it slightly increases the speed.
function GeneratePoly(x,y,radius,quality)
local circle = {};
local tmp = 0;
for i=1,quality do
tmp = rad(i*360)/quality
circle[i] = {x = x + cos(tmp)*radius,y = y + sin(tmp)*radius};
end
return circle;
end
local function HUDPaint()
surface.SetDrawColor( 255, 255, 255, 255 ) --set the additive color
surface.DrawPoly( GeneratePoly(ScrW()/2, ScrH()/2, 40, 100)) --draw the circle
end
hook.Add("HUDPaint","Draw Circle", HUDPaint)
[/CODE]
Sorry, you need to Log In to post a reply to this thread.