窗口操作1

CKCZ1.C



/* 窗口操作1 CKCZ1.C 程序设计:谢春 2000.1.1.*/

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

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

cleardevice();
setbkcolor(a); /*背景颜色*/
printf("\n");
printf("\n");
printf(" 函数曲线\n");
printf(" C 语言图形程序设计\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,632,472,1);\n");
printf(" 绘制图形语句\n");
printf(" 函数曲线\n");
printf(" 海上灯塔\n");
printf(" putpixel(240-20*cos(i),\n");
printf(" 80-20*sin(i),b);\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 (n=0;n<3;n++) /*设置循环演示次数*/
{
setviewport(323,7,632,472,1); /*设置右窗口*/
for (i=0;i<=2*PI;i+=PI/9999)
{
putpixel(30*i+5,170-22*i*sin(1.6*i),10); /*绘制山峰*/
putpixel(95-25*cos(2*i)*cos(i),160-24*cos(2*i)*sin(i),13);/*绘制花朵*/
putpixel(240-20*cos(i),80-20*sin(i),13); /*绘制太阳*/
}

for (x=35;x<=285;x+=25)
{
for (i=0;i<=PI;i+=PI/9999)
{
putpixel(158-150*cos(i),360-80*sin(i),3); /*绘制桥拱*/
putpixel(x-12*cos(i),360-30*sin(i),3); /*绘制桥孔*/
}
}

setcolor(9);
setlinestyle(3,0,1); /*虚线线宽1*/
for (x=0;x<=60;x+=20)
{
line(x+10,380+x/1.5,305-x,380+x/1.5); /*绘制水面线*/
}

setcolor(13);
for (i=0;i<=2*PI;i+=PI/12) /*绘制阳光线*/
{
line(240+30*cos(i),80-30*sin(i),240+50*cos(i),80-50*sin(i));
}
getch();
clearviewport();

setviewport(323,7,632,472,1); /*设置右窗口*/
for (i=0;i<=19*PI;i+=PI/9999)
{
putpixel(5*i+6,420-5*sin(i),9); /*绘制海面*/
}

setcolor(11);
setlinestyle(0,0,1); /*实线线宽1*/
line(65,415,65,380); /*绘制海上灯塔*/
line(65,380,95,380);
line(95,380,95,415);
line(75,380,80,250);
line(85,380,80,250);
line(80,230,80,195);

setcolor(13);
setlinestyle(3,0,1); /*虚线线宽1*/
fillellipse(80,240,10,10);
for (i=0;i<=2*PI;i+=PI/5) /*绘制灯塔光线*/
{
line(80+20*cos(i),240-20*sin(i),80+70*cos(i),240-70*sin(i));
}

setcolor(15);
setlinestyle(0,0,1); /*实线线宽1*/
line(240,415,240,400); /*绘制轮船*/
line(240,400,270,400);
line(270,400,270,415);
bar(245,390,265,400);
line(255,390,255,350);
line(253,355,258,355);
line(253,365,258,365);
line(250,375,260,375);

arc(240,80,270,450,30); /*绘制月亮*/
ellipse(240,80,270,450,15,30);
getch();
clearviewport();

}
closegraph();
}