SRL Archive - Other Scripts

Clock with hands


SKy Scripter

2007-02-07 14:13:29

This is a clock i made for fun it has
hands test it out tell me if you like it

Fix The Second Glitch And FreeForm!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


program New;
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
//
//
//
//
////////////////////////////////////////////////////////////////////////////////

var
frmDesign : TForm;
Timer:TTimer;
x, y, a, b, i:Integer;
E:Array [1..4] of Extended;
Image: TImage;

Procedure GetTime(Var Sec, Min, Hour:Word);
Var Mil:Word;
begin
DecodeTime(Now, Hour, Min, Sec, Mil);
if (Hour >12) then
Hour:= Hour-12;
End;



Procedure DrawClock;
Var Sec, Min, Hour:Word;
begin
Try
GetTime(Sec, Min, Hour);
Image.SetBounds(0,0,392,266);
Image.CANVAS.Pen.WIDTH:=1;
Image.CANVAS.Pen.Color:=255;
For i:= 0 to 266 do
begin
Image.CANVAS.Pen.Color:=Image.CANVAS.Pen.Color-1
Image.CANVAS.LineTo(0,i);
Image.CANVAS.LineTo(392,i);
end;

Image.CANVAS.Brush.STYLE:= bsClear;
Image.CANVAS.Pen.Color:=15591915;
Image.CANVAS.Pen.WIDTH:=4;
Image.CANVAS.Ellipse(50,0,342,266);
Image.CANVAS.Font.Size:=15
Image.CANVAS.Font.Color:=15591915;

For i:= 1 to 12 do
begin
e[1]:= e[1]+0.523
a:= Round(115 * Sin(e[1]) + x);
b:= Round(-115 * Cos(e[1]) + y);
Image.CANVAS.TextOut(a-8,b-14,inttostr(i));
end;

For i:= 1 to 12 do
begin
e[1]:= e[1]+0.755
a:= Round(2 * Sin(e[1]) + x);
b:= Round(-2 * Cos(e[1]) + y);
Image.CANVAS.Pixels[A, B]:=15591915;
end;
e[1]:=0;

If Hour>0 then
begin
for i:= 1 to Hour do
e[4]:= E[4]+0.523
Image.CANVAS.Pen.WIDTH:=7;
Image.CANVAS.MoveTo(x,y);
a:= Round(105 * Sin(E[4]) + x);
b:= Round(-105 * Cos(E[4]) + y);
Image.CANVAS.LineTo(A,B);
e[4]:=0;
end;

If Min>0 then
begin
for i:= 1 to Min do
e[2]:= E[2]+0.106
Image.CANVAS.MoveTo(x,y);
Image.CANVAS.Pen.WIDTH:=4;
a:= Round(120 * Sin(E[2]) + x);
b:= Round(-120 * Cos(E[2]) + y);
Image.CANVAS.LineTo(A,B);
E[2]:=0
end;

If Sec>=0 then
begin
for i:= 1 to Sec do
e[3]:= E[3]+0.106
Image.CANVAS.Pen.WIDTH:=2;
Image.CANVAS.MoveTo(x,y);
a:= Round(135 * Sin(E[3]) + x);
b:= Round(-135 * Cos(E[3]) + y);
Image.CANVAS.LineTo(A,B);
e[3]:=0;
end;
Except
Writeln('Some Kind Of Error');
End;
end;

Procedure SafeDrawClock;
var V:TVariantArray;
begin
SetArrayLength(V,0);
ThreadSafeCall('DrawClock',V);
end;

Procedure ChangeHands(Sender:TObject);
begin
SafeDrawClock;
end;

procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 259;
frmDesign.Top := 132;
frmDesign.Width := 400;
frmDesign.Height := 300;
frmDesign.Caption := 'Clock';
x:= 392 shr 1;
y:= 266 shr 1;
Image := TImage.Create(frmDesign);
Image.Parent:=frmDesign;
DrawClock;
Timer:= TTimer.CREATE(frmDesign);
Timer.INTERVAL:= 500;
Timer.ONTIMER:= @ChangeHands;
end;

procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
end;

procedure ShowFormModal;
begin
frmDesign.ShowModal;
end;

procedure SafeShowFormModal;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;

begin
SafeInitForm;
SafeShowFormModal;
FreeForm(frmDesign);
end.

bullzeye95

2007-02-07 14:28:31

Haha that's awesome :)

One problem though. When it goes to a new minute, it messes up for a second.

SKy Scripter

2007-02-07 14:47:44

lol i noticed that but don't worry i resets it self to your computer time
:)

Janilabo

2007-02-07 16:24:18

Very nice Clock :)

SKy Scripter

2007-02-07 16:51:39

thank you :)

Freddy1990

2007-02-07 17:00:39

I like it, good job! :)

SKy Scripter

2007-02-07 17:23:00

thank you and EXTREMLY good work on SCAR 3.0
:spot:

Yakman

2007-02-08 02:31:24

very nice, good use of vector graphics

Ron

2007-02-08 15:37:25

Hey nice job man! Definite rep. ;)

Besides the bug described by bullzeye. You made a very common mistake. You forgot to free the form. Not a really big deal, but just so you don't make the mistake again with an even bigger project, make sure to put this at the end. :)

FreeForm(frmDesign);

Still an awesome job!

bullzeye95

2007-02-08 22:08:36

Sorry, but what was that TextOut thing you used? Did you edit it, or am I just crazy?

Drakan

2007-02-09 07:39:33

how do you do this…. man thats cool.. it does pause for a second but i think it jumps in on the seconds according to what the system time is

SKy Scripter

2007-02-09 12:47:32




Hey nice job man! Definite rep.

Besides the bug described by bullzeye. You made a very common mistake. You forgot to free the form. Not a really big deal, but just so you don't make the mistake again with an even bigger project, make sure to put this at the end.
FreeForm(frmDesign);


lol thank you i forgot to free it


Sorry, but what was that TextOut thing you used? Did you edit it, or am I just crazy?


the text out was the numbers around the clock
1,2,3,4..12

how do you do this…. man thats cool.. it does pause for a second but i think it jumps in on the seconds according to what the system time is

it does not jump a sec
because if it does i made the clock catch up to your system time

bullzeye95

2007-02-09 16:42:34

From: SKy Scripter
lol thank you i forgot to free it



the text out was the numbers around the clock
1,2,3,4..12


No, that thing where that picture went to the bottom of SCAR.

SKy Scripter

2007-02-10 17:31:59


No, that thing where that picture went to the bottom of SCAR.


hmm i don't no what you are talking about sorry
inless you played "how to change SCAR" that i made?

neo_welmeow

2007-05-31 03:57:33

i like it, very nice job

SKy Scripter

2007-05-31 15:01:26

i like it, very nice job


lol, you must be scanning old post..
But Thanks…

Wizzup?

2007-05-31 15:07:46

Haha, incredibly cool!

SKy Scripter

2007-05-31 15:12:56

Hah. You see my magic no?

lol thanks.. :p

wired16

2007-05-31 17:20:41

very cool +rep