Анимация в delphi окружность движется по линиям семилучевой звезды

code: #delphi
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Spin;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
  xc,yc:integer;
  p:array[1..15] of Tpoint;
implementation
 
{$R *.dfm}
procedure Zvezda(c:integer;Cv:TCanvas);
begin
 with Cv do
  begin
   pen.Color:=c;
   polygon(p);//рисуем полигон
 end;
end;
procedure Okr(x,y,c:integer;cv:TCanvas);
begin
with cv do
 begin
  pen.Color:=c;
  ellipse(x-10,y-10,x+10,y+10);
 end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
color:=clWhite;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,x1,y1,x2,y2:integer;
    x,y,dx,dy,du:real;
begin
doublebuffered:=true;
xc:=Width div 2;
yc:=ClientHeight div 2-50;
du:=0;//вычисляем координаты вершин полигона
for i:=1 to 14 do
 begin
  if odd(i)then  //длииные лучи
   begin
    p[i].x:=xc+round(200*cos(du));
    p[i].y:=yc-round(200*sin(du));
   end
  else //короткие
   begin
    p[i].x:=xc+round(100*cos(du));
    p[i].y:=yc-round(100*sin(du));
   end;
  du:=du+pi/7;
 end;
p[15].x:=p[1].x; //заиыкаем полигон
p[15].y:=p[1].y;
Zvezda(clRed,Form1.Canvas);
for i:=1 to 14 do
 begin
  x1:=p[i].x; y1:=p[i].y;
  x2:=p[i+1].x; y2:=p[i+1].y;
  dx:=(x2-x1)/20;
  dy:=(y2-y1)/20;
  x:=p[i].x;
  y:=p[i].y;
  while (abs(x-x2)>1)or(abs(y-y2)>1) do
   begin
    sleep(200);
    Zvezda(clWhite,Form1.Canvas);
    Okr(round(x),round(y),clWhite,Form1.Canvas);
    x:=x+dx;
    y:=y+dy;
    Zvezda(clRed,Form1.Canvas);
    Okr(round(x),round(y),clBlue,Form1.Canvas);
   end;
 end;
end;
end.

автор: Puporev

Поделиться:

Похожие статьи: