Vc6.0不用"graphics.h"函数编写一个程序模拟时钟转动
展开全部
#include "stdlib.h"
#include "time.h"
#include "math.h"
#include "stdio.h"
#include "string.h"
char disBuff[1775];
void initDisBuff()
{
memset(disBuff, ' ', sizeof(disBuff));
for(int i=0; i<24; i++) disBuff[71 * i - 1] = '\n';
disBuff[1775] = 0;
}
#define PI_30 0.10471975511965977461542144610932
void setPixel(int x, int y, char ch)
{
if(0 <= y && y < 25 && 0 <= x && x < 70)
{
disBuff[(24-y) * 71 + x] = ch;
}
}
void SwapInt(int * a, int * b)
{
int c = * a; * a = * b; * b = c;
}
void line(int x1, int y1, int x2, int y2, char ch)
{
int dx,dy,p,const1,const2,x,y,inc;
int steep = (abs(y2 - y1) > abs(x2 - x1)) ? 1 : 0;
if(steep == 1)
{
SwapInt(&x1, &y1);
SwapInt(&x2, &y2);
}
if(x1 > x2)
{
SwapInt(&x1, &x2);
SwapInt(&y1, &y2);
}
dx = abs(x2 - x1);
dy = abs(y2 - y1);
p = 2 * dy - dx;
const1 = 2 * dy;
const2 = 2 * (dy - dx);
x = x1;
y = y1;
inc = (y1 < y2) ? 1 : -1;
while(x <= x2)
{
if(steep == 1)
setPixel(y, x, ch);
else
setPixel(x, y, ch);
x++;
if(p<0)
p += const1;
else
{
p += const2;
y += inc;
}
}
}
void lineA(int x, int y, float s, char ch)
{line(x , y , x + (int)(s * 4), y , ch);}
void lineB(int x, int y, float s, char ch)
{line(x , y , x , y + (int)(s * 2), ch);}
void lineC(int x, int y, float s, char ch)
{line(x + (int)(s * 4), y , x + (int)(s * 4), y + (int)(s * 2), ch);}
void lineD(int x, int y, float s, char ch)
{line(x , y + (int)(s * 2), x + (int)(s * 4), y + (int)(s * 2), ch);}
void lineE(int x, int y, float s, char ch)
{line(x , y + (int)(s * 2), x , y + (int)(s * 4), ch);}
void lineF(int x, int y, float s, char ch)
{line(x + (int)(s * 4), y + (int)(s * 2), x + (int)(s * 4), y + (int)(s * 4), ch);}
void lineG(int x, int y, float s, char ch)
{line(x , y + (int)(s * 4), x + (int)(s * 4), y + (int)(s * 4), ch);}
void drawNum(int x, int y, float s, int num)
{
const int table[16][7] =
{
{1,1,1,0,1,1,1}, {0,0,1,0,0,1,0}, {1,0,1,1,1,0,1}, {1,0,1,1,0,1,1},
{0,1,1,1,0,1,0}, {1,1,0,1,0,1,1}, {1,1,0,1,1,1,1}, {1,1,1,0,0,1,0},
{1,1,1,1,1,1,1}, {1,1,1,1,0,1,1}, {1,1,1,1,1,1,0}, {0,1,0,1,1,1,1},
{1,1,0,0,1,0,1}, {0,0,1,1,1,1,1}, {1,1,0,1,1,0,1}, {1,1,0,1,1,0,0}
};
if(num > 15) return;
if(table[num][0]) lineG(x, y, s, num + '0');
if(table[num][1]) lineE(x, y, s, num + '0');
if(table[num][2]) lineF(x, y, s, num + '0');
if(table[num][3]) lineD(x, y, s, num + '0');
if(table[num][4]) lineB(x, y, s, num + '0');
if(table[num][5]) lineC(x, y, s, num + '0');
if(table[num][6]) lineA(x, y, s, num + '0');
}
void drawZhizhen(int pos, int len, char ch)
{
int x, y;
x = (int)(len * 2.0 * cos(PI_30 * (15 - pos)));
y = (int)(len * 1.0 * sin(PI_30 * (15 - pos)));
line(39, 12, 39 + x, 12 + y, ch);
}
void drawZhizhen(int pos, int len1, int len2, char ch)
{
int x1, y1;
int x2, y2;
x1 = (int)(len1 * 2.0 * cos(PI_30 * (15 - pos)));
y1 = (int)(len1 * 1.0 * sin(PI_30 * (15 - pos)));
x2 = (int)(len2 * 2.0 * cos(PI_30 * (15 - pos)));
y2 = (int)(len2 * 1.0 * sin(PI_30 * (15 - pos)));
line(39+x1, 12+y1, 39 + x2, 12 + y2, ch);
}
void draw(tm * x)
{
int i;
for(i = 0; i< 60; i+=5) drawZhizhen(i, 10, 11, '*');
drawZhizhen(x->tm_hour * 5 + x->tm_min / 12, 5, 'H');
drawZhizhen(x->tm_min, 7, 'm');
drawZhizhen(x->tm_sec, 9, 's');
drawNum(2,2,1,x->tm_sec / 10);
drawNum(9,2,1,x->tm_sec % 10);
drawNum(2,9,1,x->tm_min / 10);
drawNum(9,9,1,x->tm_min % 10);
drawNum(2,16,1,x->tm_hour / 10);
drawNum(9,16,1,x->tm_hour % 10);
}
void display()
{
system("cls");
printf("%s\n", disBuff);
initDisBuff();
}
int main()
{
time_t now = time(NULL);
tm *tm_now = localtime(&now);
clock_t t1 = clock(), t2 = 0;
initDisBuff();
while(1)
{
if(t2 > t1 + 1000)
{
t1 +=1000;
now = time(NULL);
tm_now = localtime(&now);
draw(tm_now);
display();
}
t2 = clock();
}
return 0;
}
追问
虽然纯净Vc++6.0里没指定头文件,但还是辛苦了,谢谢
浙江启扬智能科技有限公司
2022-05-05 广告
2022-05-05 广告
选择arm开发板,可以参考一下几个点:1、确定一种CPU,去了解其核心架构,CPU资源有哪些,一些芯片厂商都会有说明的,可以去它们网站上看看;2、确定要使用什么操作系统,比如Linux啊,安卓这些等等;3、确定开发或者学习要用的哪些接口,比...
点击进入详情页
本回答由浙江启扬智能科技有限公司提供
2015-03-29
展开全部
我草哥 请问VC里面有这个库函数吗?
追问
运行环境是turbo 2.0里面的,就是想问问画个表盘的话能不能用别的方式
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询