Function poly_radius#(sidelength:Float,num_sides:Float) Local r:Float = sidelength /(2.0*Sin(180.0/num_sides)) Return r End Function Function draw_ngon(x#,y#,numsides%,sidelength#) Local small_angle# =360.0/Float(numsides) Local start_angle#=0 Local radius#=poly_radius(sidelength,numsides) For Local i=0 To numsides-1 DrawLine x+Sin(start_angle)*radius,y-Cos(start_angle)*radius,x+Sin(start_angle+small_angle)*radius,y-Cos(start_angle+small_angle)*radius start_angle:+small_angle Next Flip End Function Graphics 640,480 draw_ngon 100,100,16,32 While Not KeyHit(KEY_ESCAPE) Wend
Two things:
You're drawing one too many sides.
You're also depending upon multiplications to work out points, which generally is a bad idea. Depending upon the floating point errors, you'll overshoot or undershoot the final value. Accumulate the starting angle, rather than calculating it.