{******************************************************************************* Program to bounce animated ball around screen *******************************************************************************} program ball1(input, output); uses gralib; label 99; const ballsize = 21; halfball = ballsize div 2; frametime = 156; { time between frames, 60 cycle refresh } ballaccel = 5; { ball acceleration } var x, y: integer; nx, ny: integer; xd, yd: integer; er: evtrec; tc: integer; { wait time in 100 microseconds } procedure wait(t: integer); begin timer(input, 1, t, false); repeat event(input, er) until (er.etype = ettim) or (er.etype = etterm); if er.etype = etterm then goto 99 end; begin curvis(output, false); { turn off cursor } x := halfball; { set inital ball location } y := halfball; xd := +1; { set movements } yd := +1; while true do begin { place ball } fcolor(output, green); fellipse(output, x-halfball+1, y-halfball+1, x+halfball-1, y+halfball-1); wait(frametime); { wait } { erase ball } fcolor(output, white); fellipse(output, x-halfball+1, y-halfball+1, x+halfball-1, y+halfball-1); for tc := 1 to ballaccel do begin { move ball } nx := x+xd; { trial move ball } ny := y+yd; { check out of bounds and reverse direction } if (nx < halfball) or (nx > maxxg(output)-halfball+1) then xd := -xd; if (ny < halfball) or (ny > maxyg(output)-halfball+1) then yd := -yd; x := x+xd; { move ball } y := y+yd end end; 99: curvis(output, true) { turn on cursor } end.