Code archives/Graphics/Polygon Inscribed Inside Circle
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Parameters: Sides - The number of sides the inscribed angle contains Radius - The distance from the center of the circle to the edge CenterX and CenterY - The corridnates of the center of the circle Rotate# - Rotates the polygon in degrees example code Graphics 800,600,32,2 DrawInscribedPolygon(3,100,170,150,30) Text 170,150,"Triangle",True,True DrawInscribedPolygon(6,100,370,400,0) Text 370,400,"Hexagon",True,True DrawInscribedPolygon(8,100,580,150,0) Text 580,150,"Octagon",True,True WaitKey Function DrawInscribedPolygon(Sides,Radius,CenterX,CenterY,Rotate#) PerAngle# = 360/Float(Sides) Angle# = Rotate# OriginPoint = True .BeginLoop ; I use a goto loop because the step value was not constant PrevX = cVertexX PrevY = cVertexY cVertexX = (CenterX+Radius*Cos(Angle#)) cVertexY = (CenterY+Radius*Sin(Angle#)) If OriginPoint = False Then Line PrevX,PrevY,cVertexX,cVertexY Else OriginPoint = False Angle# = Angle# + PerAngle# If Angle# < 360.1+Rotate# Then Goto BeginLoop End Function | |||||
Function DrawInscribedPolygon(Sides,Radius,CenterX,CenterY,Rotate#) PerAngle# = 360/Float(Sides) Angle# = Rotate# OriginPoint = True .BeginLoop ; I use a goto loop because the step value was not constant PrevX = cVertexX PrevY = cVertexY cVertexX = (CenterX+Radius*Cos(Angle#)) cVertexY = (CenterY+Radius*Sin(Angle#)) If OriginPoint = False Then Line PrevX,PrevY,cVertexX,cVertexY Else OriginPoint = False Angle# = Angle# + PerAngle# If Angle# < 360.1+Rotate# Then Goto BeginLoop End Function |
Comments
| ||
You could've used a while loop instead of a goto loop, but I guess that dosn't really matter. |
Code Archives Forum