Professional Documents
Culture Documents
{ --------
Analog clock demo for Pascal N-IDE
by: Mr Bee -- @pak_lebah
}
uses
CRT, Graph, SysUtils, DOS, Math;
type
// screen orientation
// clock structure
TPoint = record
x, y : integer;
// x,y coordinat
end;
TAngle = record
a : float;
// angle
r : integer;
// radius
end;
var
o : TOrientation;
c : TPoint;
a : TAngle;
procedure drawText;
var
t : string = 'Analog Clock';
h, n, s, z, w : Word;
j, m, d, e : string;
yr, mo, dy, wd : Word;
begin
setTextStyle(defaultFont, horizDir, 3);
setTextJustify(leftText, topText);
setColor(15);
w := textWidth(t) div 2;
if o = oPortrait then
outTextXY(c.x - w, c.y - a.r - 50, t)
else
outTextXY(c.x - a.r - w * 2 - 50, c.y, t);
// show digital time
getTime(h, n, s, z);
j := intToStr(h);
if length(j) = 1 then j := '0' + j;
m := intToStr(n);
if length(m) = 1 then m := '0' + m;
d := intToStr(s);
if length(d) = 1 then d := '0' + d;
e := intToStr(z);
if length(e) = 1 then e := '0' + e;
t := j + ':' + m + ':' + d + '.' + e;
w := textWidth(t) div 2;
if o = oPortrait then
outTextXY(c.x - w, c.y + a.r + 80, t)
else
outTextXY(c.x + a.r + 50, c.y, t);
getDate(yr, mo, dy, wd);
// FORMAT DOES NOT WORK!!!
//t := format('%-2.2d-%-2.2d-%-2.2d',[dy,mo,yr]);
//outTextXY(c.x-w,c.y+a.r+140,t)
end;
procedure drawFace;
var
i : integer;
p : TPoint;
r : TAngle;
begin
// style
setTextJustify(centerText, centerText);
setTextStyle(defaultFont, horizDir, 3);
setLineStyle(solidLn, 0, 2);
setFillStyle(solidFill, color(24, 24, 24));
setColor(7);
r := a;
// border
//circle(c.x,c.y,a.r);
pieSlice(c.x, c.y, 0, 360, a.r);
// center
//circle(c.x,c.y,10);
// tick marks
i := 0;
r.r := r.r - 30;
repeat
i := i + 1;
r.a := i * 6; // second degree
p := hand(c, r);
// hour ticks
if i * 6 mod 30 = 0 then
fillEllipse(p.x, p.y, 1, 1)
else
putPixel(p.x, p.y, 7);
until i > 60;
// hour marks
i := 0;
r.r := r.r - 30;
repeat
i := i + 1;
r.a := i * 30; // hour degree
p := hand(c, r);
outTextXY(p.x, p.y, intToStr(i));
until i >= 12;
end;
procedure getOrientation;
begin
c.x := getMaxX div 2;
c.y := getMaxY div 2;
if c.x > c.y then o := oLandscape
else o := oPortrait;
if o = oLandscape then
a.r := c.y - 10 else a.r := c.x - 10;
end;
procedure openScreen;
var
gd, gm : integer;
begin
gd := detect;
setBufferEnable(true);
initGraph(gd, gm, '');
end;
procedure closeScreen;
begin
closeGraph;
end;
var
h, n, s, z : word;
begin
openScreen;
getOrientation;
repeat
clearBuffer;
drawText;
drawFace;
getTime(h, n, s, z);
handHour(h, n);
handMinute(n, s);
handSecond(s, z);
drawBuffer;
until keyPressed;
closeScreen;
end.