窗口操作6
CKCZ6.C
/* 窗口操作6 CKCZ6.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,b1,h,r1,r2,x=75,y=75;
float f,i,j,j0; /*定义单精度浮点型变量*/
int gdriver=DETECT,gmode; /*定义整型变量gdriver,gmode*/
initgraph(&gdriver,&gmode," "); /*定义变量后,初始化图形系统*/
cleardevice();
setbkcolor(a); /*背景颜色*/
printf("\n");
printf("\n");
printf(" C 语言图形程序设计\n");
printf(" 窗口操作\n");
setcolor(13);
settextjustify(1,1); /*水平垂直中心对齐*/
settextstyle(1,0,2); /*三倍笔画字体,水平,放大倍数*/
outtextxy(160,90,"CHUANG KOU CAO ZUO");
setcolor(10);
settextjustify(1,1); /*水平垂直中心对齐*/
settextstyle(1,0,8); /*三倍笔画字体,水平,放大倍数*/
outtextxy(160,130,"CKCZ");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" 清除窗口函数\n");
printf(" clearviewport( );\n");
printf(" 设置窗口函数\n");
printf(" setviewport(xl,yt,xr,yb,clipflag);\n");
printf(" clipflag为1: 超窗口剪掉\n");
printf(" clipflag为0: 超窗口不剪\n");
printf(" 画像素点函数\n");
printf(" putpexel(x,y,color);\n");
printf(" 设置右边小窗口语句\n");
printf(" setviewport(323,7,477,157,1);\n");
printf(" 绘制图形语句\n");
printf(" putpixel(x-r1*cos(i*j)*cos(j),\n");
printf(" y-r2*cos(i*j)*sin(j),b);\n");
printf(" 按任意键继续 !\n");
setcolor(2);
setlinestyle(0,0,3); /*实线线宽3*/
rectangle(2,2,637,477); /*绘制图纸边框*/
setcolor(3);
setlinestyle(0,0,1); /*实线线宽1*/
rectangle(6,6,318,473); /*绘制0号窗口框*/
rectangle(322,6,478,158); /*绘制1号窗口框*/
rectangle(482,6,633,158); /*绘制2号窗口框*/
rectangle(482,162,633,318); /*绘制3号窗口框*/
rectangle(482,322,633,473); /*绘制4号窗口框*/
rectangle(322,322,478,473); /*绘制5号窗口框*/
rectangle(322,162,478,318); /*绘制6号窗口框*/
getch();
/*画一幅,擦一幅*/
setviewport(323,7,477,157,1); /*设置1号窗口*/
for (j=0;j<=2*PI;j+=PI/999) /*绘制左上单线花朵*/
{
b=10,i=2,r1=60,r2=60;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
getch();
clearviewport();
for (b=2;b<14;b++)
{
clearviewport();
setviewport(483,7,632,157,1); /*设置2号窗口*/
for (j=0;j<=2*PI;j+=PI/99999) /*绘制右上颜色花瓣变化花朵*/
{
i=b,r1=60,r2=60;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
}
getch();
clearviewport();
setviewport(483,163,632,317,1); /*设置3号窗口*/
for (j=0;j<=2*PI;j+=PI/999) /*绘制右中双线花朵*/
{
b=13,b1=10,i=4,r1=50,r2=60;
putpixel(x-r1*cos(i*j)*cos(j),y-r1*cos(i*j)*sin(j),b);
putpixel(x-r2*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b1);
}
getch();
clearviewport();
for (b=2;b<14;b++)
{
clearviewport();
setviewport(483,323,632,472,1); /*设置4号窗口*/
for (r2=20;r2<=60;r2+=1)
for (j=0;j<=2*PI;j+=PI/999) /*绘制右下花朵生长*/
{
i=6,r1=r2;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
}
getch();
clearviewport();
for (x=100;x>50;x--)
{
setviewport(323,323,477,472,1); /*设置5号窗口*/
for (j=0;j<=2*PI;j+=PI/9999) /*绘制右下左移花朵*/
{
b=13,i=5,r1=50,r2=50;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
clearviewport();
}
setviewport(323,323,477,472,1); /*设置5号窗口*/
for (j=0;j<=2*PI;j+=PI/9999) /*绘制右下静止花朵*/
{
b=13,i=5,r1=50,r2=50,x=75;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
getch();
clearviewport();
setviewport(323,163,477,317,1); /*设置6号窗口*/
for (a=1;a<4;a++) /*绘制正弦波*/
for (j=0;j<=2*PI;j+=PI/9999)
{
b=13-a,h=15,x=24*j,y=37*a;
putpixel(x,y-h*sin(2*a*j),b);
}
getch();
clearviewport();
/*只画不擦*/
x=75,y=75;
for (b=1;b<14;b++)
{
clearviewport();
setviewport(323,7,477,157,1); /*设置1号窗口*/
for (r2=20;r2<=60;r2+=1)
for (j=0;j<=2*PI;j+=PI/999) /*绘制左上花朵生长*/
{
b=13,i=6,r1=r2;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
}
setviewport(483,7,632,157,1); /*设置2号窗口*/
for (j=0;j<=2*PI;j+=PI/99999) /*绘制右上单线花朵*/
{
b=13,i=13,r1=60,r2=60;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
setviewport(483,163,632,317,1); /*设置3号窗口*/
setcolor(10);
for (r1=20;r1<=60;r1+=20)
{
h=5;
moveto(x-r1-h,y);
for (j0=0;j0<=360;j0+=5) /*绘制梯形波图形*/
{
j=j0*PI/180;
f=fmod(j0,10);
if(f>0) h=-h;
lineto (x-(r1+h)*cos(j),y-(r1+h)*sin(j));
}
}
getch();
setviewport(483,323,632,472,1); /*设置4号窗口*/
for (j=0;j<=2*PI;j+=PI/9999) /*绘制右下静止花朵*/
{
b=13,i=5,r1=50,r2=50,x=75;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
setviewport(323,323,477,472,1); /*设置5号窗口*/
for (j=0;j<=2*PI;j+=PI/999) /*绘制左下小花朵*/
{
b=12,i=4,r1=50,r2=50;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
for (j=0;j<=2*PI;j+=PI/999) /*绘制左下大花朵*/
{
b=11,i=4,r1=60,r2=60;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
getch();
setviewport(323,163,477,317,1); /*设置6号窗口*/
for (r2=20;r2<=60;r2+=20)
for (j=0;j<=2*PI;j+=PI/999) /*绘制正弦波调整圆图形*/
{
b=13,h=10,i=15,r1=r2;
putpixel(x-(r1+h*sin(i*j))*cos(j),y-(r2+h*sin(i*j))*sin(j),b);
}
getch();
closegraph();
}