Recent Posts
Selamat datang di Coding Delphi Land Weblog kumpulan source code pemogram delphi
(Bukan maksud untuk menggurui tetapi marilah kita berbagi ilmu tuk perkembangan kemajuan teknologi kita
Minggu, 15 November 2009
Bouncing Image
unit bouncingcode;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Image1: TImage;
Timer2: TTimer;
procedure FormActivate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
quote1:string ;
quote2:string;
quote3:string;
vert : integer;
hoiz : integer;
step : integer;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormActivate(Sender: TObject);
begin
quote1 := 'Bouncing Picture Affect';
quote2 := 'Created By J';
quote3 := 'www.projectscript.tk';
vert := 1;
hoiz := 1;
step := 5;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
val:integer;
begin
{This code randomizes the froms caption}
val := random(3) + 1;
case val of
1 : form1.caption := quote1;
2 : form1.caption := quote2;
3 : form1.caption := quote3;
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var
pictureVal:integer;
begin
{code randomizes the pciture that appears this cause the flashing affect}
pictureVal := random(4)+1;
case pictureVal of
1 : image1.picture.loadfromfile('image1.bmp');
2 : image1.picture.loadfromfile('image2.bmp');
3 : image1.picture.loadfromfile('image3.bmp');
4 : image1.picture.loadfromfile('image4.bmp');
end;
{this code makes the picture bounce around}
image1.left := image1.left + hoiz * step; {horiz is set to 1 and step is 5 to 1 * 5 is
5 and that is how many pixels it moves}
image1.top := image1.Top + vert * step;{same as the hoiz code}
if image1.left + image1.Width >= form1.clientwidth{this code checks to if the pciture is at the end
of the form and if it is it sets hoiz to -1 and to -1 * 5 = -5 so it moves in the other direction}
then
hoiz := -1;
{below is the same code as above}
if image1.top + image1.height >= form1.clientheight
then
vert := -1;
{the picture is moving left so this code checks to see
if the picture is less than step which is set to 5 so if the picture is y co-ord is less than 5 it starts moving right}
if image1.left <> then
begin
hoiz := 1;
end;
if image1.Top <> then
vert := 1;
end;
end.
0 komentar:
Posting Komentar