drawclock.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 49 行

CPP
49
字号
#include <cmath>
#include "canvas.h"
#include "utils.h"



const int RADIUS=50;
const int h=400;
const int w=400;

const int TICK_LENGTH=15;
Canvas c(w,h,10,10);

void DrawTick(const Point& p, double theta, int length)
{
    Point start(p.x+cos(theta)*RADIUS,p.y+sin(theta)*RADIUS);
    Point end(p.x+cos(theta)*(RADIUS-length),p.y+sin(theta)*(RADIUS-length));
    c.DrawLine(start,end);
}

int main()
{
    
   
    Point center(w/2,h/2);
    
    int k;
    const double PI = 3.1415926535897;
    int x, y;
    int limit= 60;
    
    //WaitForReturn();
    
    c.SetColor(LIGHTGREY);
    c.DrawCircle(center,RADIUS+1);
    c.SetColor(BLACK);
    double theta = 0;
    
    for(k=0; k < limit; k++)
    {
       DrawTick(center,theta,k % 5 == 0 ? TICK_LENGTH : TICK_LENGTH/3);
        
       theta += 2*PI/limit;
    }
    
    WaitForReturn();
    
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?