home *** CD-ROM | disk | FTP | other *** search
- unit MainUnit;
-
- (* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Graphics32
- *
- * The Initial Developer of the Original Code is
- * Alex A. Denisov
- *
- * Portions created by the Initial Developer are Copyright (C) 2000-2004
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * ***** END LICENSE BLOCK ***** *)
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- GR32, GR32_Transforms, StdCtrls, AppEvnts, GR32_Image, GR32_Layers;
-
- type
- TForm1 = class(TForm)
- Image32: TImage32;
- Button1: TButton;
- Edit1: TEdit;
- Button2: TButton;
- BitmapList: TBitmap32List;
- Label1: TLabel;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- public
- Velocities: TArrayOfFloatPoint;
- procedure IdleHandler(Sender: TObject; var Done: Boolean);
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- X: Integer;
- ALayer: TBitmapLayer;
- L: TFloatRect;
- I: Integer;
- begin
- Image32.BeginUpdate;
- for X := 0 to 49 do
- begin
- // create a new layer...
- ALayer := TBitmapLayer.Create(Image32.Layers);
- with ALayer do
- begin
- Bitmap := BitmapList.Bitmaps[Random(BitmapList.Bitmaps.Count)].Bitmap;
- Bitmap.DrawMode := dmBlend;
- Bitmap.MasterAlpha := Random(255);
-
- // put it somethere
- L.Left := Random(Image32.Width);
- L.Top := Random(Image32.Height);
- L.Right := L.Left + Bitmap.Width;
- L.Bottom := L.Top + Bitmap.Height;
- ALayer.Location := L;
-
- I := Length(Velocities);
- SetLength(Velocities, I + 1);
- Velocities[I] := FloatPoint(Random - 0.5, Random - 0.5);
- end;
- end;
- Image32.EndUpdate;
- Image32.Changed;
- Edit1.Text := IntToStr(Image32.Layers.Count) + ' layers';
- end;
-
- procedure TForm1.IdleHandler(Sender: TObject; var Done: Boolean);
- var
- I: Integer;
- R: TFloatRect;
- begin
- if Image32.Layers.Count = 0 then Exit;
- Image32.BeginUpdate;
- for I := 0 to Image32.Layers.Count - 1 do
- begin
- with TBitmapLayer(Image32.Layers[I]) do
- begin
- Bitmap.MasterAlpha := (Bitmap.MasterAlpha + 1) mod 256;
- R := Location;
- with Velocities[I] do
- begin
- OffsetRectF(R, X, Y);
- X := X + (Random - 0.5) * 0.1;
- Y := Y + (Random - 0.5) * 0.1;
- if (R.Left < 0) and (X < 0) then X := 1;
- if (R.Top < 0) and (Y < 0) then Y := 1;
- if (R.Right > Image32.Width) and (X > 0) then X := -1;
- if (R.Bottom > Image32.Height) and (Y > 0) then Y := -1;
- end;
- Location := R;
- end;
- end;
- Image32.EndUpdate;
- Image32.Invalidate;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- Image32.Layers.Clear;
- Velocities := nil;
- Edit1.Text := '0 layers';
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Application.OnIdle := IdleHandler;
- end;
-
- end.
-