home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d584 / spli.lha / SpLi / SpLi.c < prev    next >
C/C++ Source or Header  |  1992-01-04  |  3KB  |  145 lines

  1.                /******************************************
  2.                *                                         *
  3.                *  Sphere-Lissajous.c - Lissajous Curves  *
  4.                *                                         *
  5.                * written by C.Raufuß of ! WIZARD WORKS ! *
  6.                *                                         *
  7.                *      with SAS/C 5.10, on 06/04/91       *
  8.                *                                         *
  9.                *              Version 1.00               *
  10.                *                                         *
  11.                ******************************************/
  12.  
  13. #include <exec/types.h>
  14. #include <intuition/intuition.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <math.h>
  18. #include <proto/exec.h>
  19. #include <proto/graphics.h>
  20. #include <proto/intuition.h>
  21.  
  22. int CXBRK(void) { return(0); }
  23. int chkabort(void) { return(0); }
  24.  
  25. void main(int argc,char **argv)
  26. {
  27.    struct IntuitionBase *IntuitionBase=NULL;
  28.    struct GfxBase *GfxBase=NULL;
  29.    struct IntuiMessage *IMsg;
  30.    struct Screen *s=NULL;
  31.    struct NewScreen ns =
  32.    {
  33.       0,0,
  34.       640,256,
  35.       2,
  36.       1,0,
  37.       HIRES,
  38.       CUSTOMSCREEN,
  39.       NULL,
  40.       NULL,
  41.       NULL,
  42.       NULL   
  43.    };
  44.    struct Window *w=NULL;
  45.    struct NewWindow nw =
  46.    {
  47.       0,0,
  48.       640,256,
  49.       -1,-1,
  50.       MOUSEBUTTONS,
  51.       BORDERLESS|SMART_REFRESH|ACTIVATE|RMBTRAP,   
  52.       NULL,NULL,
  53.       NULL,
  54.       NULL,
  55.       NULL,
  56.       NULL,NULL,
  57.       NULL,NULL,
  58.       CUSTOMSCREEN
  59.    };
  60.    
  61.    ULONG class;
  62.    double a,b,m,n,o,x,y,z;
  63.    register int t;
  64.    
  65.    if(argc!=3)
  66.    {
  67.       printf("Sphere Lissajous v1.00 by C.Raufuß ©1991\nUsage: SpLi a b\n");
  68.       goto cleanexit;  
  69.    }
  70.    
  71.    printf("Sphere Lissajous v1.00 by C.Raufuß of ! WIZARD WORKS ! ©1991\n");
  72.    
  73.    a=atof(argv[1]);
  74.    b=atof(argv[2]);
  75.    
  76.    if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  77.    {
  78.       goto cleanexit;
  79.    }
  80.    if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)))
  81.    {
  82.       goto cleanexit;
  83.    }
  84.    if(!(s=(struct Screen *)OpenScreen(&ns)))
  85.    {
  86.       goto cleanexit;
  87.    }
  88.    nw.Screen=s;
  89.    if(!(w=(struct Window *)OpenWindow(&nw)))
  90.    {
  91.       goto cleanexit;
  92.    }
  93.    
  94.    /******** Lissajous Algorithm ***********/
  95.  
  96.    SetAPen(w->RPort,(ULONG)3);
  97.    DrawEllipse(w->RPort,(ULONG)320,(ULONG)128,(ULONG)240,(ULONG)120);
  98.    
  99.    for(t=0;t<=100000;t++)
  100.    {
  101.       m=a*t;
  102.       n=b*t;
  103.       o=sin(m);
  104.       x=o*cos(n);
  105.       y=o*sin(n);
  106.       z=cos(m);
  107.       
  108.       SetAPen(w->RPort,(ULONG)1);
  109.       WritePixel(w->RPort,(ULONG)((x*240)+320),(ULONG)((z*120)+128));
  110.       SetAPen(w->RPort,(ULONG)2);
  111.       WritePixel(w->RPort,(ULONG)((x*240)+320),(ULONG)((y*120)+128));
  112.            
  113.       if((IMsg=(struct IntuiMessage *)GetMsg(w->UserPort)))
  114.       {
  115.          class=IMsg->Class;
  116.          ReplyMsg((struct Message *)IMsg);
  117.          if(class==MOUSEBUTTONS) goto cleanexit;
  118.       }
  119.       
  120.    }
  121.    
  122.    /****************************************/
  123.       
  124.    Wait(1<<w->UserPort->mp_SigBit);
  125.    
  126.    cleanexit:
  127.    if(w)
  128.    {
  129.       CloseWindow((struct Window *)w);
  130.    }
  131.    if(s)
  132.    {
  133.       CloseScreen((struct Screen *)s);
  134.    }
  135.    
  136.    if(GfxBase)
  137.    {
  138.       CloseLibrary((struct GfxBase *)GfxBase);
  139.    }
  140.    if(IntuitionBase)
  141.    {
  142.       CloseLibrary((struct IntuitionBase *)IntuitionBase);
  143.    }
  144. }
  145.