Code archives/Graphics/Polygon and Star functions
This code has been declared by its author to be Public Domain code.
Download source code
| This code draws perfect stars and polygons and is commented for comprehendability. Be sure to include the line of code 'Dim B3DM_xp(359),B3DM_yp(359)' at the beginning of your source if you use it. The functions have trouble only with the most insane numbers that (hopefully) nobody in their right mind would try. No credit is required for use of these functions, it is public code. Also, you may use LockBuffer when calling these functions if you wish. An example is included within the code. |
;*-------------------------------------------------------------*; ;*--Polygon and Star functions coded by Blitz3DMan on 11-2-07--*; ;*-------------------------------------------------------------*; ; No credit is needed for use of these functions. Dim B3DM_xp(359),B3DM_yp(359) ;These arrays must be declared at start of code for the functions to work. ;Example Usage Graphics 640,480,0,2 Color 255,255,255 Repeat Flip LockBuffer() For a=5 To 8 Polygon 70+(a-4)*100, 100, 70, 70, a, -90 Star 70+(a-4)*100, 100, 70, 70, a, -90 Next UnlockBuffer() Flip If KeyDown(1) End Forever ;Polygon draws a shape with the specified number of sides ;Polygon ( x position, y position, width, height, number of sides[, angle at which to draw = 0] ) Function Polygon(x#,y#,w#,h#,s%,ang#=0) If s>360 Then s=360 s=s-1:w=w/2:h=h/2 For dop=0 To s B3DM_xp(dop)=x+w*(Cos((360/(s+1)*dop)+ang)) B3DM_yp(dop)=y+h*(Sin((360/(s+1)*dop)+ang)) Next For lin=0 To s p2=lin+1:If p2>s Then p2=0 Line B3DM_xp(lin),B3DM_yp(lin),B3DM_xp(p2),B3DM_yp(p2) Next End Function ;Star uses a mathematical formula to connect the points of a ploygon to form a star ;Star ( x position, y position, width, height, number of points[, angle at which to draw = 0] ) Function Star(x#,y#,w#,h#,s%,ang#=0) If s>360 Then s=360 s=s-1:w=w/2:h=h/2 For dop=0 To s B3DM_xp(dop)=x+w*(Cos((360/(s+1)*dop)+ang)) B3DM_yp(dop)=y+h*(Sin((360/(s+1)*dop)+ang)) Next For lin=0 To s p2=lin+2:If p2=s+1 Then p2=0 ElseIf p2=s+2 Then p2=1 Line B3DM_xp(lin),B3DM_yp(lin),B3DM_xp(p2),B3DM_yp(p2) Next End Function |