void __fastcall TForm1::Vector (int x0, int y0, int a, int l)
{
// x0,y0 – vektorning boshlanishi
//a – X o’qi va vektor o’rtasidagi burchak
// l – vektor uzunligi
#define TORAD 0.0174532 // burchakni gradusdan
// radianga o’tkazish koeffisetsenti
int x, y; // vektorning tugash koordinatasi
Canvas->MoveTo(x0,y0);
x = x0 + l * cos(a*TORAD);
y = y0 - l * sin(a*TORAD);
Canvas->LineTo(x,y);
}
// siferblatni qayta chizish
void __fastcall TForm1::FormPaint(TObject *Sender)
{
int x, y; // siferblatdagi marker koordinatlari
int a; // (х0,уо) (х,у) to’g’ri chiziq va OX
//o’rtasidagi burchak
int h; // soat tahdidi nishoni
TBrushStyle bs; // mo’yqalam stili
TColor pc; // qalam rangi
int pw; // qalam kengligi
bs = Canvas->Brush->Style;
pc = Canvas->Pen->Color;
pw = Canvas->Pen->Width;
Canvas->Brush->Style = bsClear;
Canvas->Pen->Width = 1;
Canvas->Pen->Color = clBlack;
a = 0; // nishonlarni soat ko’rsatkichiga teskari,
// soat 3 dan qo’yamiz
h = 3; // угол 0 градусов - это 3 часа
// siferblat
while (a<360)
{
x = x0 + R * cos(a * TORAD);
y = x0 - R * sin(a * TORAD);
Form1->Canvas->MoveTo(x,y);
if ((a % 30) == 0)
{
Canvas->Ellipse(x-2,y-2,x+3,y+3);
// katta radiusl bo’yicha raqamlar
x = x0 + (R+15) * cos(a * TORAD);
y = x0 - (R+15) * sin(a * TORAD);
Canvas->TextOut(x-5,y-7,IntToStr(h));
h--;
if (h == 0) h = 12;
}
else
Canvas->Ellipse (x-1, y-1, x+1, y+1) ;
a = a + 6; // 1 minut - 6 gradusdan iborat
}
// qalam va mo’yqalamni tiklash
Canvas->Brush->Style = bs;
Canvas->Pen->Width = pw;
Canvas->Pen->Color = pc;
DrawClock();
}
void __fastcall TForm1::DrawClock(void){
TDateTime t;
// sekund va minut ko’rsatkichining qadami 6 gradus,
// soatniki - 30.
// ko’rsatkich tasvirlarini tozalsh
Canvas->Pen->Color = clBtnFace;
Canvas->Pen->Width = 3;
// soatniki
Vector(x0,y0, ahr, R-20);
// minutniki
Vector(x0,y0, amin, R-15);
// sekundniki
Vector(x0,y0, asec, R-7);
t = Now();
// ko’rsatkichning yangi xolati
ahr = 90 - HourOf(t)*30-(MinuteOf(t)% 12)*6;
amin = 90 - MinuteOf(t)*6;
asec = 90 - SecondOf(t)*6;
// ko’rsatlichlarni chizish
// soat ko’rsatkichi
Canvas->Pen->Width = 3;
Canvas->Pen->Color = clBlack;
Vector(x0,y0, ahr, R-20);
// minut ko’rsatkichi
Canvas->Pen->Width = 2 ;
Canvas->Pen->Color = clBlack;
Vector(x0,y0, amin, R-15);
// sekund ko’rsatkichi
Canvas->Pen->Width = 1;
Canvas->Pen->Color = clYellow;
Vector(x0,y0, asec, R-7);
}
//taymerdan signal
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
DrawClock();
}
Do'stlaringiz bilan baham: |