
                      /* Listato 3 */

                       /* Circle */


#include <grafica.h>
#include <math.h> /* Funzioni matematiche sin-cos-PI */

#define PORT finestra->UserPort

 main()
 {
struct Screen *schermo;/* Prepara struttura per lo screen */
struct Window *finestra;/* Prepara struttura per la finestra */
struct IntuiMessage *messaggio;/* Prepara struttura per il messaggio */

ULONG class;


  AttivaG(); /* Apre le librerie */

schermo=(struct Screen *)Schermo(0,640,256,2,0,1,HIRES,
                                 NULL,"Schermo di prova");
if (schermo==NULL) {
                    EndG();
                    exit(); /* Problemi !*/
                   };

Palette(schermo,0,0,0,0); /* Schermo nero */
Palette(schermo,1,0,0,15); /* Blu */
Palette(schermo,2,0,15,0); /* Verde */
Palette(schermo,3,15,0,0); /* Rosso */

finestra=(struct Window *)Finestra(100,50,150,150,-1,-1,CLOSEWINDOW,
                                   WINDOWCLOSE+WINDOWDRAG+ACTIVATE,
                                   NULL,NULL,
                                   "Finestra",schermo,50,50,600,250);


   Circle(finestra,70,70,60,40,3);


           /* Aspetta che la finestra sia chiusa */

 for(;;)  /* Ciclo infinito */
     {
              /* Attende un messaggio valido */
       while ((messaggio=(struct IntuiMessage *)GetMsg(PORT))!=NULL)
               {
                    /* Salvo i campi che mi interessano */
                 class=messaggio->Class;
                 ReplyMsg(messaggio); /* Messaggio ricevuto ! */

                 if (class==CLOSEWINDOW) { /* Chiude la finestra */
                                           CloseWindow(finestra);
                                           CloseScreen(schermo);
                                           EndG();
                                           exit();
                                          };

                }; /* Fine while */

 
     };  /* Ciclo infinto */


} /* FINE */


Circle(w,xo,yo,rx,ry,c)
struct Window *w;
unsigned xo,yo,rx,ry,c;
{
 unsigned x,y,xv,yv;
 int i;
 xv=rx+xo;
 yv=yo;
 for(i=0;i<361;i++)
      {
       x=cos(i*PI/180)*rx+xo;
       y=sin(i*PI/180)*ry+yo;
       Line(w,xv,yv,x,y,c);
       xv=x;
       yv=y;
      };
}
