2D polygon generation

Blitz3D Forums/Blitz3D Beginners Area/2D polygon generation

I first created this function to give myself some extra polys to play with. So far Iv'e just used it in a screen saver.
THE PROBLEM IS, the octogon, decagon,dodecagon have gaps between some of the corners. And the 11 gon(whatever thats called) has an uneven side. I originally thought that it was due to coordinates not being floating point numbers, but it's mostly the even numbers giving me problem. Any help would be greatly appreciated.
Graphics 320,240,16,2
AutoMidHandle(True)
size = 3

Print "Press mouse button to change polygons......"
WaitMouse
While Not KeyDown(1)
Cls
polygon = PolyImage(size,100,0,255,255,255)

DrawImage polygon,320/2,240/2
FreeImage polygon
Text 320/2,240/2,size + " sides",1,1
WaitMouse


size = size + 1
If size > 12 Then size = 3

Wend

End



;Creates an image of a polygon and returns it to specified handle
;****************************************************************

Function PolyImage(numSides,size,rotation,r,g,b)

Color r,g,b

polygon = CreateImage(size*2,size*2)
SetBuffer ImageBuffer(polygon)
Origin size,size

rotationSolver = rotation + 90

sides= 360/numSides

degrees = 0-rotationSolver

a = 0


;Generate coordinates of the polygon corners with polar coordinate system based on sin/cos
;*****************************************************************************************
Repeat
 

	y = Sin(degrees)*size 
	
	x = Cos(degrees)*size 
	;Plot x,y
	
	a = a + 1
	
	Select a
		Case 1
			px1 = x
			py1 = y
		Case 2
			px2 = x
			py2 = y
		Case 3
			px3 = x
			py3 = y
		Case 4
			px4 = x
			py4 = y
		Case 5
			px5 = x
			py5 = y
		Case 6
			px6 = x
			py6 = y
		Case 7
			px7 = x
			py7 = y	
		Case 8	
			px8 = x
			py8 = y
		Case 9	
			px9 = x
			py9 = y
		Case 10	
			px10 = x
			py10 = y
		Case 11	
			px11 = x
			py11 = y
		Case 12	
			px12 = x
			py12 = y


	End Select
	
degrees = degrees + sides	

Until degrees > 360



;draw sides of polygons based on corners coordinates
Select numSides
	Case 3
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px1,py1
		
	Case 4
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px1,py1


	Case 5
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px5,py5
		Line px5,py5,px1,py1

	Case 6
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px5,py5
		Line px5,py5,px6,py6
		Line px6,py6,px1,py1 
		
	Case 7
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px5,py5
		Line px5,py5,px6,py6
		Line px6,py6,px7,py7
		Line px7,py7,px1,py1
		
	Case 8
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px5,py5
		Line px5,py5,px6,py6
		Line px6,py6,px7,py7
		Line px7,py7,px8,py8
		Line px8,py8,px1,py1

	Case 9
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px5,py5
		Line px5,py5,px6,py6
		Line px6,py6,px7,py7
		Line px7,py7,px8,py8
		Line px8,py8,px9,py9
		Line px9,py9,px1,py1

	Case 10
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px5,py5
		Line px5,py5,px6,py6
		Line px6,py6,px7,py7
		Line px7,py7,px8,py8
		Line px8,py8,px9,py9
		Line px9,py9,px10,py10
		Line px10,py10,px1,py1

	Case 11
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px5,py5
		Line px5,py5,px6,py6
		Line px6,py6,px7,py7
		Line px7,py7,px8,py8
		Line px8,py8,px9,py9
		Line px9,py9,px10,py10
		Line px10,py10,px11,py11
		Line px11,py11,px1,py1

	Case 12
		Line px1,py1,px2,py2
		Line px2,py2,px3,py3
		Line px3,py3,px4,py4
		Line px4,py4,px5,py5
		Line px5,py5,px6,py6
		Line px6,py6,px7,py7
		Line px7,py7,px8,py8
		Line px8,py8,px9,py9
		Line px9,py9,px10,py10
		Line px10,py10,px11,py11
		Line px11,py11,px12,py12
		Line px12,py12,px1,py1
End Select

SetBuffer FrontBuffer()

Return polygon

End Function  ;PolyImage()