/* 图形移动 TXYD.C 程序设计: 谢 春 2000.1.1. */ /* a, b : 背景颜色 a=1--6 画笔颜色 b=14--9 */ /* x, y : 水平移动图形 x=0--310 垂直移动图形 y=0--479 */ /* r1,r2: 水平方向半径 r1=0--150 垂直方向半径 r2=0--200 */ /* 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=13,n,i=4,r1=10,r2=10,v,x,y; float j; /*定义单精度浮点型变量*/ int gdriver=DETECT,gmode; /*定义整型变量gdriver,gmode*/ initgraph(&gdriver,&gmode," "); /*定义变量后,初始化图形系统*/ cleardevice(); setbkcolor(a); /*背景颜色*/ printf("\n"); printf("\n"); printf(" C 语言图形程序设计\n"); setcolor(13); printf(" 图 形 移 动\n"); settextjustify(1,1); /*水平垂直中心对齐*/ outtextxy(130,100,"TU XING YI DONG"); setcolor(10); settextstyle(1,0,6); /*三倍笔画字体,水平,放大倍数*/ outtextxy(140,140,"T X Y D"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf(" 画像素点函数\n"); printf(" putpexel(x,y,color);\n"); printf("\n"); printf(" 绘制图形语句\n"); printf(" 用画像素点图形函数,先画一朵红花 \n"); printf(" putpixel(x,y,color); color=13\n"); printf(" 用背景蓝色,再画一遍擦除红花 \n"); printf(" putpixel(x,y,color); color=1\n"); printf(" 水平垂直方向移动一步级,再画一朵红花\n"); printf(" putpixel(x,y,color); color=13\n"); printf("\n"); printf(" 请选择演示速度(慢1--快99):\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); /*绘制右窗口框*/ scanf("%d",&v); /*画一幅,擦一幅*/ for (n=0;n<1;n++) /*设置循环演示次数*/ { setviewport(323,7,632,472,1); /*设置右窗口*/ /* 只画不擦 移一个花距再画*/ for (x=15;x<=295;x+=25) for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制上边花纹*/ { y=15; putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b); } for (y=45;y<=430;y+=25) for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制右边花纹*/ { x=295; putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b); } for (x=295;x>=15;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=420;y>=40;y+=-25) for (j=0;j<=2*PI;j+=v*PI/9999) /*绘制左边花纹*/ { x=15; putpixel(x-r1*cos(i*j)*cos(j),y-r2*cos(i*j)*sin(j),b); } getch(); /* 只画不擦 移小步再画*/ clearviewport(); /*清除右窗口*/ setviewport(323,7,632,472,1); /*设置右窗口*/ r1=r2=40; for(x=270;x>=60;x-=5) /* 右中到左中 */ { b=13,i=3,y=232; 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); } } getch(); /* 先画后擦 移小步再画 */ clearviewport(); /*清除右窗口*/ setviewport(323,7,632,472,1); /*设置右窗口*/ r1=r2=30; for(x=270;x>=40;x-=5) /* 右中到左中 */ { b=13,i=3,y=232; 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); } b=a; 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=232;y>=40;y-=5) /* 左中到左上 */ { b=10,i=3,x=40; 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); } b=a; 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(x=40;x<=270;x+=5) /* 左上到右上 */ { b=11,i=5,y=40; 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); } b=a; 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=40;y<=425;y+=5) /* 右上到右下 */ { b=12,i=5,x=270; 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); } b=a; 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(x=270;x>=40;x-=5) /* 右下到左下 */ { b=13,i=7,y=425; 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); } b=a; 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=425;y>=232;y-=5) /* 左下到左中 */ { b=2,i=7,x=40; 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); } b=a; 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(x=40;x<=270;x+=5) /* 左中到右中 */ { b=5,i=9,y=232; 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); } b=a; 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); } } getch(); clearviewport(); } /* 只画不擦 移一个花距再画*/ clearviewport(); /*清除右窗口*/ setviewport(323,7,632,472,1); /*设置右窗口*/ r1=r2=30; for(x=220;x>=80;x-=70) /* 右中到左中 */ { b=13,i=3,y=222; 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=170;y>=40;y-=65) /* 左中到左上 */ { b=10,i=3,x=40; 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(x=80;x<=230;x+=70) /* 左上到右上 */ { b=11,i=5,y=40; 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=45;y<=425;y+=70) /* 右上到右下 */ { b=12,i=5,x=270; 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(x=230;x>=80;x-=65) /* 右下到左下 */ { b=13,i=7,y=425; 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=400;y>=270;y-=65) /* 左下到左中 */ { b=2,i=7,x=40; 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); } } getch(); closegraph(); }