// 正弦波群 ZXBQ.CPP 谢春 2001.1.1. #include "point0.h" //包含自定义point.h函数 #include "point1.h" #include "point2.h" #include "point3.h" //包含自定义point.h函数 #include "point4.h" #include "point5.h" #include "math.h" //包含数学函数 #define PI 3.141596 //宏定义PI符号常量 void main() //主函数 { int gdriver=DETECT,gmode; //定义整型变量gdriver,gmode int b=8,bk=1,c,d,m,n,p,v,w; float i,s=PI/9999,x,xa,y,yh; registerbgidriver(EGAVGA_driver); //登记图形驱动程序(EGAVGA_driver) initgraph(&gdriver,&gmode," "); //定义变量后,初始化图形系统 setbkcolor(bk); cout<<"\n"; cout<<"\n"; cout<<"\n"; cout<<"\n"; cout<<" C++语言 图形程序设计\n"; cout<<"\n"; cout<<" 彩色正弦波群演示\n"; cout<<" 线宽,颜色,位置,波峰数,背景,速度,方向循环变化\n"; cout<<"\n"; cout<<" 佛山职业技术学院\n"; cout<<" 计算机及应用984 课程设计\n"; cout<<" 2001.1.1.\n"; cout<<"\n"; cout<<"\n"; cout<<"\n"; cout<<" 按任意键开始演示\n"; cout<<" 水平正弦波群!\n"; getch(); //按任意键继续 cleardevice(); // 1. 水平正弦波群 // 线宽,颜色,位置,波峰数,背景,速度,方向循环变化 n=-1; for(m=1;m<6;m++) //波峰数m: 1,2,3,4,5 { n+=2; //半波数n: 1,3,5,7,9 v=n*n; //速度v:1,9,25,49,81,121 yh=40; bk=m; //背景颜色bk:1,2,3,4,5 setbkcolor(bk); for(d=1;d<6;d++) //正弦波群段d:1,2,3,4,5,6 { for(p=0;p<6;p++) //point0.h, ...... point5.h { w=1+2*p; //线宽w:1,3,5,7,9,11 c=14-p; //颜色c:14,13,12,11,10,9 yh=yh+w+b; //正弦波位置yh:49,60,73,...... switch(p) { case 0: for(i=0;i<=n*PI;i+=v*s) { x=640/(n*PI)*i; y=yh-25*sin(i); point0 p(x,y,c); //线宽:1,颜色:黄 p.show(); } break; case 1: for(i=n*PI;i>=0;i-=v*s) { x=640/(n*PI)*i; y=yh-25*sin(i); point1 p(x,y,c); //线宽:3,颜色:洋红 p.show(); } break; case 2: for(i=0;i<=n*PI;i+=v*s) //半波数n: 3,5,7,9,11 { x=640/(n*PI)*i; y=yh-25*sin(i); point2 p(x,y,c); //线宽:5,颜色:红 p.show(); } break; case 3: for(i=n*PI;i>=0;i-=v*s) { x=640/(n*PI)*i; y=yh-25*sin(i); point3 p(x,y,c); //线宽:7,颜色:11 p.show(); } break; case 4: for(i=0;i<=n*PI;i+=v*s) //半波数n: 3,5,7,9,11 { x=640/(n*PI)*i; y=yh-25*sin(i); point4 p(x,y,c); //线宽:9,颜色:绿 p.show(); } break; case 5: for(i=n*PI;i>=0;i-=v*s) { x=640/(n*PI)*i; y=yh-25*sin(i); point5 p(x,y,c); //线宽11,颜色:蓝 p.show(); } break; } } } cleardevice(); } // 2. 垂直正弦波群 // 线宽,颜色,位置,波峰数,背景,速度,方向循环变化 cout<<" 按任意键开始演示\n"; cout<<" 垂直正弦波群!\n"; getch(); //按任意键继续 cleardevice(); cout<<" 循环\n"; cout<<" 变化\n"; cout<<"\n"; cout<<" 线宽\n"; cout<<" 颜色\n"; cout<<" 峰数\n"; cout<<" 位置\n"; cout<<" 幅值\n"; cout<<" 背景\n"; cout<<" 速度\n"; cout<<" 方向\n"; n=-1; for(m=1;m<6;m++) //波峰数m: 1,2,3,4,5 { n+=2; //半波数n: 1,3,5,7,9 v=n*n; //速度v:9,25,49,81,121 xa=80; bk=m; //背景颜色bk:1,2,3,4,5 setbkcolor(bk); for(d=1;d<6;d++) //正弦波群段d:1,2,3,4,5,6 { for(p=0;p<6;p++) //point0.h, ...... point5.h { w=1+2*p; //线宽w:1,3,5,7,9,11 c=14-p; //颜色c:14,13,12,11,10,9 xa=xa+w+b; //正弦波位置xa:89,100,113...... switch(p) { case 0: for(i=0;i<=n*PI;i+=v*s) //半波数n: 1,3,5,7,9 { y=480/(n*PI)*i; x=xa-25*sin(i); point0 p(x,y,c); //线宽:1,颜色:黄 p.show(); } break; case 1: for(i=n*PI;i>=0;i-=v*s) { y=480/(n*PI)*i; x=xa-25*sin(i); point1 p(x,y,c); //线宽:3,颜色:洋红 p.show(); } break; case 2: for(i=0;i<=n*PI;i+=v*s) //半波数n: 3,5,7,9,11 { y=480/(n*PI)*i; x=xa-25*sin(i); point2 p(x,y,c); //线宽:5,颜色:红 p.show(); } break; case 3: for(i=n*PI;i>=0;i-=v*s) { y=480/(n*PI)*i; x=xa-25*sin(i); point3 p(x,y,c); //线宽:7,颜色:11 p.show(); } break; case 4: for(i=0;i<=n*PI;i+=v*s) //半波数n: 3,5,7,9,11 { y=480/(n*PI)*i; x=xa-25*sin(i); point4 p(x,y,c); //线宽:9,颜色:绿 p.show(); } break; case 5: for(i=n*PI;i>=0;i-=v*s) { y=480/(n*PI)*i; x=xa-25*sin(i); point5 p(x,y,c); //线宽11,颜色:蓝 p.show(); } break; } } } cleardevice(); } // 3. 水平,垂直正弦波群 // 线宽,颜色,位置,波峰数,背景,速度,方向循环变化 cout<<" 按任意键开始演示\n"; cout<<" 水平,垂直正弦波群!\n"; getch(); //按任意键继续 cleardevice(); n=-1; for(m=1;m<6;m++) //波峰数m: 1,2,3,4,5 { n+=2; //半波数n: 1,3,5,7,9 v=n*n; //速度v:9,25,49,81,121 yh=40; xa=80; bk=m; //背景颜色bk:1,2,3,4,5 setbkcolor(bk); for(d=1;d<6;d++) //正弦波群段d:1,2,3,4,5,6 { for(p=0;p<6;p++) //point0.h, ...... point5.h { w=1+2*p; //线宽w:1,3,5,7,9,11 c=14-p; //颜色c:14,13,12,11,10,9 yh=yh+w+b; //水平正弦波位置yh:49,60,73...... xa=xa+w+b; //垂直正弦波位置xa:89,100,113...... switch(p) { case 0: for(i=0;i<=n*PI;i+=v*s) //半波数n: 1,3,5,7,9 { x=640/(n*PI)*i; //水平正弦波 y=yh-25*sin(i); point0 px(x,y,c); //线宽:1,颜色:黄 px.show(); y=480/(n*PI)*i; //垂直正弦波 x=xa-25*sin(i); point0 py(x,y,c); //线宽:1,颜色:黄 py.show(); } break; case 1: for(i=n*PI;i>=0;i-=v*s) { x=640/(n*PI)*i; //水平正弦波 y=yh-25*sin(i); point1 px(x,y,c); //线宽:3,颜色:洋红 px.show(); y=480/(n*PI)*i; //垂直正弦波 x=xa-25*sin(i); point1 py(x,y,c); //线宽:3,颜色:洋红 py.show(); } break; case 2: for(i=0;i<=n*PI;i+=v*s) //半波数n: 3,5,7,9,11 { x=640/(n*PI)*i; //水平正弦波 y=yh-25*sin(i); point2 px(x,y,c); //线宽:5,颜色:红 px.show(); y=480/(n*PI)*i; //垂直正弦波 x=xa-25*sin(i); point2 py(x,y,c); //线宽:5,颜色:红 py.show(); } break; case 3: for(i=n*PI;i>=0;i-=v*s) { x=640/(n*PI)*i; //水平正弦波 y=yh-25*sin(i); point3 px(x,y,c); //线宽:7,颜色:11 px.show(); y=480/(n*PI)*i; //垂直正弦波 x=xa-25*sin(i); point3 py(x,y,c); //线宽:7,颜色:11 py.show(); } break; case 4: for(i=0;i<=n*PI;i+=v*s) //半波数n: 3,5,7,9,11 { x=640/(n*PI)*i; //水平正弦波 y=yh-25*sin(i); point4 px(x,y,c); //线宽:9,颜色:绿 px.show(); y=480/(n*PI)*i; //垂直正弦波 x=xa-25*sin(i); point4 py(x,y,c); //线宽:9,颜色:绿 py.show(); } break; case 5: for(i=n*PI;i>=0;i-=v*s) { x=640/(n*PI)*i; //水平正弦波 y=yh-25*sin(i); point5 px(x,y,c); //线宽:11,颜色:蓝 px.show(); y=480/(n*PI)*i; //垂直正弦波 x=xa-25*sin(i); point5 py(x,y,c); //线宽:11,颜色:蓝 py.show(); } break; } } } cleardevice(); } cout<<" 按任意键退出演示\n"; cout<<" 正弦波群!\n"; getch(); //按任意键继续 closegraph(); //关闭图形模式返回字符模式 }