unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; type { TForm1 } TForm1 = class(TForm) StartStopBtn: TButton; Screen: TPaintBox; procedure ScreenPaint(Sender: TObject); procedure StartStopBtnClick(Sender: TObject); private var EarthX, EarthY: Integer; { Координаты земли } EarthA: Real; { Текущий угол отклонения Земли } MoonX, MoonY: Integer; { Координаты Луны } MoonA: Real; { Текущий угол отклонения Луны } IsRunning: Boolean; const SunR: Integer = 60; { Радиус Солнца } EarthR: Integer = 20; { Радиус Земли } MoonR: Integer = 4; { Радиус Луны } EarthD: Integer = 140; { Расстояние от Солнца до Земли } MoonD: Integer = 40; { Радиус от Земли до Луны } EarthV: Real = 0.02; { Угловая скорость Земли } MoonV: Real = 0.1; { Угловая скорость Луны } public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.StartStopBtnClick(Sender: TObject); begin if IsRunning then begin IsRunning := false; StartStopBtn.Caption := 'Пуск'; Exit; end; StartStopBtn.Caption := 'Стоп'; IsRunning := true; { Инициализация переменных } EarthA := 0; MoonA := 0; EarthX := 0; EarthY := 0; MoonX := 0; MoonY := 0; while IsRunning do { Основной цикл } begin { Пересчитаем координаты Земли и Луны } EarthX := Round(Screen.Width div 2 + EarthD * Cos(EarthA)); EarthY := Round(Screen.Height div 2 + EarthD * Sin(EarthA)); MoonX := Round(EarthX + MoonD * Cos(MoonA)); MoonY := Round(EarthY + MoonD * Sin(MoonA)); EarthA := EarthA + EarthV; { Изменяем текущие углы отклонения } MoonA := MoonA + MoonV; { Земли и Луны } if EarthA > 2 * PI then EarthA := EarthA - 2 * PI; { Корректируем углы } if MoonA > 2 * PI then MoonA := MoonA - 2 * PI; { если требуется } Screen.Invalidate; Sleep(30); { Пауза } Application.ProcessMessages; if Application.Terminated then break; end; end; procedure TForm1.ScreenPaint(Sender: TObject); begin if not IsRunning then Exit; Screen.Canvas.Pen.Width := 5; { Толщина линий - 5 пикселей } Screen.Canvas.Pen.Color := clRed; { Рисуем Солнце в центре экрана } Screen.Canvas.Ellipse(Screen.Width div 2 - SunR, Screen.Height div 2 - SunR, Screen.Width div 2 + SunR, Screen.Height div 2 + SunR); Screen.Canvas.Pen.Color := clGreen; { Рисуем Землю } Screen.Canvas.Ellipse(EarthX - EarthR, EarthY - EarthR, EarthX + EarthR, EarthY + EarthR); { и Луну } Screen.Canvas.Pen.Color := clBlue; Screen.Canvas.Ellipse(MoonX - MoonR, MoonY - MoonR, MoonX + MoonR, MoonY + MoonR); end; end.