Bouncing Balls
program Balls;
uses Types, QuickDraw, Events, MiscTool;

var
	i: Integer;
	x, y, sx, sy: Array[1..10] of Integer;
	ball: Rect;
	
begin
	graphics(320);
	clearScreen(black);
	hideCursor;
	setPenSize(3, 3);
	setRandSeed(getTick);

	{ Setup balls }

	for i := 1 to 10 do begin
		x[i] := random mod 300 + 10;
		y[i] := random mod 180 + 10;
		
		if random > 0 then
			sx[i] := random mod 2 + 1
		else
			sx[i] := -(random mod 2 + 1);
		
		if random > 0 then
			sy[i] := random mod 2 + 1
		else
			sy[i] := -(random mod 2 + 1);
	end;
	
	repeat
		for i := 1 to 10 do begin
		
			{ Draw balls }
			
			setRect(ball, x[i], y[i], x[i] + 10, y[i] + 10);
			setSolidPenPat(i);	
			paintOval(ball);
			setRect(ball, x[i] - 2, y[i] - 2, x[i] + 12, y[i] + 12);
			setSolidPenPat(black);
			frameOval(ball);
		
			{ Move balls }
		
			x[i] := x[i] + sx[i];
			y[i] := y[i] + sy[i];
		
			if (x[i] < 0) or (x[i] > 319) then
				sx[i] := -sx[i];
		
			if (y[i] < 0) or (y[i] > 199) then
				sy[i] := -sy[i];
		end;
	until button(0);
end.
This program uses array to generate many balls and animate them all at once at different speed and direction. Also teaches random number generation.
Sample Codes
Hosted by www.Geocities.ws

1