// draw_poligon x y num len // draw_poligon_ugly x y next_x next_y num len angle num_acc import simple_graphics; import floats; define colore = (100 , 100 , 100); define max_x = 800 ; define max_y = 600 ; define itof = \ x . integer_to_float x; define find_alfa = \ num . (pi -f ((pi *f 2.) /f (itof num))); // server soltanto per farlo visualizzare usando una visualizzazione del primo quadrante define c_y = \ y . max_y - y; // sono pigro a passare gli argomenti define show_line2 = \ x1 . \ y1 . \ x2 . \ y2 . show_line x1 (c_y y1) x2 (c_y y2) colore ; define loop = fix \ f . \ x . f x ; // e a scrvere il nome delle funzioni ....... define ftoi = \ x . float_to_integer x; // non le uso piu ma non fanno male define deg_to_rad = \ x . (x *f pi) /f 180. ; define rad_to_deg = \ x . (x *f 180.) /f pi ; define get_next_angle = \ x . \ base . (x +f pi +f base); define next_xy_rad = \ x . \ y . \ len . \ angle . if ( angle <=f (pi /f 2.)) then ( ((ftoi((cos angle) *f len)) + x) , ((ftoi((sin angle) *f len)) + y) ) else if ( angle <=f pi) then ( ((ftoi((cos angle) *f len)) + x) , ((-(ftoi((sin angle) *f len))) + y) ) else if (angle <=f ((pi *f 3.)/f 2.)) then ( ((-(ftoi((cos angle) *f len))) + x) , ((-(ftoi((sin angle) *f len))) + y) ) else ( ((-(ftoi((cos angle) *f len))) + x) , ((ftoi((sin angle) *f len)) + y) ) ; define next_xy = \ x . \ y . \ len . \ angle . next_xy_rad x y len angle; define draw_poligon_ugly = fix \ f . \ x . \ y . \ new_xy . \ num . \ len . \ angle . \ base_ang . \ num_acc . \ origin . if (num_acc < num) then begin show_line2 x y (new_xy ^ 1) (new_xy ^ 2); f (new_xy ^ 1) (new_xy ^ 2) (next_xy (new_xy ^ 1) (new_xy ^ 2) len (angle +f pi +f base_ang)) num len (angle +f pi +f base_ang) base_ang (num_acc + 1) origin; end else show_line2 x y (origin ^ 1) (origin ^ 2); // mi sono dimenticato se il compilatore e' furbo e si calcola una sola volta angle +f etc. define draw_poligon_with_angle = \ x . \ y . \ num . \ len . \ angle . draw_poligon_ugly x y (next_xy x y len (angle +f pi +f angle)) num len (angle +f pi +f angle) angle 1 (x , y) ; define draw_poligon = \ x . \ y . \ num . \ len . draw_poligon_with_angle x y num len (find_alfa num) ; define main = begin initialize_graphics max_x max_y; draw_poligon 400 400 13 40.; loop 1; end;