/*******************************消隐的部分主要是在cube那里面的*************************************/
#include<graphics.h> /*头文件*/ #include<stdio.h> #include<dos.h> #include<math.h> #define PI 3.14159265 /*加入宏定义*/ #define DELTAX 320 #define DELTAY 240 union REGS regs,reg; /*定义寄存器regs、reg*/ int far *buf=0xFFFFF000; void sp();
void RGB(int p,int r,int g,int b) /*RGB调色板程序*/ { p=p%16; if (p>7) p+=48; if (p==6) p=0x14; reg.x.ax=0x1010; /*中断号0x1010*/ reg.x.bx=p; reg.h.ch=g%64; reg.h.cl=b%64; reg.h.dh=r%64; int86(0x10,®,®); /*调用int86软中断*/ }
void magicline() /*变幻线程序*/ { int i,t,r, xx[4]={242,48,328,534}, yy[4]={450,156,48,136}, xx1[4]={246,52,332,538}, /*初始化第一个多点数组*/ yy1[4]={450,156,48,136}, xx2[4]={250,56,336,542}, yy2[4]={450,156,48,136}, xxc[4]={252,568,50,230}, yyc[4]={234,423,254,413}, xxc1[4]={256,572,54,234}, /*初始化第一个参照多点数组*/ yyc1[4]={234,423,254,413}, xxc2[4]={260,576,58,238}, yyc2[4]={234,423,254,413}, dxx[4],dyy[4],dxx1[4],dyy1[4],dxx2[4],dyy2[4], x[4]={40,248,630,134}, y[4]={57,456,248,436}, x1[4]={44,252,634,138}, /*初始化第二个多点数组*/ y1[4]={57,456,248,436}, x2[4]={48,254,638,140}, y2[4]={57,456,248,436}, xc[4]={250,542,52,612}, yc[4]={391,56,424,413}, xc1[4]={254,546,56,616}, /*初始化第二个参照多点数组*/ yc1[4]={391,56,424,413}, xc2[4]={258,550,60,620}, yc2[4]={391,56,424,413}, dx[4],dy[4],dx1[4],dy1[4],dx2[4],dy2[4]; for(i=0;i<4;i++) { dxx[i]=xxc[i]-xx[i]; /*计算第一组的横纵坐标的差值*/ dyy[i]=yyc[i]-yy[i]; dxx1[i]=xxc1[i]-xx1[i]; dyy1[i]=yyc1[i]-yy1[i]; dxx2[i]=xxc2[i]-xx2[i]; dyy2[i]=yyc2[i]-yy2[i]; dx[i]=xc[i]-x[i]; /*计算第二组的横纵坐标的差值*/ dy[i]=yc[i]-y[i]; dx1[i]=xc1[i]-x1[i]; dy1[i]=yc1[i]-y1[i]; dx2[i]=xc2[i]-x2[i]; dy2[i]=yc2[i]-y2[i]; } for(t=0;t<=5000;t++) /*变幻线主循环程序*/ { regs.x.ax=5; regs.x.bx=0; int86(51,®s,®s); r=(regs.x.ax==2)?1:0; /*调用鼠标的5号中断,测试右击*/ if(r) { cleardevice(); sp(); /*若在变幻线执行时右击鼠标,退回初始界面*/ } else { cleardevice(); for(i=0;i<4;i++) { if(y[i]>=480||y[i]<=0) /*计算第一组的第一个点*/ dy[i]=(-1)*dy[i]; if(x[i]>=640||x[i]<=0) dx[i]=(-1)*dx[i]; x[i]=x[i]+dx[i]/190; y[i]=y[i]+dy[i]/190;
if(y1[i]>=480||y1[i]<=0) /*计算第一组的第二个点*/ dy1[i]=(-1)*dy1[i]; if(x1[i]>=640||x1[i]<=0) dx1[i]=(-1)*dx1[i]; x1[i]=x1[i]+dx1[i]/190; y1[i]=y1[i]+dy1[i]/190;
if(y2[i]>=480||y2[i]<=0) /*计算第一组的第三个点*/ dy2[i]=(-1)*dy2[i]; if(x2[i]>=640||x2[i]<=0) dx2[i]=(-1)*dx2[i]; x2[i]=x2[i]+dx2[i]/190; y2[i]=y2[i]+dy2[i]/190;
if(yy[i]>=480||yy[i]<=0) /*计算第二组的第一个点*/ dyy[i]=(-1)*dyy[i]; if(xx[i]>=640||xx[i]<=0) dxx[i]=(-1)*dxx[i]; xx[i]=xx[i]+dxx[i]/140; yy[i]=yy[i]+dyy[i]/140;
if(yy1[i]>=480||yy1[i]<=0) /*计算第二组的第二个点*/ dyy1[i]=(-1)*dyy1[i]; if(xx1[i]>=640||xx1[i]<=0) dxx1[i]=(-1)*dxx1[i]; xx1[i]=xx1[i]+dxx1[i]/140; yy1[i]=yy1[i]+dyy1[i]/140;
if(yy2[i]>=480||yy2[i]<=0) /*计算第二组的第三个点*/ dyy2[i]=(-1)*dyy2[i]; if(xx2[i]>=640||xx2[i]<=0) dxx2[i]=(-1)*dxx2[i]; xx2[i]=xx2[i]+dxx2[i]/140; yy2[i]=yy2[i]+dyy2[i]/140; } setlinestyle(0,0,1); /*设定直线类型*/ for(i=0;i<4;i++) { setcolor(1); /*画第一组线*/ line(x[i],y[i],x[(i+1)%4],y[(i+1)%4]); line(x1[i],y1[i],x1[(i+1)%4],y1[(i+1)%4]); line(x2[i],y2[i],x2[(i+1)%4],y2[(i+1)%4]); setcolor(2); /*画第二组线*/ line(xx[i],yy[i],xx[(i+1)%4],yy[(i+1)%4]); line(xx1[i],yy1[i],xx1[(i+1)%4],yy1[(i+1)%4]); line(xx2[i],yy2[i],xx2[(i+1)%4],yy2[(i+1)%4]); } delay(8000); /*设定延迟时间*/ } } }
rfs(x0,y0,l,a,b) /*五角星程序*/ int x0,y0,l; float a,b; { int i,j,k,n,r,rr,s,z0,z1,z2; int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5; int p[5],q[5],x[5],y[5],X[5],Y[5]; int graphdriver=DETECT,graphmode; initgraph(&graphdriver,&graphmode,""); /*设定所需要的变量*/ x1=x0-l*sin(PI*54/180), y1=y0+l*cos(PI*54/180), x2=x1+l*cos(PI*72/180), y2=y1+l*sin(PI*72/180), x3=x2+l, y3=y2, x4=x0+l*sin(PI*54/180), y4=y1, x5=x0, y5=y0+(l/2)/cos(PI*54/180); /*静止的五角星*/ x[0]=x0,x[1]=x1,x[2]=x2,x[3]=x3,x[4]=x4; y[0]=y0,y[1]=y1,y[2]=y2,y[3]=y3,y[4]=y4; r=x0-x1; s=x0-x2; z0=y5-y0; z1=y5-y1; z2=y2-y5; /*五角星的中心坐标*/
setbkcolor(0); for(n=0;n<=1;n++) /*五角星绕y轴旋转*/ { for(k=0;k<=100;k++) { regs.x.ax=5; regs.x.bx=0; int86(51,®s,®s); rr=(regs.x.ax==2)?1:0; /*若右击则退出*/ if(rr) { cleardevice(); sp(); } else { /*确定下一个点的坐标,只需要横坐标*/ x[1]=x1+2*r*sin(k*PI/200); x[2]=x2+2*s*sin(k*PI/200); x[3]=x3-2*s*sin(k*PI/200); x[4]=x4-2*r*sin(k*PI/200); setlinestyle(0,0,1); setcolor(k%15); /*选择颜色*/ for(i=0;i<=4;i++) for(j=1;j<=4;j++) line(x[i],y[i],x[(i+j)%5],y[(i+j)%5]); /*画五角星*/ setcolor(0); for(i=0;i<=4;i++) line(x[i],y[i],x[(i+1)%5],y[(i+1)%5]); delay(10000); cleardevice(); /*清屏*/ } } }
for(n=0;n<=1;n++) /*五角星绕x轴旋转*/ { for(k=0;k<=100;k++) { regs.x.ax=5; regs.x.bx=0; int86(51,®s,®s); rr=(regs.x.ax==2)?1:0; /*若右击则退出*/ if(rr) { cleardevice(); sp(); } else /*确定下一个点的坐标,只需要纵坐标*/ { y[0]=y0+2*z0*sin(k*PI/100); y[1]=y[4]=y1+2*z1*sin(k*PI/100); y[2]=y[3]=y2-2*z2*sin(k*PI/100); setlinestyle(0,0,1); setcolor(k%15); /*选择颜色*/ for(i=0;i<=4;i++) for(j=1;j<=4;j++) line(x[i],y[i],x[(i+j)%5],y[(i+j)%5]); /*画五角星*/ setcolor(0); for(i=0;i<=4;i++) line(x[i],y[i],x[(i+1)%5],y[(i+1)%5]); delay(15000); cleardevice(); /*清屏*/ } } }
for(n=0;n<=20;n++) /*五角星绕垂直平面的轴旋转*/ { regs.x.ax=5; regs.x.bx=0; int86(51,®s,®s); rr=(regs.x.ax==2)?1:0; if(rr) /*若右击则退出*/ { cleardevice(); sp(); } else { /*确定下一点的坐标*/ for(i=0;i<=4;i++) { x[i]=2*x5-x[i]; y[i]=2*y5-y[i]; } for(k=0;k<=60;k++) /*画五角星*/ { setcolor(k%15); for(i=0;i<=4;i++) for(j=1;j<=4;j++) line(x[i],y[i],x[(i+j)%5],y[(i+j)%5]); setcolor(0); /*清五角星*/ for(j=0;j<=4;j++) { for(i=0;i<=4;i++) line(x[i],y[i],x[(i+1)%5],y[(i+1)%5]); } delay(10); /*设定延时*/ } cleardevice(); } }
p[0]=x0,p[1]=x1,p[2]=x2,p[3]=x3,p[4]=x4; /*五角星的拉伸效果程序*/ q[0]=y0,q[1]=y1,q[2]=y2,q[3]=y3,q[4]=y4; for(n=0;n<=1;n++) { for(k=0;k<=100;k++) /*第一种拉伸效果*/ { regs.x.ax=5; regs.x.bx=0; int86(51,®s,®s); rr=(regs.x.ax==2)?1:0; /*若右击则退出*/ if(rr) { cleardevice(); sp(); } else { for(i=0;i<=4;i++) /*计算下一步的坐标*/ { X[i]=(-a*a*p[i]+a*q[i]-a*b)/(a*a+1); Y[i]=(a*p[i]-q[i]+b)/(a*a+1); x[i]=p[i]+2*X[i]*sin(k*PI/100); y[i]=q[i]+2*Y[i]*sin(k*PI/100); } setcolor(k%15); /*画五角星*/ for(i=0;i<=4;i++) for(j=1;j<=4;j++) line(x[i],y[i],x[(i+j)%5],y[(i+j)%5]); setcolor(0); /*清五角星*/ for(i=0;i<=4;i++) line(x[i],y[i],x[(i+1)%5],y[(i+1)%5]); delay(80000); cleardevice(); /*清屏*/ } } }
for(n=0;n<=1;n++) /*第二种拉伸效果*/ { for(k=0;k<=200;k++) { regs.x.ax=5; regs.x.bx=0; int86(51,®s,®s); rr=(regs.x.ax==2)?1:0; /*若右击则退出*/ if(rr) { cleardevice(); sp(); } else { for(i=0;i<=4;i++) /*计算下一步的坐标*/ { X[i]=(-a*a*p[i]+a*q[i]-a*b)/(a*a+1); Y[i]=(a*p[i]-q[i]+b)/(a*a+1); x[i]=p[i]+2*X[i]*cos(k*PI/100); y[i]=q[i]+2*Y[i]*cos(k*PI/100); } setcolor(k%15); /*画五角星*/ for(i=0;i<=4;i++) for(j=1;j<=4;j++) line(x[i],y[i],x[(i+j)%5],y[(i+j)%5]); setcolor(0); /*清五角星*/ for(i=0;i<=4;i++) line(x[i],y[i],x[(i+1)%5],y[(i+1)%5]); delay(10000); cleardevice(); /*清屏*/ } } }
for(n=0;n<=1;n++) /*第三种拉伸效果*/ { for(k=0;k<=200;k++) { regs.x.ax=5; regs.x.bx=0; int86(51,®s,®s); rr=(regs.x.ax==2)?1:0; /*若右击则退出*/ if(rr) { cleardevice(); sp(); } else { for(i=0;i<=4;i++) /*计算下一步的坐标*/ { X[i]=(-a*a*p[i]+a*q[i]-a*b)/(a*a+1); Y[i]=(a*p[i]-q[i]+b)/(a*a+1); x[i]=p[i]+2*X[i]*cos(k*PI/100); y[i]=q[i]+2*Y[i]*sin(k*PI/100); } setcolor(k%15); /*画五角星*/ for(i=0;i<=4;i++) for(j=1;j<=4;j++) line(x[i],y[i],x[(i+j)%5],y[(i+j)%5]); setcolor(0); /*清五角星*/ for(i=0;i<=4;i++) line(x[i],y[i],x[(i+1)%5],y[(i+1)%5]); delay(10000); cleardevice(); /*清屏*/ } } }
for(n=0;n<=1;n++) /*第四种拉伸效果*/ { for(k=0;k<=200;k++) { regs.x.ax=5; regs.x.bx=0; int86(51,®s,®s); rr=(regs.x.ax==2)?1:0; /*若右击则退出*/ if(rr) { cleardevice(); sp(); } else { for(i=0;i<=4;i++) /*计算下一步的坐标*/ { X[i]=(-a*a*p[i]+a*q[i]-a*b)/(a*a+1); Y[i]=(a*p[i]-q[i]+b)/(a*a+1); x[i]=p[i]+2*X[i]*sin(k*PI/100); y[i]=q[i]+2*Y[i]*cos(k*PI/100); } setcolor(k%15); /*画五角星*/ for(i=0;i<=4;i++) for(j=1;j<=4;j++) line(x[i],y[i],x[(i+j)%5],y[(i+j)%5]); setcolor(0); /*清五角星*/ for(i=0;i<=4;i++) line(x[i],y[i],x[(i+1)%5],y[(i+1)%5]); delay(10000); cleardevice(); /*清屏*/ } } } }
/***************************** 下面继续*****************************/
[此贴子已经被作者于2004-11-13 17:29:56编辑过]