real_het

ConsoleClock.dpr

Nov 13th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.95 KB | None | 0 0
  1. program ConsoleClock;{$APPTYPE CONSOLE}
  2. uses windows, SysUtils, graphics;
  3.  
  4. procedure DrawClk;
  5. var b:tbitmap;
  6.  
  7.   function a2p(const a,r:single):TPoint; //transzforamcio polarbol -> screen-re
  8.   begin
  9.     result.x:=round(cos(a-pi/2)*r*1.3)+40;
  10.     result.y:=round(sin(a-pi/2)*r)+25;
  11.   end;
  12.  
  13.   procedure text(a,r:single;s:string);
  14.   begin
  15.     //ezt imádni fogod a C#-bol :D
  16.     with b.canvas, textextent(s), a2p(a,r)do TextOut(x-cx shr 1, y-cy shr 1,s);
  17.   end;
  18.  
  19.   procedure line(a,r0,r1:single);
  20.   begin
  21.     with a2p(a,r0)do b.Canvas.MoveTo(x,y);
  22.     with a2p(a,r1)do b.Canvas.LineTo(x,y);
  23.   end;
  24.  
  25. const szamlap:array[1..12]of string=('I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII');
  26. var h,m,s,z:word;
  27.     c,i,j,k:integer;
  28.     st:ansistring;
  29.     ch:ansichar;
  30.     a:single;
  31. begin
  32.   DecodeTime(now,h,m,s,z);
  33.   b:=TBitmap.Create;
  34.   with b, Canvas do begin
  35.     PixelFormat:=pf32bit; Width:=80; Height:=50;
  36.     Font.Name:='Times New Roman';
  37.     Font.Size:=8;
  38.     Brush.Style:=bsClear;
  39.     for i:=1 to 12 do text(i/12*2*pi,22,szamlap[i]); //számozás
  40.  
  41.     //kismutato
  42.     a:=frac(now)*pi;
  43.     Pen.Color:=clBlack; Pen.Width:=3; line(a,-3,8);
  44.     Pen.Color:=clWhite; Pen.Width:=1; line(a,-3,8);
  45.  
  46.     //nagymutato
  47.     a:=a*12;
  48.     Pen.Color:=clBlack; Pen.Width:=3; line(a,-3,16);
  49.     Pen.Color:=clWhite; Pen.Width:=1; line(a,-3,16);
  50.  
  51.     //masodperec
  52.     a:=a*60;
  53.     Pen.Color:=clBlack; Pen.Width:=1; line(a,-3,16);
  54.  
  55.     i:=0;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),_COORD(i));//cursor home
  56.     st:='';
  57.     for j:=0 to b.Height shr 1-1 do for i:=0 to b.Width-1 do begin
  58.       c:=0;for k:=0 to 1 do c:=c+PIntegerArray(b.ScanLine[j shl 1+k])[i]and $ff;
  59.       if c=$ff*2 then ch:=' ' else if c=0 then ch:='#' else ch:='+';
  60.       st:=st+ch;
  61.     end;
  62.     Delete(st,length(st),1);// ne legyen ujsor a legaljan
  63.     write(st);
  64.  
  65.     free;//b
  66.   end;
  67. end;
  68.  
  69. begin
  70.   while True do begin DrawClk;Sleep(300);end;
  71. end.
Advertisement
Add Comment
Please, Sign In to add comment