home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 304.lha / Pyth / Pyth.c < prev    next >
C/C++ Source or Header  |  1980-12-05  |  7KB  |  347 lines

  1. /**************************| Pyth.c |*********** 20 July 1989 *****/
  2. /*                                                                */
  3. /*  Pyth v1.1: (c) 7/89 by Andreas Krebs                          */
  4. /*                         Mittelweg 9                            */
  5. /*                         7110 Oehringen 2                       */
  6. /*                                                                */
  7. /*                                                                */
  8. /*            This programm ist Public-Domain.                    */
  9. /*                                                                */
  10. /* Compile commands: (for Aztec-C v3.6a)                          */
  11. /*                   cc Pyth                                      */
  12. /*                   ln Pyth -lc -lm                              */
  13. /*                                                                */
  14. /******************************************************************/
  15.  
  16. #include <exec/types.h>
  17. #include <intuition/intuition.h>
  18. #include <graphics/gfx.h>
  19. #include <graphics/gfxbase.h>
  20. #include <graphics/gfxmacros.h>
  21. #include <libraries/mathffp.h>
  22.  
  23. struct IntuitionBase *IntuitionBase;
  24. struct GfxBase *GfxBase;
  25. struct MathBase *MathBase;
  26. struct MathTransBase *MathTransBase;
  27.  
  28. struct Screen *PythScreen;
  29. struct Window *PythWindow;
  30. static struct RastPort *rp;
  31.  
  32. USHORT Kords[21][3][2];
  33. USHORT Box[4][2];
  34.  
  35. struct NewScreen NewPythScreen =
  36. {
  37.   0,0,
  38.   640,400,
  39.   3,
  40.   1,0,
  41.   HIRES|LACE,
  42.   CUSTOMSCREEN,
  43.   NULL,
  44.   NULL,
  45.   NULL,
  46.   NULL
  47. };
  48.  
  49. struct NewWindow NewPythWindow =
  50. {
  51.   0,10,
  52.   640,390,
  53.   1,0,
  54.   CLOSEWINDOW,
  55.   WINDOWCLOSE|ACTIVATE|BORDERLESS,
  56.   NULL,
  57.   NULL,
  58.   (UBYTE *)"Pyth v1.1 (c) 7/89 by Andreas Krebs",
  59.   NULL,
  60.   NULL,
  61.   0,0,
  62.   0,0,
  63.   CUSTOMSCREEN
  64. };
  65.  
  66. main()
  67. {
  68.   OpenALL();
  69.  
  70.   SetRGB4(&PythScreen->ViewPort,3L,15L,0L,0L);
  71.   SetRGB4(&PythScreen->ViewPort,4L,0L,15L,15L);
  72.   SetRGB4(&PythScreen->ViewPort,5L,0L,15L,0L);
  73.  
  74.   DrawPyth();
  75.  
  76.   Wait(1L << PythWindow->UserPort->mp_SigBit);
  77.  
  78.   CloseALL();
  79. }
  80.  
  81. OpenALL()
  82. {
  83.   void *OpenLibrary();
  84.   struct Screen *OpenScreen();
  85.   struct Window *OpenWindow();
  86.  
  87.   if(!(IntuitionBase=(struct IntuitionBase *)
  88.        OpenLibrary("intuition.library",0L)))
  89.   {
  90.     puts("Can't open intuition library !");
  91.     exit(FALSE);
  92.   }
  93.  
  94.   if(!(GfxBase=(struct GfxBase *)
  95.        OpenLibrary("graphics.library",0L)))
  96.   {
  97.     puts("Can't open graphics library !");
  98.     CloseALL();
  99.     exit(FALSE);
  100.   }
  101.  
  102.   if(!(MathBase=(struct MathBase *)
  103.        OpenLibrary("mathffp.library",0L)))
  104.   {
  105.     puts("Can't open mathffp library !");
  106.     CloseALL();
  107.     exit(FALSE);
  108.   }
  109.  
  110.   if(!(MathTransBase=(struct MathTransBase *)
  111.        OpenLibrary("mathtrans.library",0L)))
  112.   {
  113.     puts("Can't open mathtrans library !");
  114.     CloseALL();
  115.     exit(FALSE);
  116.   }
  117.  
  118.   if(GfxBase->DisplayFlags & (UWORD)PAL)
  119.   {
  120.     NewPythScreen.Height=512;
  121.     NewPythWindow.Height=502;
  122.   }
  123.  
  124.   if(!(PythScreen=(struct Screen *)
  125.        OpenScreen(&NewPythScreen)))
  126.   {
  127.     puts("Can't open Screen !");
  128.     CloseALL();
  129.     exit(FALSE);
  130.   }
  131.  
  132.   NewPythWindow.Screen=PythScreen;
  133.  
  134.   if(!(PythWindow=(struct Window *)
  135.        OpenWindow(&NewPythWindow)))
  136.   {
  137.     puts("Can't open Window !");
  138.     CloseALL();
  139.     exit(FALSE);
  140.   }
  141.  
  142.   rp=PythWindow->RPort;
  143. }
  144.  
  145. CloseALL()
  146. {
  147.   if(PythWindow) CloseWindow(PythWindow);
  148.   if(PythScreen) CloseScreen(PythScreen);
  149.   if(MathBase) CloseLibrary(MathBase);
  150.   if(MathTransBase) CloseLibrary(MathTransBase);
  151.   if(GfxBase) CloseLibrary(GfxBase);
  152.   if(IntuitionBase) CloseLibrary(IntuitionBase);
  153. }
  154.  
  155. DrawPyth()
  156. {
  157.   USHORT Seite[21],t;
  158.   SHORT x=0,y=0,Nr=0,ax,ay;
  159.   int sqr,sx,sy;
  160.   FLOAT a,b,c,h,h2,e,f,wia1,wia2,wib,abx,aby,abx2,aby2;
  161.  
  162.   for(t=0;t<21;t++)
  163.   {
  164.     Seite[t]=0;
  165.   }
  166.  
  167.   SetAPen(rp,5L);
  168.  
  169.   if(GfxBase->DisplayFlags & (UWORD)PAL)
  170.   {
  171.     Move(rp,320L,500L);
  172.     Draw(rp,320L,400L);
  173.     Draw(rp,220L,400L);
  174.     Draw(rp,220L,500L);
  175.     Draw(rp,320L,500L);
  176.  
  177.     Kords[0][0][0]=320;
  178.     Kords[0][0][1]=400;
  179.     Kords[0][1][0]=256;
  180.     Kords[0][1][1]=352;
  181.     Kords[0][2][0]=220;
  182.     Kords[0][2][1]=400;
  183.   }
  184.   else
  185.   {
  186.     Move(rp,310L,388L);
  187.     Draw(rp,310L,308L);
  188.     Draw(rp,230L,308L);
  189.     Draw(rp,230L,388L);
  190.     Draw(rp,310L,388L);
  191.  
  192.     Kords[0][0][0]=310;
  193.     Kords[0][0][1]=308;
  194.     Kords[0][1][0]=259;
  195.     Kords[0][1][1]=270;
  196.     Kords[0][2][0]=230;
  197.     Kords[0][2][1]=308;
  198.   }
  199.  
  200.   DrawDreieck(0);
  201.  
  202.   do
  203.   {
  204.     Nr++;
  205.  
  206.     x=Kords[Nr-1][0][0]-Kords[Nr-1][1][0];
  207.     y=Kords[Nr-1][0][1]-Kords[Nr-1][1][1];
  208.     sqr=x*x+y*y;
  209.     a=SPSqrt((FLOAT)(sqr));
  210.  
  211.     if(x==0.0 || x==-0.0)
  212.       wia1=PI/2;
  213.     else
  214.       wia1=SPAtan((FLOAT)y/(FLOAT)x);
  215.  
  216.     if(x<=0.0 || x<=-0.0)
  217.       wia1+=PI;
  218.  
  219.     x=Kords[Nr-1][1][0]-Kords[Nr-1][2][0];
  220.     y=Kords[Nr-1][1][1]-Kords[Nr-1][2][1];
  221.     sqr=x*x+y*y;
  222.     b=SPSqrt((FLOAT)(sqr));
  223.  
  224.     if(x==0.0 || x==-0.0)
  225.       wia2=PI/2.0;
  226.     else
  227.       wia2=-SPAtan((FLOAT)y/(FLOAT)x);
  228.  
  229.     if(x<=0.0 || x<=-0.0)
  230.       wia2+=PI;
  231.  
  232.     x=Kords[Nr-1][2][0]-Kords[Nr-1][0][0];
  233.     y=Kords[Nr-1][2][1]-Kords[Nr-1][0][1];
  234.     sqr=x*x+y*y;
  235.     c=SPSqrt((FLOAT)(sqr));
  236.  
  237.     h=a*0.6;   /*   a*sin(36.9°)   */
  238.     e=a*0.8;   /*   a*sin(53.1°)   */
  239.     f=c-e;
  240.  
  241.     if(Seite[Nr]==1)
  242.     {
  243.       abx=-b*SPSin(wia2);
  244.       aby=b*SPCos(wia2);
  245.     }
  246.     else
  247.     {
  248.       abx=a*SPSin(wia1);
  249.       aby=a*SPCos(wia1);
  250.     }
  251.  
  252.     Box[0][0]=Kords[Nr-1][Seite[Nr]][0];
  253.     Box[0][1]=Kords[Nr-1][Seite[Nr]][1];
  254.     Box[1][0]=Kords[Nr-1][Seite[Nr]][0]+(SHORT)abx;
  255.     Box[1][1]=Kords[Nr-1][Seite[Nr]][1]-(SHORT)aby;
  256.     Box[2][0]=Kords[Nr-1][Seite[Nr]+1][0]+(SHORT)abx;
  257.     Box[2][1]=Kords[Nr-1][Seite[Nr]+1][1]-(SHORT)aby;
  258.     Box[3][0]=Kords[Nr-1][Seite[Nr]+1][0];
  259.     Box[3][1]=Kords[Nr-1][Seite[Nr]+1][1];
  260.  
  261.     if(Seite[Nr]==1)
  262.       SetAPen(rp,3L);
  263.     else
  264.       SetAPen(rp,5L);
  265.  
  266.     DrawBox();
  267.  
  268.     Kords[Nr][0][0]=Box[1][0];
  269.     Kords[Nr][0][1]=Box[1][1];
  270.     Kords[Nr][2][0]=Box[2][0];
  271.     Kords[Nr][2][1]=Box[2][1];
  272.  
  273.     sx=(int)Box[Seite[Nr]+1][0];
  274.     sy=(int)Box[Seite[Nr]+1][1];
  275.  
  276.     if(Seite[Nr]==1)
  277.     {
  278.       wib=wia2+0.927295;
  279.       wib=PI-wib;
  280.  
  281.       aby2=f*SPSin(wib);
  282.       abx2=f*SPCos(wib);
  283.     }
  284.     else
  285.     {
  286.       wib=wia1+0.6435011;
  287.  
  288.       aby2=e*SPSin(wib);
  289.       abx2=e*SPCos(wib);
  290.     }
  291.  
  292.     ax=(SHORT)abx2;
  293.     ay=(SHORT)aby2;
  294.  
  295.     sx-=ax;
  296.     sy-=ay;
  297.  
  298.     Kords[Nr][1][0]=(USHORT)sx;
  299.     Kords[Nr][1][1]=(USHORT)sy;
  300.  
  301.     DrawDreieck(Nr);
  302.  
  303.     if((b<=3.0 && a<=4.0 && c<=5.0) || Nr>=20)
  304.     {
  305.       for(t=(Nr+1);t<21;t++)
  306.       {
  307.         Seite[t]=0;
  308.       }
  309.  
  310.       while(Seite[Nr]==1)
  311.       {
  312.         Seite[Nr]=0;
  313.         Nr--;
  314.         if(Nr<1)
  315.           break;
  316.       }
  317.       Seite[Nr]=1;
  318.       Nr--;
  319.     }
  320.  
  321.     if(GetMsg(PythWindow->UserPort))
  322.     {
  323.       CloseALL();
  324.       exit(TRUE);
  325.     }
  326.   }while(Nr>-1);
  327. }
  328.  
  329.  
  330. DrawDreieck(Nr)
  331. USHORT Nr;
  332. {
  333.   SetAPen(rp,4L);
  334.  
  335.   Move(rp,(LONG)Kords[Nr][2][0],(LONG)Kords[Nr][2][1]);
  336.  
  337.   PolyDraw(rp,3L,&Kords[Nr][0][0]);
  338. }
  339.  
  340. DrawBox()
  341. {
  342.   Move(rp,(LONG)Box[3][0],(LONG)Box[3][1]);
  343.   
  344.   PolyDraw(rp,4L,&Box[0][0]);
  345. }
  346.  
  347.