Code archives/Algorithms/Creating circles with a certain amount of corners

This code has been declared by its author to be Public Domain code.

Download source code

Creating circles with a certain amount of corners by Phoenix2006
This function will create a circle with a variable amount of corners
;Circles with variable corners
;Written 5th January 2006 by Phoenix
;************************************************
Circle(100,100,100,8)
WaitKey()

Function Circle(x,y,radius,corners)
	If corners = 0 Then Return 0 ;Check so that we don't divide by 0

	For i = 0 To corners
		Line radius*Sin(360/corners*i)+x,radius*Cos(360/corners*i)+y,radius*Sin(360/corners*(i+1))+x,radius*Cos(360/corners*(i+1))+y
	Next
End Function

Comments

Damien Sturdy2006
oh, you mean a polygon with (x) Sides? Cool :)


CS_TBL2006
For completeness, since you divide by 'corners' .. better have a check on 'corners' being <>0 :P


Phoenix2006
@Cygnus: Not necessarily a polygon, if you change corners to 32 it becomes a circle.

@CS_TBL: Ok, forgot that.


big10p2006
If it's got any 'corners' at all, it's a polygon. 'polygon' means 'many sided'. A true circle doesn't have sides.


Code Archives Forum