48 lines
1.3 KiB
Text
48 lines
1.3 KiB
Text
include xpllib; \for DrawCircle, DrawLine, LineWidth, MovePen, Deg2Rad
|
|
def X0=400, Y0=300; \center coordinate
|
|
int Hour, Minute, Second;
|
|
|
|
proc DrawHand(Angle, Length, Width, Color);
|
|
real Angle, Length;
|
|
int Width, Color;
|
|
int X, Y;
|
|
[X:= fix(Length*Sin(Angle));
|
|
Y:= fix(Length*Cos(Angle));
|
|
LineWidth:= Width;
|
|
MovePen(X0, Y0);
|
|
DrawLine(X0+X, Y0-Y, Color);
|
|
];
|
|
|
|
proc DrawClock; \Show analog clock with current time
|
|
real Angle;
|
|
int N, X, Y;
|
|
[DrawCircle(X0, Y0, 299, LCyan, true);
|
|
Angle:= 0.;
|
|
for N:= 0 to 59 do \draw tick marks
|
|
[X:= fix(260.*Cos(Angle));
|
|
Y:= fix(260.*Sin(Angle));
|
|
DrawCircle(X+X0, Y+Y0, if rem(N/5) then 4 else 8, Black, true);
|
|
Angle:= Angle + 6.*Deg2Rad;
|
|
];
|
|
Angle:= float((Hour*60+Minute)/2) * Deg2Rad;
|
|
DrawHand(Angle, 210., 8, Black);
|
|
Angle:= float((Minute*60+Second)/10) * Deg2Rad;
|
|
DrawHand(Angle, 240., 5, Black);
|
|
Angle:= float(Second*6) * Deg2Rad;
|
|
DrawHand(Angle, 260., 3, LRed);
|
|
DrawCircle(X0, Y0, 8, Black, true);
|
|
];
|
|
|
|
int Second0;
|
|
char Time;
|
|
[SetVid($103); \800x600x8
|
|
InitDraw;
|
|
repeat Time:= GetDateTime;
|
|
Hour:= Time(3);
|
|
if Hour>=12 then Hour:= Hour-12;
|
|
Minute:= Time(4);
|
|
Second:= Time(5);
|
|
if Second # Second0 then
|
|
[Second0:= Second; DrawClock];
|
|
until KeyHit;
|
|
]
|