跟着童晶老师学c语言//时钟

#include<graphics.h>
#include<conio.h>
#include<cmath>

#define High 480
#define Width 640
#define PI 3.1415926 

int main()
{
    initgraph(Width,High);
    int center_x,center_y;
    center_x=Width/2;
    center_y=High/2;
    double second_angle=0;
    double hour_angle=0;
    double minter_angle=0;
    int long_of_second;
    long_of_second=Width/5;
    int long_of_hour;
    long_of_hour=Width/16;
    int long_of_minter;
    long_of_minter=Width/9;
    int second_x,second_y;
    second_x=long_of_second+center_x;
    second_y=long_of_second+center_y;
    int hour_x,hour_y;
    hour_x=long_of_hour+center_x;
    hour_y=long_of_hour+center_y;
    int minter_x,minter_y;
    minter_x=long_of_minter+center_x;
    minter_y=long_of_minter+center_y;

    SYSTEMTIME ti;    //当前秒钟 
     
    BeginBatchDraw();
    while(1)
    {
        // 绘制一个简单的表盘
        setlinestyle(PS_SOLID, 1);
        setcolor(WHITE);
        circle(center_x, center_y, Width/4);
        
        // 画刻度
        int x, y,i;
        for (i=0; i<60; i++)
        {
            x = center_x + int(Width/4.3 * sin(PI * 2 * i / 60));
            y = center_y + int(Width/4.3 * cos(PI * 2 * i / 60));
            
            if (i % 15 == 0)
                bar(x - 5, y - 5, x + 5, y + 5);
            else if (i % 5 == 0)
                circle(x, y, 3);
            else
                putpixel(x, y, WHITE);
        }
        
        outtextxy(center_x - 25, center_y + Width/6, "我的时钟");
        
        
    GetLocalTime(&ti);
    second_angle=ti.wSecond*2*PI/60;
    minter_angle=ti.wMinute*2*PI/60;
    hour_angle=ti.wHour*2*PI/12;
    setlinestyle(PS_SOLID,1);
    setcolor(WHITE);
    second_x=center_x+long_of_second*sin(second_angle);
    second_y=center_y-long_of_second*cos(second_angle);
    minter_x=center_x+long_of_minter*sin(minter_angle);
    minter_y=center_y-long_of_minter*cos(minter_angle);
    hour_x=center_x+long_of_hour*sin(hour_angle);
    hour_y=center_y-long_of_hour*cos(hour_angle);
    
    line(center_x,center_y,
    second_x,second_y);
    setcolor(YELLOW);
    setlinestyle(PS_SOLID,2);
    line(center_x,center_y,
    minter_x,minter_y);
    setcolor(GREEN);
    setlinestyle(PS_SOLID,4);
    line(center_x,center_y,
    hour_x,hour_y);
    
//    Sleep(500);
    
    FlushBatchDraw();
    
    setcolor(BLACK);
    line(center_x,center_y,
    second_x,second_y);
    line(center_x,center_y,
    minter_x,minter_y);
    line(center_x,center_y,
    hour_x,hour_y);
    
    }
    
    
    EndBatchDraw();
    getch();
    closegraph();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值