rem n gons
rem and gradient
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,0,255),0)
   n_gon(256,240,4,size,angle#,4,rgb(0,255,0),0)
   n_gon(384,240,5,size,angle#,1,rgb(255,0,0),1)
   n_gon(512,240,9,size,angle#,30,rgb(200,200,0),1)
   gradient(480,217,543,265,2,45.0,0,255,0)
   text 1,1,str$(screen fps())
sync
loop
 
function n_gon(x,y,sides,size,angle#,thickness#,color,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()/8
 
 
   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
                  *pointer=color
               endif
            endif
         endif
      next j
   next i
   unlock pixels
endfunction
 
function gradient(startx,starty,stopx,stopy,grad_type,angle#,color1,color2,transparent)
   lock pixels
   start=get pixels pointer()
   repeat_number=get pixels pitch()
   bits_per_pixel=bitmap depth()/8
 
   red1=rgbr(color1)
   green1=rgbg(color1)
   blue1=rgbb(color1)
   red2=rgbr(color2)
   green2=rgbg(color2)
   blue2=rgbb(color2)
   x0=startx+(stopx-startx)/2.0
   y0=starty+(stopy-starty)/2.0
 
   if (stopx-startx) > (stopy-starty)
      rad#=(stopx-startx)/2.0
   else
      rad#=(stopy-starty)/2.0
   endif
 
   for i=startx to stopx
      for j=starty to stopy
         pointer=start+j*repeat_number+i*bits_per_pixel
         color=*pointer
         if color=transparent
         else
            select grad_type
               case 1:a#=0.5+(((j-y0)*sin(angle#))+((i-x0)*cos(angle#))+0.5)/(2.0*rad#):endcase
               case 2:a#=sqrt((i-x0)^2+(j-y0)^2)/rad#:endcase
            endselect
               if a#>1.0 then a#=1.0
               if a#<0.0 then a#=0.0
               b#=1.0-a#
               color=rgb(a#*red1+b#*red2,a#*green1+b#*green2,a#*blue1+b#*blue2)
               *pointer=color
         endif
      next j
   next i
   unlock pixels
endfunction