
展开全部
c 画的指针式 Roma 表
#include <dos.h>
#include <stdio.h>
#include <math.h>
#include <graphics.h>
void drawhourbrick(int x, int y, int color, float arg);
void drawminutebrick(int x, int y, int color, float arg);
void drawsecondbrick(int x, int y, int color, float arg);
void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle);
int main()
{
int GraphDriver;
int GraphMode;
float arg = 292.5;
float hourarg = 0;
float minuterarg = 0;
float secondrarg = 0;
char buffer[10];
int a, b;
int x, y, r;
int h;
int xmo[12] = {1, 2, -6, -1, -1, -2, -2, -1, 0, -4, -4, -5};
int ymo[12] = {-1, -2, -1, -1, -1, -5, 2, 1, -2, -4, -4, 0};
long delay;
float degree;
struct time time, time1;
GraphDriver = DETECT;
initgraph(&GraphDriver, &GraphMode, "");
x = 300;
y = 220;
r = 200;
degree = atan(1) / 45;
polygon(8, x, y, r, 12, arg, 0);
polygon(8, x, y, r - 2, 11, arg, 0);
polygon(8, x, y, r - 4, 14, arg, 0);
setcolor(12);
/*settextstyle(DEFAULT_FONT, 1, 0);*/
for (a = 0; a < 12; a++)
{
sprintf(buffer, "%d", a + 1);
outtextxy(x + (r - 22) * cos((a - 2) * 30 * degree) + xmo[a], y + (r - 22) * sin((a - 2) * 30 * degree) + ymo[a], buffer);
}
drawhourbrick(x, y, 14, hourarg);
drawminutebrick(x, y, 9, minuterarg);
drawsecondbrick(x, y, 13, secondrarg);
while(1)
{
gettime(&time);
if (time.ti_hour != time1.ti_hour || time.ti_min != time1.ti_min || time.ti_sec != time1.ti_sec)
{
h = time.ti_hour;
if (h > 12)
h -= 12;
drawhourbrick(x, y, 0, hourarg);
drawminutebrick(x, y, 0, minuterarg);
drawsecondbrick(x, y, 0, secondrarg);
hourarg = (h % 12) * 30 + time.ti_min * 0.5 + time.ti_sec * 0.1 / 60;
minuterarg = time.ti_min * 6 + time.ti_sec * 0.1;
secondrarg = time.ti_sec * 6;
setcolor(8);
outtextxy(x - 15, y + 120, "Roma");
drawhourbrick(x, y, 14, hourarg);
drawminutebrick(x, y, 9, minuterarg);
drawsecondbrick(x, y, 13, secondrarg);
time1 = time;
}
while(kbhit())
{
a = getch();
if (a == 27)
{
closegraph();
return 0;
}
}
}
}
void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle)
{
double pi;
int i;
float x1[9], y1[9];
setcolor(color);
pi = atan(1) * 4;
arg = atan(1) / 45 * arg;
x1[1] = x + r * cos(2 * pi / n + arg);
y1[1] = y + r * sin(2 * pi / n + arg);
moveto(x1[1], y1[1]);
for (i = 2; i <= n; i++)
{
x1[i] = x + r * cos(2 * pi * i / n + arg);
y1[i] = y + r * sin(2 * pi * i / n + arg);
lineto(x1[i], y1[i]);
}
lineto(x1[1], y1[1]);
if (fillstyle != 0)
{
setfillstyle(SOLID_FILL, color);
floodfill(x, y, color);
}
}
void drawhourbrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
x1[1] = x + 20 * cos(pi * (arg - 90 - 23));
y1[1] = y + 20 * sin(pi * (arg - 90 - 23));
x1[2] = x + 25 * cos(pi * (arg - 90 + 23));
y1[2] = y + 25 * sin(pi * (arg - 90 + 23));
x1[3] = x + 120 * cos(pi * (arg - 90 + 0));
y1[3] = y + 120 * sin(pi * (arg - 90 + 0));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);
*/
}
void drawminutebrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
x1[1] = x + 20 * cos(pi * (arg - 90 - 23));
y1[1] = y + 20 * sin(pi * (arg - 90 - 23));
x1[2] = x + 25 * cos(pi * (arg - 90 + 23));
y1[2] = y + 25 * sin(pi * (arg - 90 + 23));
x1[3] = x + 160 * cos(pi * (arg - 90 + 0));
y1[3] = y + 160 * sin(pi * (arg - 90 + 0));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);
*/
}
void drawsecondbrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
x1[1] = x + 20 * cos(pi * (arg - 90 - 6));
y1[1] = y + 20 * sin(pi * (arg - 90 - 6));
x1[2] = x + 25 * cos(pi * (arg - 90 + 6));
y1[2] = y + 25 * sin(pi * (arg - 90 + 6));
x1[3] = x + 160 * cos(pi * (arg - 90 + 0));
y1[3] = y + 160 * sin(pi * (arg - 90 + 0));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);
*/
}
#include <dos.h>
#include <stdio.h>
#include <math.h>
#include <graphics.h>
void drawhourbrick(int x, int y, int color, float arg);
void drawminutebrick(int x, int y, int color, float arg);
void drawsecondbrick(int x, int y, int color, float arg);
void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle);
int main()
{
int GraphDriver;
int GraphMode;
float arg = 292.5;
float hourarg = 0;
float minuterarg = 0;
float secondrarg = 0;
char buffer[10];
int a, b;
int x, y, r;
int h;
int xmo[12] = {1, 2, -6, -1, -1, -2, -2, -1, 0, -4, -4, -5};
int ymo[12] = {-1, -2, -1, -1, -1, -5, 2, 1, -2, -4, -4, 0};
long delay;
float degree;
struct time time, time1;
GraphDriver = DETECT;
initgraph(&GraphDriver, &GraphMode, "");
x = 300;
y = 220;
r = 200;
degree = atan(1) / 45;
polygon(8, x, y, r, 12, arg, 0);
polygon(8, x, y, r - 2, 11, arg, 0);
polygon(8, x, y, r - 4, 14, arg, 0);
setcolor(12);
/*settextstyle(DEFAULT_FONT, 1, 0);*/
for (a = 0; a < 12; a++)
{
sprintf(buffer, "%d", a + 1);
outtextxy(x + (r - 22) * cos((a - 2) * 30 * degree) + xmo[a], y + (r - 22) * sin((a - 2) * 30 * degree) + ymo[a], buffer);
}
drawhourbrick(x, y, 14, hourarg);
drawminutebrick(x, y, 9, minuterarg);
drawsecondbrick(x, y, 13, secondrarg);
while(1)
{
gettime(&time);
if (time.ti_hour != time1.ti_hour || time.ti_min != time1.ti_min || time.ti_sec != time1.ti_sec)
{
h = time.ti_hour;
if (h > 12)
h -= 12;
drawhourbrick(x, y, 0, hourarg);
drawminutebrick(x, y, 0, minuterarg);
drawsecondbrick(x, y, 0, secondrarg);
hourarg = (h % 12) * 30 + time.ti_min * 0.5 + time.ti_sec * 0.1 / 60;
minuterarg = time.ti_min * 6 + time.ti_sec * 0.1;
secondrarg = time.ti_sec * 6;
setcolor(8);
outtextxy(x - 15, y + 120, "Roma");
drawhourbrick(x, y, 14, hourarg);
drawminutebrick(x, y, 9, minuterarg);
drawsecondbrick(x, y, 13, secondrarg);
time1 = time;
}
while(kbhit())
{
a = getch();
if (a == 27)
{
closegraph();
return 0;
}
}
}
}
void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle)
{
double pi;
int i;
float x1[9], y1[9];
setcolor(color);
pi = atan(1) * 4;
arg = atan(1) / 45 * arg;
x1[1] = x + r * cos(2 * pi / n + arg);
y1[1] = y + r * sin(2 * pi / n + arg);
moveto(x1[1], y1[1]);
for (i = 2; i <= n; i++)
{
x1[i] = x + r * cos(2 * pi * i / n + arg);
y1[i] = y + r * sin(2 * pi * i / n + arg);
lineto(x1[i], y1[i]);
}
lineto(x1[1], y1[1]);
if (fillstyle != 0)
{
setfillstyle(SOLID_FILL, color);
floodfill(x, y, color);
}
}
void drawhourbrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
x1[1] = x + 20 * cos(pi * (arg - 90 - 23));
y1[1] = y + 20 * sin(pi * (arg - 90 - 23));
x1[2] = x + 25 * cos(pi * (arg - 90 + 23));
y1[2] = y + 25 * sin(pi * (arg - 90 + 23));
x1[3] = x + 120 * cos(pi * (arg - 90 + 0));
y1[3] = y + 120 * sin(pi * (arg - 90 + 0));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);
*/
}
void drawminutebrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
x1[1] = x + 20 * cos(pi * (arg - 90 - 23));
y1[1] = y + 20 * sin(pi * (arg - 90 - 23));
x1[2] = x + 25 * cos(pi * (arg - 90 + 23));
y1[2] = y + 25 * sin(pi * (arg - 90 + 23));
x1[3] = x + 160 * cos(pi * (arg - 90 + 0));
y1[3] = y + 160 * sin(pi * (arg - 90 + 0));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);
*/
}
void drawsecondbrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
x1[1] = x + 20 * cos(pi * (arg - 90 - 6));
y1[1] = y + 20 * sin(pi * (arg - 90 - 6));
x1[2] = x + 25 * cos(pi * (arg - 90 + 6));
y1[2] = y + 25 * sin(pi * (arg - 90 + 6));
x1[3] = x + 160 * cos(pi * (arg - 90 + 0));
y1[3] = y + 160 * sin(pi * (arg - 90 + 0));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0] + x1[3]) / 2, (y1[0] + y1[3]) / 2, color);
*/
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询