program caratula;
uses crt,graph,dos;

procedure graf;
var ag,mg:integer;
begin
 ag:=detect;
 initgraph(ag,mg,'c:\tp6');
end;

procedure reloj;
var h,m,s,c,ha,ma,sa:word;
    hr,xh,yh,xm,ym,xs,ys:real;
    k,sv,mv:integer;
    x,y:real;
    cad,ch,cm,cs:string;
begin
 setbkcolor(8);
 gettime(h,m,s,c);
 setlinestyle(0,0,3);
 setcolor(6);
 circle(320,240,200);
 setfillstyle(1,7);
 floodfill(320,240,6);
 setfillstyle(1,6);
 fillellipse(320,240,3,3);
 setcolor(14);
 settextstyle(0,0,1);
 for k:=1 to 12 do
 begin
  x:=180*cos((90-k*30)*pi/180);
  y:=180*sin((90-k*30)*pi/180);
  str(k,cad);
  setcolor(14);
  outtextxy(317+round(x),238-round(y),cad);
 end;
 settextstyle(4,0,5);
 setcolor(15);
 outtextxy(570,100,'R');
 outtextxy(570,150,'E');
 outtextxy(570,200,'Y');
 outtextxy(570,250,'E');
 outtextxy(570,300,'S');
 setcolor(6);
 for k:=1 to 60 do
 begin
  line(320+round(199*cos((90-k*6)*pi/180)),240-round(199*sin((90-k*6)*pi/180)),
       320+round(186*cos((90-k*6)*pi/180)),240-round(186*sin((90-k*6)*pi/180)));
 end;
 str(h,ch);
 if h<10 then ch:='0'+ch;
 str(m,cm);
 if m<10 then cm:='0'+cm;
 str(s,cs);
 if s<10 then cs:='0'+cs;
 setfillstyle(1,1);
 bar(450,430,600,469);
 settextstyle(3,0,4);
 setcolor(15);
 outtextxy(450,430,ch+':'+cm+':'+cs);
 hr:=h mod 12;
 xh:=140*cos((90-(hr *30 + m /2))*pi/180);
 yh:=140*sin((90-(hr *30 + m /2))*pi/180);
 setcolor(9);
 line(320,240,320+round(xh),240-round(yh));
 mv:=m;
 xm:=160*cos((90-mv*6 )*pi/180);
 ym:=160*sin((90-mv*6 )*pi/180);
 setcolor(10);
 line(320,240,320+round(xm),240-round(ym));
 sv:=s;
 xs:=165*cos((90-sv*6)*pi/180);
 ys:=165*sin((90-sv*6)*pi/180);
 setcolor(11);
 line(320,240,320+round((xs)),240-round((ys)));
 ha:=h; ma:=m; sa:=s;
 repeat
  gettime(h,m,s,c);
  str(h,ch);
  if h<10 then ch:='0'+ch;
  str(m,cm);
  if m<10 then cm:='0'+cm;
  str(s,cs);
  if s<10 then cs:='0'+cs;
  setcolor(7);
  if m<>ma then
  begin
   line(320,240,320+round(xh),240-round(yh));
   ha:=h;
  end;
  if m<>ma then
  begin
   line(320,240,320+round(xm),240-round(ym));
   ma:=m;
  end;
  if s<>sa then
  begin
   line(320,240,320+round(xs),240-round(ys));
   setfillstyle(1,1);
   bar(450,430,600,469);
   setcolor(15);
   settextstyle(3,0,4);
   outtextxy(450,430,ch+':'+cm+':'+cs);
   settextstyle(4,0,5);
   setcolor(random(7)+9);
   outtextxy(570,100,'R');
   outtextxy(570,150,'E');
   outtextxy(570,200,'Y');
   outtextxy(570,250,'E');
   outtextxy(570,300,'S');
   sound(500);
   delay(3);
   nosound;
   sa:=s;
  end;
  hr:=h mod 12;
  xh:=140*cos((90-(hr*30 + m div 2 ))*pi/180);
  yh:=140*sin((90-(hr*30 + m div 2 ))*pi/180);
  setcolor(9);
  line(320,240,320+round(xh),240-round(yh));
  mv:=m;
  xm:=160*cos((90-mv*6)*pi/180);
  ym:=160*sin((90-mv*6)*pi/180);
  setcolor(10);
  line(320,240,320+round(xm),240-round(ym));
  sv:=s;
  xs:=165*cos((90-sv*6)*pi/180);
  ys:=165*sin((90-sv*6)*pi/180);
  setcolor(11);
  line(320,240,320+round(xs),240-round(ys));
 until keypressed;
end;

begin
 graf;
 reloj;
 closegraph
end.