C语言画直线和填充的程序,要有算法的

简单短小没关系,要能运行,但不能直接调用函数的,要用自己的算法……... 简单短小没关系,要能运行,但不能直接调用函数的,要用自己的算法…… 展开
 我来答
兴谆炊o
2009-06-17 · TA获得超过6985个赞
知道大有可为答主
回答量:2388
采纳率:0%
帮助的人:3728万
展开全部
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);
*/
}
张泣露
2009-06-18 · TA获得超过149个赞
知道答主
回答量:166
采纳率:0%
帮助的人:0
展开全部
line(x1,y1,x2,y2);
setfillstyle(a,b)
floodfill(a,b)
你看书就会了啊 就那几个函数啊 ,加油啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式