图形程序设计

TXCXSJ12.C


/* 图形程序设计 TXCXSJ12.C 程序设计:谢春 2000.1.1.*/

/* a, b : 背景颜色 a=1--6 画笔颜色 b=13--9 */
/* x, y : 水平移动图形 x=0--639 垂直移动图形 y=0--479 */
/* r1,r2: 水平方向半径 r1=0--320 垂直方向半径 r2=0--240 */
/* i, j : 心形曲线叶片 i=1--24 心形曲线弧度 j=0--2*PI */


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

main() /*主函数*/
{
int a=1,b=10,x=0,y=30,r1=10,r2=10,r3=240,r4=170,i=4,v=3;
float j,k,m; /*定义单精度浮点型变量*/
int gdriver=DETECT,gmode; /*定义整型变量gdriver,gmode*/
initgraph(&gdriver,&gmode," "); /*定义变量后,初始化图形系统*/

cleardevice();
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" C 语言\n");
printf(" 图形程序设计\n");
printf(" 教学演示系统 TCS1.2版\n");

setcolor(10); /*设置画笔浅洋红色*/
outtextxy(220,170,"C-TU XING CHENG XU SHE JI");
setcolor(12);
settextjustify(1,1); /*水平垂直中心对齐*/
settextstyle(1,0,8); /*三倍笔画字体,水平,放大倍数*/
outtextxy(320,240," CTX CXSJ");

printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" 佛山广播电视大学\n");
printf(" 计算机应用 96(09)班 毕业设计\n");
printf(" 指导教师: 谢 春\n");
printf(" 2000.1.1.\n");

setcolor(2); /*设置画笔绿色*/
setlinestyle(0,0,3); /*实线线宽3*/
rectangle(2,2,637,477); /*绘制图纸边框*/
putpixel(320,240,13); /*中心点*/

for (x=30;x<=610;x+=25)
for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制上边花纹*/
{
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

for (y=65;y<=415;y+=25)
for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制右边花纹*/
{
x=610;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

for (x=610;x>=30;x+=-25)
for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制下边花纹*/
{
y=450;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

for (y=415;y>=65;y+=-25)
for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制左边花纹*/
{
x=30;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

for (k=-11*PI/6;k<=-PI/6;k+=PI/26)
for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制 C 字符*/
{
x=320,y=240,b=13;
putpixel(x+r3*cos(k)-r1*cos(i*j)*cos(j),y-r4*sin(k)-r2*cos(i*j)*sin(j),b);
}

setcolor(10); /*设置画笔浅绿色*/
setlinestyle(3,0,1); /* 线线宽1*/
rectangle(250,190,390,290);
for (k=-11*PI/6;k<=-PI/6;k+=PI/16) /*绘制中心 C 字符*/
for (j=0;j<=2*PI;j+=v*PI/9999)
{
x=320,y=240,r1=4,r2=4,r3=50,r4=40,b=14,i=2;
putpixel(x+r3*cos(k)-r1*cos(i*j)*cos(j),y-r4*sin(k)-r2*cos(i*j)*sin(j),b);
}

/*画一个窗口,擦一个窗口*/
setviewport(40,40,130,130,1); /*设置窗口*/
for (j=0;j<=2*PI;j+=v*PI/99999) /*绘制左上单线花朵*/
{
x=45,y=45,r1=40,r2=40,b=13-a,i=2;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

clearviewport();
setviewport(510,40,600,130,1); /*设置窗口*/
for (j=0;j<=2*PI;j+=v*PI/99999) /*绘制右上小花朵*/
{
x=45,y=45,r1=35,r2=35,b=13,i=4;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

for (j=0;j<=2*PI;j+=v*PI/99999) /*绘制右上绿叶*/
{
x=45,y=45,r1=45,r2=45,b=10,i=4;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

clearviewport();
setviewport(510,350,600,440,1); /*设置窗口*/
rectangle(0,0,90,90);
for (r2=20;r2<=40;r2+=1)
for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制右下花朵生长*/
{
x=45,y=45,r1=r2,b=15-a,i=6;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

clearviewport();
setviewport(40,350,130,440,1); /*设置窗口*/
rectangle(0,0,90,90);
for (j=0;j<=2*PI;j+=v*PI/99999) /*绘制左下单线花朵*/
{
x=45,y=45,r1=40,r2=40,b=12,i=8;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}
clearviewport();

/*画四个窗口,全部不擦*/
setbkcolor(a);
setviewport(40,40,130,130,1); /*设置窗口*/
for (j=0;j<=2*PI;j+=v*PI/99999) /*绘制左上单线花朵*/
{
x=45,y=45,r1=40,r2=40,b=10,i=2;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

setviewport(510,40,600,130,1); /*设置窗口*/
for (j=0;j<=2*PI;j+=v*PI/99999) /*绘制右上小花朵*/
{
x=45,y=45,r1=35,r2=35,b=13,i=4;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

for (j=0;j<=2*PI;j+=v*PI/99999) /*绘制右上绿叶*/
{
x=45,y=45,r1=45,r2=45,b=10,i=4;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

setviewport(510,350,600,440,1); /*设置窗口*/
rectangle(0,0,90,90);
for (r2=20;r2<=40;r2+=1)
for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制右下花朵生长*/
{
x=45,y=45,r1=r2,b=11,i=6;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

setviewport(40,350,130,440,1); /*设置窗口*/
rectangle(0,0,90,90);
for (j=0;j<=2*PI;j+=v*PI/99999) /*绘制左下单线花朵*/
{
x=45,y=45,r1=40,r2=40,b=12,i=8;
putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b);
}

getch();
closegraph(); /*关闭图形系统,返回文本模式*/
}