تمرین(2) 89/8/25
برنامه زیر را اجرا کرده و سعی کنید از عملکرد دستورات آن سر در آورید:
program JumpingJack;
{Moves a stick figure across the screen.}
uses
Graph, Crt;
const
Directory = 'C:\tp\BGI'; {Graphicd directory}
DelayTime = 250; {time between "frames" - 1/4 of a second}
var
XPosition, YPosition, {Position of stick figure}
Driver, Mode, {graphics system indicators}
I : Integer; {loop control variable}
Standing : Boolean; {flag - determines orientation}
procedure DrawMan (X, Y {input} : Integer;
Standing {input} :Boolean);
{
Draw a standing or jumping stick figure.
Pre : X, Y, Standing are defined.
Post: Stick figure is drawn with head centered at pixel
(X, Y) with arms and legs down if Standing is True
and with arms and legs raised if Standing is False.
}
begin {DrawMan}
Circle (X, Y, 20);
Line (X, Y + 20, X, Y + 60);
if Standing then
begin {Standing}
Line (X, Y + 30, X - 20, Y + 60); {Draw left arm.}
Line (X, Y + 30, X + 20, Y + 60); {Draw right arm.}
Line (X, Y + 60, X - 20, Y + 100); {Draw left leg.}
Line (X, Y + 60, X + 20, Y + 100) {Draw right leg.}
end {Standing}
else
begin {jumping}
Line (X, Y + 30, X - 30, Y + 20); {Draw left arm.}
Line (X, Y + 30, X + 30, Y + 20); {Draw right arm.}
Line (X, Y + 60, X - 30, Y + 80); {Draw left leg.}
Line (X, Y + 60, X + 30, Y + 80) {Draw right leg.}
end {jumping}
end; {DrawMan}
begin {JumpingJack}
InitGraph (driver, Mode, Directory); {Initialize graphics.}
OutTextXY (10, 10,'Press any key to stop the stick figure:');
XPosition := 20;
YPosition := GetMaxY div 2;
{Draw the stick figure repeatealy.}
Standing := True; {Start in standing position.}
repeat
{Draw the stick figure.}
SetColor (White);
DrawMan (XPosition, YPosition, Standing);
Delay (DelayTime); {Wait . . .}
{Erase the stick figure.}
SetColor (Black);
DrawMan (XPosition, YPosition, Standing);
{Move the stick figure and change its position.}
XPosition := Xposition + 5;
Standing := not standing
until KeyPressed
end. {JumpingJack}
{Moves a stick figure across the screen.}
uses
Graph, Crt;
const
Directory = 'C:\tp\BGI'; {Graphicd directory}
DelayTime = 250; {time between "frames" - 1/4 of a second}
var
XPosition, YPosition, {Position of stick figure}
Driver, Mode, {graphics system indicators}
I : Integer; {loop control variable}
Standing : Boolean; {flag - determines orientation}
procedure DrawMan (X, Y {input} : Integer;
Standing {input} :Boolean);
{
Draw a standing or jumping stick figure.
Pre : X, Y, Standing are defined.
Post: Stick figure is drawn with head centered at pixel
(X, Y) with arms and legs down if Standing is True
and with arms and legs raised if Standing is False.
}
begin {DrawMan}
Circle (X, Y, 20);
Line (X, Y + 20, X, Y + 60);
if Standing then
begin {Standing}
Line (X, Y + 30, X - 20, Y + 60); {Draw left arm.}
Line (X, Y + 30, X + 20, Y + 60); {Draw right arm.}
Line (X, Y + 60, X - 20, Y + 100); {Draw left leg.}
Line (X, Y + 60, X + 20, Y + 100) {Draw right leg.}
end {Standing}
else
begin {jumping}
Line (X, Y + 30, X - 30, Y + 20); {Draw left arm.}
Line (X, Y + 30, X + 30, Y + 20); {Draw right arm.}
Line (X, Y + 60, X - 30, Y + 80); {Draw left leg.}
Line (X, Y + 60, X + 30, Y + 80) {Draw right leg.}
end {jumping}
end; {DrawMan}
begin {JumpingJack}
InitGraph (driver, Mode, Directory); {Initialize graphics.}
OutTextXY (10, 10,'Press any key to stop the stick figure:');
XPosition := 20;
YPosition := GetMaxY div 2;
{Draw the stick figure repeatealy.}
Standing := True; {Start in standing position.}
repeat
{Draw the stick figure.}
SetColor (White);
DrawMan (XPosition, YPosition, Standing);
Delay (DelayTime); {Wait . . .}
{Erase the stick figure.}
SetColor (Black);
DrawMan (XPosition, YPosition, Standing);
{Move the stick figure and change its position.}
XPosition := Xposition + 5;
Standing := not standing
until KeyPressed
end. {JumpingJack}
+ نوشته شده در شنبه بیست و دوم آبان ۱۳۸۹ ساعت 0:2 توسط کلانترزاده
|