/***********************************************/ /* Program rysuje krzywâ poôcigu (psia krzywa) */ /* Napisane dla Magazynu Amiga */ /* 1995 by BsZ */ /***********************************************/ #include #include #include #include #include #define WIDTH 640 #define HEIGHT 256 #define x0 10 #define y0 210 int xp,yp,xz,yz; /* wspóîrzëdne psa i zajâca */ struct Window *wind; struct IntuitionBase *IntuitionBase; struct GfxBase *GfxBase; struct NewWindow wind_data={ 0,0,WIDTH,HEIGHT,1,1,CLOSEWINDOW, ACTIVATE|GIMMEZEROZERO|WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH, 0,0,(UBYTE *)"Psia krzywa. (c) 1994 by BSZ",0,0, 200,256,WIDTH,HEIGHT,WBENCHSCREEN}; void dowidzenia(void) { if (wind) CloseWindow(wind); if (GfxBase) CloseLibrary((struct Library *)GfxBase); if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase); exit(0); } void OpenAllLibraries(void) { IntuitionBase=(struct IntuitionBase *) OldOpenLibrary("intuition.library"); if (!IntuitionBase) exit(100); GfxBase=(struct GfxBase *) OldOpenLibrary("graphics.library"); if (!GfxBase) exit(100); } int x(int X) { return(X+x0); } int y(int Y) { return(y0-Y); } void odcinekP(int x1,int y1,int x3,int y3,int d) { double D; int x2,y2; Move(wind->RPort,x(x1),y(y1)); D=sqrt( (double)( (x3-x1)*(x3-x1)+(y3-y1)*(y3-y1) ) ); x2=(int)( x1+d/D*(x3-x1) ); y2=(int)( y1-d/D*(y1-y3) ); if(d>=D) { Draw(wind->RPort,x(xz),y(yz)); xp=xz; yp=yz; } else { Draw(wind->RPort,x(x2),y(y2)); xp=x2; yp=y2; } } void odcinekZ(int x1, int d) { Move(wind->RPort,x(x1),y(0)); Draw(wind->RPort,x(x1+d),y(0)); xz=x1+d; } main(int argc,char *argv[]) { long int zmiany=0; /* iloôê zmian kierunku */ int t0; /* czas, czas reakcji w milisekundach */ int a,b; /* poîoûenia poczâtkowe zajâca i psa */ int vp,vz; /* prëdkoôci poczâtkowe */ int sp,sz; /* drogi */ if(argc!=6) { printf("Argumenty:t0 a b vz vp"); exit(0); } OpenAllLibraries(); if(!(wind=OpenWindow(&wind_data))) dowidzenia(); /* osie */ Move(wind->RPort,x0,y0); Draw(wind->RPort,x0,10); Move(wind->RPort,x0,y0); Draw(wind->RPort,610,y0); t0 = atoi(argv[1]); a = atoi(argv[2]); b = atoi(argv[3]); vz = atoi(argv[4]); vp = atoi(argv[5]); xp = 0; yp = b; xz = a; yz = 0; sp = vp*t0; sz = vz*t0; zmiany=0; SetAPen(wind->RPort,1); for(;;) { odcinekP(xp,yp,xz,yz,sp); if(xp>=xz || xp>WIDTH) { Wait(1<UserPort->mp_SigBit); dowidzenia(); } odcinekZ(xz,sz); zmiany++; } Wait(1<UserPort->mp_SigBit); dowidzenia(); }