Вращение треугольникаРефераты >> Программирование и компьютеры >> Вращение треугольника
(-50,91,-50));
Var x_c , y_c : Integer;
Time2W : Byte;
Event : TEvent;
grDriver : Integer;
grMode : Integer;
ErrCode : Integer;
xn, yn, a : Integer;
Angle : Real;
K : ShortInt;
Procedure VgaDrv; external;
{$L EGAVGA.OBJ }
procedure SetCenter(x_nc , y_nc : integer);
begin
x_c := x_nc ; y_c := y_nc;
end;
Function Str2(Num:Integer):String;
Type S = String;
var P : ^S;
Begin
New(P); Str(Num,P^); Str2 := P^; Dispose(P);
End;
procedure draw(color:integer);
begin
SetColor(Color);
Line(x_c+ctr[1][1],y_c+ctr[2][1],x_c+ctr[1][2],y_c+ctr[2][2]);
Line(x_c+ctr[1][2],y_c+ctr[2][2],x_c+ctr[1][3],y_c+ctr[2][3]);
Line(x_c+ctr[1][3],y_c+ctr[2][3],x_c+ctr[1][1],y_c+ctr[2][1]);
end;
procedure DrawText(XX,YY : Integer; Text : String);
Begin
SetColor(Black);
OutTextXY(XX,YY,'');
SetColor(White);
OutTextXY(XX,YY,Text);
End;
procedure ShowD;
Begin
GetKeyEvent(Event);
If Event.What = evKeyDown Then
Case Event.KeyCode of
kbUp : Begin
if Time2W > 2 Then Time2W := Time2W - 1;
SetColor(Black);
OutTextXY(85,10, '');
SetColor(White);
OutTextXY(90,10,Str2(100-Time2W));
End;
kbDown : Begin
if Time2W < 100 Then Time2W := Time2W + 1;
SetColor(Black);
OutTextXY(85,10,'');
SetColor(White);
OutTextXY(90,10,Str2(102-Time2W));
End;
kbEnter : Begin
SetColor(LightRed);
OutTextXY(1,30, 'Freeze');
ReadKey;
SetColor(Black);
OutTextXY(1,30, '');
End;
kbTab : Begin
K := -K;
End;
End;
Angle := 0.1;
Draw(White);
Delay(Time2W);
Draw(Black);
for A := 1 to 3 do
begin
Xn := Round(ctr[1][a] * cos(Angle) + K * ctr[2][a] * sin(Angle));
Yn := Round(-K * ctr[1][a] * sin(Angle) + ctr[2][a] * cos(Angle));
Ctr[1][a] := Xn; Ctr[2][a] := Yn;
end;
Draw(White);
DrawText(105,60,Str2(x_c+ctr[1][1]));
DrawText(105,75,Str2(x_c+ctr[2][1]));
DrawText(105,90,Str2(x_c+ctr[1][2]));
DrawText(155,60,Str2(x_c+ctr[2][2]));
DrawText(155,75,Str2(x_c+ctr[1][3]));
DrawText(155,90,Str2(x_c+ctr[2][3]));
end;
begin
RegisterBgiDriver(@vgaDrv);
K:=-1;
Time2W := 15;
SetCenter(320,240);
Angle := 0.1;
grDriver := Detect;
grMode:=VGAHi; {video mode VGA 640x480x16colors}
InitGraph(grDriver, grMode,'');
ErrCode := GraphResult;
if ErrCode = grOk then
begin
OutTextXY(1,10,'Speed : '+Str2(100-Time2W));
OutTextXY(10,60,' Corn. 1 X Y');
OutTextXY(10,75,' Corn. 2 X Y');
OutTextXY(10,90,' Corn. 3 X Y');
SetTextStyle(TriplexFont, HorizDir, 2);
OutTextXY(10,425,'');
OutTextXY(10,415,'');
SetColor(Black);
OutTextXY(10,420,' -Exit -Freeze '+
' -Speed -Direction ');
SetColor(LightRed);
OutTextXY(10,420,' ESC Enter Up/Down TAB ');
SetTextStyle(DefaultFont, HorizDir, 1);
Repeat ShowD Until Event.KeyCode = kbEsc;
CloseGraph;
end
else Writeln('Graphics error : ', GraphErrorMsg(ErrCode));
end.