Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program cannon;
- uses Graph,Crt;
- const dt=0.035;
- g=98.1;
- var a,v0,x,y,t:Real;
- gd,gm,maxX,maxY,midX,midY,i:Integer;
- PathToDriver,stat,xs,ys,ts:String;
- clr1:Boolean;
- ch:Char;
- procedure TUI1;
- begin
- WriteLn;
- Write('Angle:');
- ReadLn(a);
- a:=a*Pi/180;
- Write('Initial speed:');
- ReadLn(v0);
- v0:=v0*10;
- end;
- procedure startgraph;
- begin
- gd:=0;
- PathToDriver:='P:\BGI\';
- DetectGraph(gd,gm);
- InitGraph(gd,gm,PathToDriver);
- maxX:=GetMaxX;
- maxY:=GetMaxY;
- midX:=maxX div 2;
- midY:=maxY div 2;
- end;
- procedure DrawGrid;
- begin
- MoveTo(midX,midY);
- SetColor(15);
- Rectangle(midX-5,midY-3,midX+5,midY+3);
- MoveTo(0,0);
- for i:=1 to 64 do
- begin
- SetColor(i);
- SetFillStyle(SolidFill,i);
- Bar(8*i,8,8*i+8,16);
- end;
- end;
- procedure DrawTrack;
- begin
- x:=midX;
- y:=midY;
- t:=0;
- clr1:=False;
- MoveTo(Round(x),Round(y));
- while (GetX>0) and (GetX<maxX) {and (GetY>0)} and (GetY<maxY) do
- begin
- if clr1 then
- begin
- SetColor(64);
- clr1:=False;
- end else
- begin
- SetColor(7);
- clr1:=True;
- end;
- t:=t+dt;
- x:=midX + v0*Cos(a)*t;
- y:=midY - v0*Sin(a)*t + (g*t*t)/2;
- LineTo(Round(x),Round(y));
- MoveTo(32,32);
- SetFillStyle(SolidFill,16);
- Bar(32,32,300,48);
- SetColor(15);
- Str(x:0:4,xs);
- Str(y:0:4,ys);
- Str(t:0:4,ts);
- stat:='x: '+xs+' y: '+ys+' t: '+ts;
- OutText(stat);
- MoveTo(Round(x),Round(y));
- Delay(Round(dt*1000));
- if KeyPressed then ch:=ReadKey;
- case ch of
- #75: t:=Abs(t-10*dt);
- #77: t:=t+dt;
- #32: Readkey;
- end;
- end;
- end;
- {main}
- begin
- TUI1;
- startgraph;
- drawgrid;
- drawtrack;
- ReadLn;
- CloseGraph;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement