# enlarge and shrink a circle

Hey guys,

I was wondering if any of you can help me out, im still new to this.

I am trying to do a simple animation using pascal i.e. enlarging and shrinking a circle.

This is my code to draw the circle.
begin

Form1.Canvas.Pen.Width := 2;
Form1.Canvas.Pen.Color := clBlack;
Form1.Canvas.Brush.Color := clblack;
end;

I tried using if and then functions to do it, but it wont work e.g. if rc = 25 then rc:= rc+ 10 etc.

It seems like a for loop is suitable for this, but i have no idea how to get around doing it.

Thanks

• This is an example written in TP7, it is slow BGI graphics with lots of flickers. The idea is to draw a circle, wait some time, erase the circle, update the circle parameters then start over.[code][color=Blue]program bouncing_circles;

uses crt,graph;

const max_circle=8;

type _circle_=record
x,y:word; {coords.}
xm{ovement},ym{ovement}:shortint;
c{olor}:byte;
e{nlarging}:byte;
end;

var c:array[1..max_circle] of _circle_;
maxx,maxy,maxcolor:word;

procedure init_graph;
var gd, gt: integer;
begin
gd:=detect;
initgraph(gd,gt,'');
maxx:=getmaxx;
maxy:=getmaxy;
maxcolor:=getmaxcolor;
end;

procedure init_circles;
var i:byte;
begin
for i:=1 to max_circle do
with c[i] do begin
r:=0;
while r=max_radius then e:=0 else inc(r);
if xm<0 then
if x<=r then xm:=-xm else inc(x,xm)
else
if x>=maxx-r then xm:=-xm else inc(x,xm);
if ym<0 then
if y<=r then ym:=-ym else inc(y,ym)
else
if y>=maxy-r then ym:=-ym else inc(y,ym);
end;{with}

for i:=1 to max_circle do {draw new circles}
with c[i] do begin
setcolor(c);
circle(x,y,r);
end;{with}

delay(15); {wait a bit}

until keypressed;
end;

begin
randomize;
init_graph;
init_circles;
animate;
closegraph;
end.[/color][/code]
• Thanks a lot for this. Do you by any chance have a sample in delphi? That'll be helpful, if not this is fine too.