Анимация вращения Луны

Земля

Задача : создать приложение, выводящее на экран анимированное изображение.
Картинка рисуется при помощи графических примитивов: линия, эллипс, многоугольник.

unit Unit1; 
 
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls, ExtCtrls;
 
type
 
  { TForm1 }
 
  TForm1 = class(TForm)
    Button1: TButton;
    PaintBox1: TPaintBox;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end; 
 
var
  Form1: TForm1;
  BMP:TBitMap;
  y,x:integer;
 
implementation
 
{ TForm1 }
 
procedure TForm1.Button1Click(Sender: TObject);
begin
//окружность Земли
PaintBox1.canvas.Brush.color:=RGBTocolor(100,138,217);
PaintBox1.canvas.Ellipse(20,30,520,530);
PaintBox1.canvas.pen.color:=RGBTocolor(0,0,0);
 
//Северная Америка
PaintBox1.canvas.Brush.color:=RGBTocolor(121,228,105);
PaintBox1.canvas.polygon([point(120,84),point(125,130),point(130,110),
point(135,150),point(130,155),point(160,155),point(190,170),point(175,155),
point(179,150),point(169,150),point(169,140),point(178,130),point(190,135),
point(190,145),point(198,135),point(230,110),point(255,80),point(265,75),
point(240,55),point(270,40),point(280,50),point(300,37),point(250,35),
point(180,50)]);
 
//Южная Америка
PaintBox1.canvas.polygon([point(190,180),point(185,210),point(170,215),
point(160,235),point(190,265),point(205,270),point(210,360),point(225,375),
point(230,375),point(227,370),point(233,365),point(228,352),point(240,320),
point(235,315),point(243,315),point(260,290),point(255,282),point(280,268),
point(300,244),point(285,225),point(270,218),point(265,225),point(262,211),
point(240,200),point(235,206),point(230,195),point(210,173),point(204,170)]);
 
//Южный полюс
PaintBox1.canvas.Brush.color:=RGBTocolor(255,255,255);
PaintBox1.canvas.polygon([point(230,523),point(240,500),point(226,490),
point(260,485),point(263,460),point(268,500),point(274,505),point(310,495),
point(315,500),point(324,500),point(324,510),point(340,518),point(300,526),
point(260,528)]);
 
//часть Евразии
PaintBox1.canvas.Brush.color:=RGBTocolor(121,228,105);
PaintBox1.canvas.polygon([point(460,125),point(445,160),point(475,150)]);
 
//Африка
PaintBox1.canvas.Brush.color:=RGBTocolor(232,230,142);
PaintBox1.canvas.polygon([point(485,155),point(442,175),point(443,190),
point(455,198),point(455,210),point(485,220),point(493,310),point(483,340),
point(490,387),point(507,350),point(516,300),point(516,250),point(510,220)]);
 
//горы Северной Америки
PaintBox1.canvas.Brush.color:=RGBTocolor(226,189,63);
PaintBox1.canvas.Ellipse(140,105,160,150);
 
//Анды
PaintBox1.canvas.Brush.color:=RGBTocolor(143,113,48);
PaintBox1.canvas.polygon([point(212,325),point(222,295),point(222,250),
point(210,240),point(190,240),point(170,220),point(169,235),point(200,265),
point(209,265)]);
 
//Экватор
PaintBox1.canvas.line(22,270,520,270);
PaintBox1.canvas.Brush.color:=RGBTocolor(177,177,177);
 
 
x:=600;
y:=60;
 
//запоминание изображения для дальнейшего использование его в затирании при анимации
BMP:=TBitMap.Create;
BMP.Width:=PaintBox1.width;
BMP.Height:=PaintBox1.Height;
BMP.Canvas.CopyRect(Rect(0,0,PaintBox1.width,PaintBox1.Height),PaintBox1.Canvas,
Rect(0,0,PaintBox1.Width,PaintBox1.Height));
Timer1.Enabled:=True;
end;
 
//движение Луны
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  PaintBox1.Canvas.CopyRect(Rect(x,y,x+90,y+90),BMP.Canvas,Rect(x,y,x+90,y+90));
    x:=x-10;
    y:=y+5;
    PaintBox1.canvas.Ellipse(x,y,x+90,y+90);
    if(x <= 10)  then  begin
    PaintBox1.Canvas.CopyRect(Rect(x
    ,y,x+90,y+90),BMP.Canvas,Rect(x,y,x+90,y+90));
   x:=600;
   y:=60;
    PaintBox1.canvas.Ellipse(x,y,x+90,y+90);
    end;
 
end;
 
initialization
  {$I unit1.lrs}
 
end.
 

Ключевые слова: 
анимация, земля, движение
ВложениеРазмер
anim.zip945.01 кб