home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1997 #3 / amigamamagazinepolishissue03-1 / ma_1995 / 06 / ami028a.txt < prev    next >
Text File  |  1997-04-07  |  3KB  |  244 lines

  1. /***********************************************/
  2.  
  3. /* Program rysuje krzywâ poôcigu (psia krzywa) */
  4.  
  5. /*         Napisane dla Magazynu Amiga         */
  6.  
  7. /*                1995 by BsZ                  */
  8.  
  9. /***********************************************/
  10.  
  11. #include <intuition/intuition.h>
  12.  
  13. #include <functions.h>
  14.  
  15. #include <stdio.h>
  16.  
  17. #include <stdlib.h>
  18.  
  19. #include <math.h>
  20.  
  21. #define WIDTH 640
  22.  
  23. #define HEIGHT 256
  24.  
  25. #define x0 10
  26.  
  27. #define y0 210
  28.  
  29. int xp,yp,xz,yz; /* wspóîrzëdne psa i zajâca */
  30.  
  31. struct Window *wind;
  32.  
  33. struct IntuitionBase *IntuitionBase;
  34.  
  35. struct GfxBase *GfxBase;
  36.  
  37. struct NewWindow wind_data={
  38.  
  39.     0,0,WIDTH,HEIGHT,1,1,CLOSEWINDOW,
  40.  
  41.     ACTIVATE|GIMMEZEROZERO|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH,
  42.  
  43.     0,0,(UBYTE *)"Psia krzywa. (c) 1994 by BSZ",0,0,
  44.  
  45.     200,256,WIDTH,HEIGHT,WBENCHSCREEN};
  46.  
  47. void dowidzenia(void)
  48.  
  49. {
  50.  
  51.     if (wind) CloseWindow(wind);
  52.  
  53.     if (GfxBase)
  54.  
  55.         CloseLibrary((struct Library *)GfxBase);
  56.  
  57.     if (IntuitionBase)
  58.  
  59.         CloseLibrary((struct Library *)IntuitionBase);
  60.  
  61.     exit(0);
  62.  
  63. }
  64.  
  65. void OpenAllLibraries(void)
  66.  
  67. {
  68.  
  69.     IntuitionBase=(struct IntuitionBase *)
  70.  
  71.         OldOpenLibrary("intuition.library");
  72.  
  73.     if (!IntuitionBase) exit(100);
  74.  
  75.     GfxBase=(struct GfxBase *)
  76.  
  77.         OldOpenLibrary("graphics.library");
  78.  
  79.     if (!GfxBase) exit(100);
  80.  
  81. }
  82.  
  83. int x(int X)
  84.  
  85. {
  86.  
  87.     return(X+x0);
  88.  
  89. }
  90.  
  91. int y(int Y)
  92.  
  93. {
  94.  
  95.     return(y0-Y);
  96.  
  97. }
  98.  
  99. void odcinekP(int x1,int y1,int x3,int y3,int d)
  100.  
  101. {
  102.  
  103.     double D;
  104.  
  105.     int x2,y2;
  106.  
  107.     Move(wind->RPort,x(x1),y(y1));
  108.  
  109.     D=sqrt( (double)( (x3-x1)*(x3-x1)+(y3-y1)*(y3-y1) ) );
  110.  
  111.     x2=(int)( x1+d/D*(x3-x1) );
  112.  
  113.     y2=(int)( y1-d/D*(y1-y3) );
  114.  
  115.     if(d>=D)
  116.  
  117.     {
  118.  
  119.         Draw(wind->RPort,x(xz),y(yz));
  120.  
  121.         xp=xz;
  122.  
  123.         yp=yz;
  124.  
  125.     }
  126.  
  127.     else
  128.  
  129.     {
  130.  
  131.         Draw(wind->RPort,x(x2),y(y2));
  132.  
  133.         xp=x2;
  134.  
  135.         yp=y2;
  136.  
  137.     }
  138.  
  139. }
  140.  
  141. void odcinekZ(int x1, int d)
  142.  
  143. {
  144.  
  145.     Move(wind->RPort,x(x1),y(0));
  146.  
  147.     Draw(wind->RPort,x(x1+d),y(0));
  148.  
  149.     xz=x1+d;
  150.  
  151. }
  152.  
  153. main(int argc,char *argv[])
  154.  
  155. {
  156.  
  157.     long int zmiany=0; /* iloôê zmian kierunku */
  158.  
  159.     int t0;        /* czas, czas reakcji w milisekundach */
  160.  
  161.     int a,b;       /* poîoûenia poczâtkowe zajâca i psa */
  162.  
  163.     int vp,vz;     /* prëdkoôci poczâtkowe */
  164.  
  165.     int sp,sz;     /* drogi */
  166.  
  167.     if(argc!=6)
  168.  
  169.     {
  170.  
  171.         printf("Argumenty:t0 a b vz vp");
  172.  
  173.         exit(0);
  174.  
  175.     }
  176.  
  177.     OpenAllLibraries();
  178.  
  179.     if(!(wind=OpenWindow(&wind_data))) dowidzenia();
  180.  
  181. /* osie */
  182.  
  183.     Move(wind->RPort,x0,y0);
  184.  
  185.     Draw(wind->RPort,x0,10);
  186.  
  187.     Move(wind->RPort,x0,y0);
  188.  
  189.     Draw(wind->RPort,610,y0);
  190.  
  191.     t0 = atoi(argv[1]);
  192.  
  193.     a  = atoi(argv[2]);
  194.  
  195.     b  = atoi(argv[3]);
  196.  
  197.     vz = atoi(argv[4]);
  198.  
  199.     vp = atoi(argv[5]);
  200.  
  201.     xp = 0;
  202.  
  203.     yp = b;
  204.  
  205.     xz = a;
  206.  
  207.     yz = 0;
  208.  
  209.     sp = vp*t0;
  210.  
  211.     sz = vz*t0;
  212.  
  213.     zmiany=0;
  214.  
  215.     SetAPen(wind->RPort,1);
  216.  
  217.     for(;;)
  218.  
  219.     {
  220.  
  221.         odcinekP(xp,yp,xz,yz,sp);
  222.  
  223.         if(xp>=xz || xp>WIDTH)
  224.  
  225.         {
  226.  
  227.             Wait(1<<wind->UserPort->mp_SigBit);
  228.  
  229.             dowidzenia();
  230.  
  231.         }
  232.  
  233.         odcinekZ(xz,sz);
  234.  
  235.         zmiany++;
  236.  
  237.     }
  238.  
  239.     Wait(1<<wind->UserPort->mp_SigBit);
  240.  
  241.     dowidzenia();
  242.  
  243. }
  244.