我做课程设计,要填充图像的颜色,但是他们不能同时显示
先画花 后才填充圆心:
谁能帮我具体的解释一下程序:并着重为什么不能同时显示:
#include "conio.h"
#include "graphics.h"
#include "math.h"
#define pie 3.1415926
#include <dos.h>
void initgr(void)
{ int mode;
int driver= DETECT;
mode = 0;
initgraph(&driver, &mode, "");
}
void tianchongyanse()
{
initgr();
circle(300,220,28);
setfillstyle(1,YELLOW);
floodfill(300,220,WHITE);
getch();
restorecrtmode();
}
void move_circle(int x,int y,int r)
{ int i,j;
for (i=(int)(-r*0.707);i<=(int)(r);i++)
{
j=(int)sqrt(r*r-i*i);
putpixel(x+i,y+j,4);
delay(10000);
putpixel(x+i,y+j,4);
}
for (i=r;i>=-r;i--)
{
j=(int)(sqrt(r*r-i*i));
putpixel(x+i,y-j,RED);
delay(10000);
putpixel(x+i,y-j,RED);
} for(i=r;i>=-r;i--)
{
j=(int)sqrt(r*r-i*i);
putpixel(x-i,y+j,4);
putpixel(x-i,y+j,4); }
}
/*************midcircle***************************/
void bezier_3(int color, double p[64][2])
{
double t,t1,t2,xt,yt;
int j;
int rate=100,x,y;
setcolor(color);
for(j=1;j<9;j++)
{
moveto(p[j*4][0],p[j*4][1]);
for (t=0;t<=1;t+=1.0/rate)
{
yt=1-t;
t1=yt*yt;
t2=3*yt*t;
xt=p[j*4][0]*t1*yt+p[j*4+1][0]*t2*yt+p[j*4+2][0]*t2*t+p[j*4+3][0]*t*t*t;
yt=p[j*4][1]*yt*t1+p[j*4+1][1]*t2*yt+p[j*4+2][1]*t2*t+p[j*4+3][1]*t*t*t;
x=(int)(xt);
y=(int)(yt);
lineto(x,y);
delay(2000);
}
}
}
void bezier_2(int color, double p[4][2])
{
double t,t1,t2,xt,yt;
int j;
int rate=100,x,y;
setcolor(color);
moveto(p[0][0],p[0][1]);
for (t=0;t<=1;t+=1.0/rate)
{
yt=1-t;
t1=yt*yt;
t2=3*yt*t;
xt=p[0][0]*t1*yt+p[1][0]*t2*yt+p[2][0]*t2*t+p[3][0]*t*t*t;
yt=p[0][1]*yt*t1+p[1][1]*t2*yt+p[2][1]*t2*t+p[3][1]*t*t*t;
x=(int)(xt);
y=(int)(yt);
lineto(x,y);
delay(2000);
}}void main(void)
{
static double p[64][2]={200,460, 170,340, 240,280, 280,240,
280,240, 200,320, 159,220, 272,220,
272,220, 159,220, 200,120, 280,200, 280,200, 200,120, 300,79, 300,192,
300,192, 300,79, 400,120, 320,200,
320,200, 400,120, 441,220, 328,220,
328,220, 441,220, 400,320, 320,240,
320,240, 400,320, 300,361, 300,248,
300,248, 300,361, 200,320, 280,240};
const NO=35;
int i;
initgr();
cleardevice();
setcolor(BLUE);
setlinestyle(1,0,1);
moveto(p[0][0],p[0][1]);
for (i=1;i<=NO;i++)
lineto(p[i][0],p[i][1]);
setlinestyle(0,0,1);
bezier_2(GREEN,p);
bezier_3(LIGHTRED,p);
setcolor(RED);
move_circle(300,220,28);
circle(300,220,28);
tianchongyanse();
getch();
closegraph();}
填充圆心和花朵颜色怎么填充???
高手帮帮忙啊 !!!!
先画花 后才填充圆心:
谁能帮我具体的解释一下程序:并着重为什么不能同时显示:
#include "conio.h"
#include "graphics.h"
#include "math.h"
#define pie 3.1415926
#include <dos.h>
void initgr(void)
{ int mode;
int driver= DETECT;
mode = 0;
initgraph(&driver, &mode, "");
}
void tianchongyanse()
{
initgr();
circle(300,220,28);
setfillstyle(1,YELLOW);
floodfill(300,220,WHITE);
getch();
restorecrtmode();
}
void move_circle(int x,int y,int r)
{ int i,j;
for (i=(int)(-r*0.707);i<=(int)(r);i++)
{
j=(int)sqrt(r*r-i*i);
putpixel(x+i,y+j,4);
delay(10000);
putpixel(x+i,y+j,4);
}
for (i=r;i>=-r;i--)
{
j=(int)(sqrt(r*r-i*i));
putpixel(x+i,y-j,RED);
delay(10000);
putpixel(x+i,y-j,RED);
} for(i=r;i>=-r;i--)
{
j=(int)sqrt(r*r-i*i);
putpixel(x-i,y+j,4);
putpixel(x-i,y+j,4); }
}
/*************midcircle***************************/
void bezier_3(int color, double p[64][2])
{
double t,t1,t2,xt,yt;
int j;
int rate=100,x,y;
setcolor(color);
for(j=1;j<9;j++)
{
moveto(p[j*4][0],p[j*4][1]);
for (t=0;t<=1;t+=1.0/rate)
{
yt=1-t;
t1=yt*yt;
t2=3*yt*t;
xt=p[j*4][0]*t1*yt+p[j*4+1][0]*t2*yt+p[j*4+2][0]*t2*t+p[j*4+3][0]*t*t*t;
yt=p[j*4][1]*yt*t1+p[j*4+1][1]*t2*yt+p[j*4+2][1]*t2*t+p[j*4+3][1]*t*t*t;
x=(int)(xt);
y=(int)(yt);
lineto(x,y);
delay(2000);
}
}
}
void bezier_2(int color, double p[4][2])
{
double t,t1,t2,xt,yt;
int j;
int rate=100,x,y;
setcolor(color);
moveto(p[0][0],p[0][1]);
for (t=0;t<=1;t+=1.0/rate)
{
yt=1-t;
t1=yt*yt;
t2=3*yt*t;
xt=p[0][0]*t1*yt+p[1][0]*t2*yt+p[2][0]*t2*t+p[3][0]*t*t*t;
yt=p[0][1]*yt*t1+p[1][1]*t2*yt+p[2][1]*t2*t+p[3][1]*t*t*t;
x=(int)(xt);
y=(int)(yt);
lineto(x,y);
delay(2000);
}}void main(void)
{
static double p[64][2]={200,460, 170,340, 240,280, 280,240,
280,240, 200,320, 159,220, 272,220,
272,220, 159,220, 200,120, 280,200, 280,200, 200,120, 300,79, 300,192,
300,192, 300,79, 400,120, 320,200,
320,200, 400,120, 441,220, 328,220,
328,220, 441,220, 400,320, 320,240,
320,240, 400,320, 300,361, 300,248,
300,248, 300,361, 200,320, 280,240};
const NO=35;
int i;
initgr();
cleardevice();
setcolor(BLUE);
setlinestyle(1,0,1);
moveto(p[0][0],p[0][1]);
for (i=1;i<=NO;i++)
lineto(p[i][0],p[i][1]);
setlinestyle(0,0,1);
bezier_2(GREEN,p);
bezier_3(LIGHTRED,p);
setcolor(RED);
move_circle(300,220,28);
circle(300,220,28);
tianchongyanse();
getch();
closegraph();}
填充圆心和花朵颜色怎么填充???
高手帮帮忙啊 !!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货