rem n gons
rem by coding fodder
 
sync on
size=20
do
   cls
   angle#=wrapvalue(angle#+4.0)
   n_gon(128,240,3,size,angle#,1,rgb(0,250,255),rgb(255,255,0),0)
   n_gon(256,240,4,size,angle#,4,rgb(255,155,155),rgb(100,100,100),0)
   n_gon(384,240,5,size,angle#,1,rgb(255,0,0),rgb(255,255,0),0)
   n_gon(512,240,5,size,angle#,8,rgb(250,155,155),rgb(0,0,200),1)
   text 1,1,str$(screen fps())
sync
loop
 
function n_gon(x,y,sides,size,angle#,thickness#,color1,color2,star)
   size2=cos((360.0/(sides*2.0)))*(size)
   degrees#=360.0/sides
   if star=1
      num_of_conditions=sides-2
      temp#=(tan(degrees#/2.0))^2
      ending=int(size2*(1.0+2.0*temp#/(1.0-temp#)))
      begining=-ending
   else
      num_of_conditions=sides-1
      begining=-size
      ending=size
   endif
   lock pixels
   start=get pixels pointer()
   repeat_number=get pixels pitch()
   bits_per_pixel=bitmap depth(num)/8
 
   color1r=rgbr(color1)
   color2r=rgbr(color2)
   color1g=rgbg(color1)
   color2g=rgbg(color2)
   color1b=rgbb(color1)
   color2b=rgbb(color2)
   a#=0.0
   b#=1.0
   increment#=1.0/abs((ending-beginning)*2)
 
   for i=begining to ending
      for j=begining to ending
         if i+x>=0 and j+y>=0 and i+x<bitmap width() and j+y<bitmap height()
            conditions=0
            conditions2=0
            for side=1 to sides
               test#=(j*sin(angle#+side*degrees#))+(i*cos(angle#+side*degrees#))-size2+0.5
               if test#<=0.0
                  inc conditions
                  if test#>-thickness# then inc conditions2
               endif
            next side
            if conditions>num_of_conditions
               if conditions2>0
                  pointer=start+(y+j)*repeat_number+(x+i)*bits_per_pixel
 
                  colormixr=(color1r*a#+color2r*b#)
                  colormixg=(color1g*a#+color2g*b#)
                  colormixb=(color1b*a#+color2b*b#)
                  color=rgb(colormixr,colormixg,colormixb)
 
                  *pointer=color
               endif
            endif
         endif
      next j
inc a#,increment#
dec b#,increment#
   next i
   unlock pixels
endfunction