Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit MainUnit;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.ExtCtrls, System.Math, System.Uitypes;
- type
- TMainForm = class(TForm)
- MainImage: TImage;
- AnimationTimer: TTimer;
- procedure AnimationTimerTimer(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure FormKeyPress(Sender: TObject; var Key: Char);
- private
- { Private declarations }
- public
- procedure drawRings();
- procedure drawCircles();
- procedure restart();
- procedure clearCircles();
- function isEnd(): boolean;
- procedure writeEndLabel();
- procedure writeTopListLabel();
- procedure writePositionNumber(Index: integer; NumberOfCircle: integer);
- procedure writeRestartLabel();
- function findLastPosition(): integer;
- end;
- var
- MainForm: TMainForm;
- implementation
- {$R *.dfm}
- const
- XCentreCoord = 400;
- YCentreCoord = 375;
- NumberOfRings = 8;
- BiggestRingRadius = 340;
- BiggestCircleRadius = 38;
- NumberOfCircles = 8;
- NumberOfParams = 6;
- MaxWidth = 1200;
- MaxHeight = 800;
- XTextOffset = 800;
- VerticalOffset = 30;
- HorizontalOffset = 40;
- type
- TArrayOfParams = array[1..NumberOfCircles] of array[1..NumberOfParams] of integer;
- var
- IsPlaying: boolean = false;
- ArrayOfParams: TArrayOfParams;
- Angle: double = 0;
- procedure TMainForm.AnimationTimerTimer(Sender: TObject);
- begin
- if IsPlaying then
- begin
- clearCircles();
- Angle := Angle + 0.02;
- drawRings();
- writeTopListLabel();
- drawCircles();
- IsPlaying := not (isEnd());
- writeRestartLabel()
- end
- else
- begin
- AnimationTimer.Enabled := false;
- writeEndLabel();
- writeRestartLabel()
- end;
- end;
- procedure TMainForm.drawRings();
- var
- i, CurrentRadius: integer;
- begin
- CurrentRadius := BiggestRingRadius;
- for i := NumberOfRings downto 1 do
- begin
- with MainForm.MainImage do
- begin
- Canvas.Pen.Color := clBlack;
- Canvas.Pen.Width := 3;
- Canvas.Brush.Color := clSilver;
- Canvas.Ellipse(XCentreCoord - CurrentRadius, YCentreCoord - CurrentRadius,
- XCentreCoord + CurrentRadius, YCentreCoord + CurrentRadius);
- end;
- CurrentRadius := trunc(CurrentRadius / 1.3) - 10;
- end;
- end;
- procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
- begin
- if key = #13 then
- begin
- Angle := 0;
- clearCircles();
- restart();
- AnimationTimer.Enabled := true;
- IsPlaying := true;
- end;
- end;
- procedure TMainForm.FormShow(Sender: TObject);
- begin
- Angle := 0;
- clearCircles();
- restart();
- AnimationTimer.Enabled := true;
- IsPlaying := true;
- end;
- procedure TMainForm.drawCircles();
- var
- i, XCoord, YCoord, Index: integer;
- Coefficient, CurrentAngle: double;
- begin
- for i := NumberOfRings downto 1 do
- begin
- with MainForm.MainImage do
- begin
- case i of
- 1: Canvas.Brush.Color := clRed;
- 2: Canvas.Brush.Color := clMaroon;
- 3: Canvas.Brush.Color := clYellow;
- 4: Canvas.Brush.Color := clLime;
- 5: Canvas.Brush.Color := clAqua;
- 6: Canvas.Brush.Color := clBlue;
- 7: Canvas.Brush.Color := clFuchsia;
- 8: Canvas.Brush.Color := clBlack;
- end;
- Canvas.Pen.Color := clWhite;
- Canvas.Pen.Width := 0;
- Coefficient := ArrayOfParams[i][4] / 20;
- CurrentAngle := Coefficient * Angle;
- XCoord := trunc(XCentreCoord + ArrayOfParams[i][1] * cos(CurrentAngle));
- YCoord := trunc(YCentreCoord + ArrayOfParams[i][1] * sin(CurrentAngle));
- if (CurrentAngle > 2*Pi) then
- begin
- if (ArrayOfParams[i][3] = 0) then
- begin
- Index := findLastPosition();
- ArrayOfParams[i][3] := Index;
- end;
- Canvas.Ellipse(XCentreCoord + ArrayOfParams[i][1] - ArrayOfParams[i][2],
- YCentreCoord - ArrayOfParams[i][2],
- XCentreCoord + ArrayOfParams[i][1] + ArrayOfParams[i][2],
- YCentreCoord + ArrayOfParams[i][2]);
- Canvas.Ellipse(XTextOffset + 60 + HorizontalOffset - ArrayOfParams[i][2],
- trunc(1.85 * ArrayOfParams[8][2] * (ArrayOfParams[i][3] + 1)) - 35 - ArrayOfParams[i][2],
- XTextOffset + 60 + HorizontalOffset + ArrayOfParams[i][2],
- trunc(1.85 * ArrayOfParams[8][2] * (ArrayOfParams[i][3] + 1)) - 35 + ArrayOfParams[i][2]);
- writePositionNumber(ArrayOfParams[i][3], i);
- end
- else
- Canvas.Ellipse(XCoord - ArrayOfParams[i][2], YCoord - ArrayOfParams[i][2],
- XCoord + ArrayOfParams[i][2], YCoord + ArrayOfParams[i][2]);
- end;
- end;
- end;
- procedure TMainForm.restart();
- var
- i, j, CurrentRingRadius, CurrentCircleRadius: integer;
- begin
- CurrentRingRadius := BiggestRingRadius;
- CurrentCircleRadius := BiggestCircleRadius;
- for i := NumberOfCircles downto 1 do
- begin
- for j := 1 to NumberOfParams do
- begin
- case j of
- 1: ArrayOfParams[i][j] := CurrentRingRadius;
- 2: ArrayOfParams[i][j] := CurrentCircleRadius;
- 3: ArrayOfParams[i][j] := 0;
- 4:
- begin
- Randomize;
- ArrayOfParams[i][j] := Random(20) + 2;
- end;
- end;
- end;
- CurrentRingRadius := trunc(CurrentRingRadius / 1.3) - 10;
- CurrentCircleRadius := trunc(CurrentCircleRadius / 1.2);
- end;
- end;
- function TMainForm.isEnd(): boolean;
- var
- i: integer;
- isEnd: boolean;
- begin
- IsEnd := true;
- for i := 1 to NumberOfCircles do
- if ArrayOfParams[i][3] = 0 then
- isEnd := false;
- Result := isEnd;
- end;
- procedure TMainForm.writePositionNumber(Index: integer; NumberOfCircle: integer);
- begin
- with MainForm.MainImage do
- begin
- Canvas.Font.Color := clBlack;
- Canvas.Brush.Color := clSilver;
- Canvas.Font.Size := 14;
- Canvas.textOut(XTextOffset + 15, trunc(1.85 * ArrayOfParams[8][2] * (Index + 1)) - 50,
- intToStr(Index) + ': ');
- end;
- end;
- function TMainForm.findLastPosition(): integer;
- var
- i, MaxIndex: integer;
- begin
- MaxIndex := 0;
- for i := NumberOfCircles downto 1 do
- if ArrayOfParams[i][3] > MaxIndex then
- MaxIndex := ArrayOfParams[i][3];
- inc(MaxIndex);
- Result := MaxIndex;
- end;
- procedure TMainForm.writeEndLabel();
- begin
- with MainForm.MainImage do
- begin
- Canvas.Font.Color := clBlue;
- Canvas.Brush.Color := clSilver;
- Canvas.Font.Size := 15;
- Canvas.textOut(XTextOffset - 100, 650, 'Все фигуры достигли финиша!');
- end;
- end;
- procedure TMainForm.writeTopListLabel();
- begin
- with MainForm.MainImage do
- begin
- Canvas.Font.Color := clRed;
- Canvas.Brush.Color := clSilver;
- Canvas.Pen.Color := clPurple;
- Canvas.Pen.Width := 7;
- Canvas.Font.Size := 15;
- Canvas.textOut(XTextOffset, 10, 'Список прибывших:');
- Canvas.Brush.Color := clBlue;
- Canvas.MoveTo(XTextOffset - 30, 50);
- Canvas.LineTo(XTextOffset + 250, 50);
- end;
- end;
- procedure TMainForm.writeRestartLabel();
- begin
- with MainForm.MainImage do
- begin
- Canvas.Font.Color := clGreen;
- Canvas.Brush.Color := clSilver;
- Canvas.Pen.Color := clPurple;
- Canvas.Pen.Width := 7;
- Canvas.Font.Size := 15;
- Canvas.textOut(XTextOffset, 700, '[Enter] - начать заново.');
- end;
- end;
- procedure TMainForm.clearCircles();
- begin
- with MainForm.MainImage do
- begin
- Canvas.Pen.Color := clWhite;
- Canvas.Pen.Width := 3;
- Canvas.Brush.Color := clSilver;
- Canvas.Rectangle(0, 0, MaxWidth, MaxHeight);
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement