(稻草人) 2022-06-29 08:12 采纳率: 72.7%
浏览 87
已结题

在此基础上将时钟外壳改成一个番茄图案,背景图改这个成上传图案

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

#define High 480 // 游戏画面尺寸
#define Width 640
#define PI 3.14159

int main()
{
initgraph(Width, High); // 初始化 640 x 480 的绘图窗口
int center_x,center_y; // 中心点的坐标,也是表的中心
center_x = Width/2;
center_y = High/2;
int secondLength = Width/5; // 秒针的长度
int minuteLength = Width/6; // 分针的长度
int hourLength = Width/7; // 时针的长度

  int secondEnd_x,secondEnd_y;    // 秒针的终点
  int minuteEnd_x,minuteEnd_y;    // 分针的终点
  int hourEnd_x,hourEnd_y;    // 时针的终点
  float secondAngle;       // 秒钟对应的角度
  float minuteAngle;       // 分钟对应的角度
  float hourAngle;         // 时钟对应的角度
  
  SYSTEMTIME ti;              // 定义变量保存当前时间
  
  BeginBatchDraw();
  while (1)
  {
      // 绘制一个简单的表盘
      setlinestyle(PS_SOLID, 1);
      setcolor(WHITE);
      circle(center_x, center_y, 160);
      setcolor(RGB(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, YELLOW);
      }
      
      outtextxy(center_x + 200, center_y + Width/3, "421450221");
      
      GetLocalTime(&ti);      // 获取当前时间
      // 秒钟角度变化
      secondAngle = ti.wSecond * 2*PI/60;  // 一圈一共2*PI,一圈60秒,一秒钟秒钟走过的角度为2*PI/60
      // 分钟角度变化
      minuteAngle = ti.wMinute * 2*PI/60 + secondAngle/60;  // 一圈一共2*PI,一圈60分,一分钟分钟走过的角度为2*PI/60
      // 时钟角度变化
      hourAngle = ti.wHour * 2*PI/12 + minuteAngle/12;  // 一圈一共2*PI,一圈12小时,一小时时钟走过的角度为2*PI/12     
      // 由角度决定的秒针端点坐标
      secondEnd_x = center_x + secondLength*sin(secondAngle);
      secondEnd_y = center_y - secondLength*cos(secondAngle);
      
      // 由角度决定的分针端点坐标
      minuteEnd_x = center_x + minuteLength*sin(minuteAngle);
      minuteEnd_y = center_y - minuteLength*cos(minuteAngle);
      
      // 由角度决定的时针端点坐标
      hourEnd_x = center_x + hourLength*sin(hourAngle);
      hourEnd_y = center_y - hourLength*cos(hourAngle);       
      
      setlinestyle(PS_SOLID, 2);  
      setcolor(YELLOW);
      line(center_x, center_y, secondEnd_x, secondEnd_y); // 画秒针
      
      setlinestyle(PS_SOLID, 5);  
      setcolor(BLUE);
      line(center_x, center_y, minuteEnd_x, minuteEnd_y); // 画分针
      
      setlinestyle(PS_SOLID, 10);  
      setcolor(BLUE);
      line(center_x, center_y, hourEnd_x, hourEnd_y); // 画时针
      
      FlushBatchDraw();       
      Sleep(10);
      
      setcolor(BLACK);
      setlinestyle(PS_SOLID, 2); 
      line(center_x, center_y, secondEnd_x, secondEnd_y);  // 隐藏前一帧的秒针
      setlinestyle(PS_SOLID, 5);  
      line(center_x, center_y, minuteEnd_x, minuteEnd_y); // 隐藏前一帧的分针
      setlinestyle(PS_SOLID, 10);  
      line(center_x, center_y, hourEnd_x, hourEnd_y); // 隐藏前一帧的时针
  }
  
  EndBatchDraw();
  getch();                // 按任意键继续   
  closegraph();           // 关闭绘图窗口
  return 0;

}

img

  • 写回答

3条回答 默认 最新

  • emXiaoMing 2022-06-29 09:36
    关注

    这个效果可以吗,可以的话我把代码和图片打包发你

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 7月7日
  • 已采纳回答 6月29日
  • 创建了问题 6月29日

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行