zoukankan      html  css  js  c++  java
  • C 带指针样式的时钟

    #include <stdio.h>
    #include <malloc.h>
    #include<graphics.h>
    #include<conio.h>
    #define LEN sizeof(struct student)
    #include "math.h"
    #define PI 3.1415926

    void Draw(int hour, int minute, int second)
    {
    double a_hour, a_min, a_sec; // 时、分、秒针的弧度值
    int x_hour, y_hour, x_min, y_min, x_sec, y_sec; // 时、分、秒针的末端位置
    // 计算时、分、秒针的弧度值
    a_sec = second * 2 * PI / 60;
    a_min = minute * 2 * PI / 60 + a_sec / 60;
    a_hour= hour * 2 * PI / 12 + a_min / 12;
    // 计算时、分、秒针的末端位置
    x_sec = 320 + (int)(120 * sin(a_sec));
    y_sec = 240 - (int)(120 * cos(a_sec));
    x_min = 320 + (int)(100 * sin(a_min));
    y_min = 240 - (int)(100 * cos(a_min));
    x_hour= 320 + (int)(70 * sin(a_hour));
    y_hour= 240 - (int)(70 * cos(a_hour));
    // 画时针
    setlinestyle(PS_SOLID, NULL,NULL, 10);
    setcolor(WHITE);
    line(320, 240, x_hour, y_hour);
    // 画分针
    setlinestyle(PS_SOLID,1, NULL, 6);
    setcolor(LIGHTGRAY);
    line(320, 240, x_min, y_min);
    // 画秒针
    setlinestyle(PS_SOLID,1, NULL, 2);
    setcolor(RED);
    line(320, 240, x_sec, y_sec);
    }

    void main()
    {

    initgraph(640, 480); // 初始化 640 x 480 的绘图窗口
    // 绘制一个简单的表盘
    //solidcircle(20, 40, 0xff);
    circle(320, 240, 2);
    circle(320, 240, 60);
    circle(320, 240, 160);
    //fillcircle (240, 320, BLUE);
    outtextxy(296, 300, "LAOLISHI");
    // 设置 XOR 绘图模式
    setwritemode(R2_XORPEN); // 设置 XOR 绘图模式
    // 绘制表针
    SYSTEMTIME ti; // 定义变量保存当前时间
    while(!kbhit()) // 按任意键退出钟表程序
    {
    GetLocalTime(&ti); // 获取当前时间
    printf("%d%d%d",ti.wHour, ti.wMinute, ti.wSecond);
    Draw(ti.wHour, ti.wMinute, ti.wSecond); // 画表针
    Sleep(1000); // 延时 1 秒
    printf("%d%d%d",ti.wHour, ti.wMinute, ti.wSecond);
    Draw(ti.wHour, ti.wMinute, ti.wSecond); // 擦表针(擦表针和画表针的过程是一样的)

    }
    closegraph(); // 关闭绘图窗口
    }

  • 相关阅读:
    教育行业漏洞报告平台(Beta)数据爬取分析
    对三国演义人物出现次数统计分析
    用turtle画一个雪人
    python慕课笔记
    浮动的特性
    传统网页布局的三种方式
    CSS盒子阴影
    HTTP协议
    盒子 圆角边框
    Tomcat+Idea项目的发布、war包的导出
  • 原文地址:https://www.cnblogs.com/locean/p/5223104.html
Copyright © 2011-2022 走看看