урок на делфи 22 - Таракашка
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.jpeg, Vcl.ExtCtrls,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x,y:integer;
implementation
{$R *.dfm}
procedure RotateBitmap(Bitmap:TBitmap);
var i,j,ei,ej:integer;
Buffer:TBitmap;
begin
Buffer:=TBitmap.Create;
try
Buffer.HandleType:=Bitmap.HandleType;
Buffer.PixelFormat:=Bitmap.PixelFormat;
Buffer.Palette:=Bitmap.Palette;
Buffer.Width:=Bitmap.Height;
Buffer.Height:=Bitmap.Width;
ei:=Bitmap.Height-1; ej:=Bitmap.Width-1;
for i:=0 to ei do
for j:=0 to ej do
Buffer.Canvas.Pixels[i,ej-j]:=Bitmap.Canvas.Pixels[j,i];
//в зависимости от направления поворота может быть Buffer.Canvas.Pixels[ei-i,j]:=Bitmap.Canvas.Pixels[j,i];
Bitmap.Assign(Buffer);
finally Buffer.Free; end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (Image1.Left
begin
Image1.Left:=Image1.Left+30;
if Timer1.Tag=3 then
begin
RotateBitmap(Image1.Picture.Bitmap);
Image1.Picture.Assign(Image1.Picture.Bitmap);
Timer1.Tag:=0;
end;
end;
if (Image1.Left >Form1.Width-120) and (Image1.Top>70) then
begin
Image1.Top:=Image1.Top-30;
if Timer1.Tag=0 then
begin
RotateBitmap(Image1.Picture.Bitmap);
Image1.Picture.Assign(Image1.Picture.Bitmap);
Timer1.Tag:=1;
end;
end;
if Image1.Top<60 then
begin
Image1.Left:=Image1.Left-30;
if Timer1.Tag=1 then
begin
RotateBitmap(Image1.Picture.Bitmap);
Image1.Picture.Assign(Image1.Picture.Bitmap);
Timer1.Tag:=2;
end;
end;
if Image1.left<50 then
begin
Image1.top:=Image1.top+30;
if Timer1.Tag=2 then
begin
RotateBitmap(Image1.Picture.Bitmap);
Image1.Picture.Assign(Image1.Picture.Bitmap);
Timer1.Tag:=3;
end;
end;
end;
end.