画笔颜色

HBYS.C



/* 画笔颜色 HBYS.C 程序设计:谢春 2000.1.1.*/

#include"graphics.h" /*调用图形库函数*/
#include"math.h" /*调用数学函数*/
#include"stdio.h" /*调用标准I/O函数*/
#define PI 3.141596 /*宏定义PI字符串*/

main() /*主函数*/
{
int a=1,b;
float i,x; /*定义单精度浮点型变量*/
int gdriver=DETECT,gmode; /*定义整型变量gdriver,gmode*/
initgraph(&gdriver,&gmode," "); /*定义变量后,初始化图形系统*/

cleardevice();
setbkcolor(a); /*背景颜色*/
printf("\n");
printf("\n");
printf("\n");
printf(" 画笔颜色\n");
printf(" C 语言图形程序设计\n");
printf("\n");
printf(" 画像素点函数\n");
printf(" putpexel(x,y,color);\n");
printf(" 更换画笔颜色(b)绘制图形语句\n");
printf(" for (b=2;b<16;b++)\n");
printf(" for (i=0;i<=2*PI;i+=PI/9999)\n");
printf(" {\n");
printf(" putpixel(155-150*cos(2*i)*cos(i),\n");
printf(" 232-220*cos(2*i)*sin(i),b);\n");
printf(" }\n");
printf("\n");
printf(" 按任意键继续 !\n");
setcolor(3);
setlinestyle(0,0,3); /*实线线宽3*/
rectangle(2,2,637,477); /*绘制图纸边框*/
setcolor(2);
setlinestyle(0,0,1); /*实线线宽1*/
rectangle(6,6,318,473); /*绘制左窗口框*/
rectangle(322,6,633,473); /*绘制右窗口框*/
getch();

/*画一幅,擦一幅*/
for (b=2;b<16;b++) /*设置更换画笔颜色次数*/
{
setviewport(323,7,632,472,1); /*设置右窗口*/
for (i=0;i<=2*PI;i+=PI/9999)
{
putpixel(155-150*cos(2*i)*cos(i),232-220*cos(2*i)*sin(i),b);/*绘制心形曲线*/
}

getch();
clearviewport();
}
closegraph();
}