# BASIC8 Chastity Polygon

I translated my spinning polygon routine by looking at the C version and copying everything over to BASIC syntax. It also draws a checkerboard behind the polygon because I left the code from my previous project there.

``````REM BASIC8 port of Chastity's Regular Polygon

'the width and height of the program
'this is set in stone by the BASIC8 creator so these never change
width=160,height=128

'declare my 2 color palette for the checkerboard
palette=list()
push(palette,rgba(0,0,0))
push(palette,rgba(255,255,255))

rem new section for declaring the polygon variables
cx=width/2 'center x of the polygon
cy=height/2 'center y of the polygon
radians=0 'the current rotation angle of the polygon
polygon_points = 8
polygon_step = 3 'for how the points are stepped through,applies to star polygons
polygon_color=rgba(255,0,0)
'arrays of x and y points
dim xpoints(polygon_points)
dim ypoints(polygon_points)

'old section that does the checkerboard from my other project
rectsize=8
def update()
index=0
y=0
while y<height
index1=index
x=0
while x<width
rectfill x,y,x+rectsize,y+rectsize,palette(index))
index=BXOR(index,1)
x=x+rectsize
wend
index=BXOR(index1,1)
y=y+rectsize
wend
rem end of checkerboard section

'fill the point arrays with correct values using trigonometry
i=0
while i<polygon_points
f=i/polygon_points
angle=2*pi*f
x=sin(angle);
y=cos(angle);
'print i;
'print "angle=",angle;
'print "x=",x," y=",y;
xpoints(i)=x;
ypoints(i)=y;
i=i+1;
wend
rem now all points are set up.

rem next draw triangles
i=0
while i<polygon_points
i1=(i+polygon_step) mod polygon_points;
trifill cx,cy,xpoints(i),ypoints(i),xpoints(i1),ypoints(i1),polygon_color
i=i+1;
wend

'change the rotation