热门文章:当Borland已成往事:献给曾经的Borland 编程盗2005版QQ源码 在中秋之际,写上一段爱情宣言程序,聊表爱意。 #include "stdio.h" #include "graphics.h" #include "time.h" #include "math.h" #define N 2 #define TIME 0.8/*微粒的的运动时间,TIME/步,每一步长为25个单位*/ void *buf[N]; struct { int x,y;
} lizi[]={{0,0},{75,75}};
void alter_place_lizi(int *x,int *y,int key)/*根据随机方向改变粒子的方位*/ {
switch(key) {case 0: case 1: case 2:*x-=25;break; case 4: case 5: case 6:*x+=25;break; } switch(key) { case 0: case 7: case 6:*y-=25;break; case 2: case 3: case 4:*y+=25;break; } if(*x<0) *x=0; if(*x>250) *x=250; if(*y<0) *y=0; if(*y>250) *y=250; }
void make_graphics()/*画方框*/ {int i,j,driver=VGA,mode=VGAHI; initgraph(&driver,&mode,""); setbkcolor(YELLOW); cleardevice(); setcolor(LIGHTRED); setlinestyle(0,0,1); for(i=0;i<=10;i++) line(0,25*i,250,25*i); for(i=0;i<=10;i++) line(25*i,0,25*i,250); }
void make_circle(int x,int y,int n)/*根据提供的离子所在方位画圆*/ { int size; setcolor(LIGHTRED); setlinestyle(0,0,1); setfillstyle(1,10); circle(x+25/2,y+25/2,25/2); floodfill(x+25/2,y+25/2,12); size=imagesize(x,y,x+25,y+25); buf[n]=(void *)malloc(size);/*保存每一个圆*/ }
void sport(int *x,int *y)/*粒子的运动*/ { time_t starttime,endtime; int seed=0,i,j; int key; char s[300]; int t=1; srand(seed);
/*保存现场图形*/ for(i=0;i getimage(x[i],y[i],x[i]+25,y[i]+25,buf[i]); cleardevice();/*清除*/ setbkcolor(BLUE); cleardevice(); setviewport(50, 50, 590, 430, 1); /*定义一个图形窗口*/ setfillstyle(1, 2); /*绿色以实填充*/ setcolor(YELLOW); rectangle(0, 0,590, 230); floodfill(50, 50, 14); setcolor(12); settextstyle(1, 0, 8); /*三重笔划字体, 水平放大8倍*/ outtextxy(20, 20, "I miss you"); setcolor(11); settextstyle(1, 0, 4); /*三重笔划字体, 水平放大4倍*/ outtextxy(100, 100, "where are you"); time(&starttime); time(&endtime); for(;difftime(endtime,starttime)<=2.0;time(&endtime)); setbkcolor(YELLOW); cleardevice(); setcolor(LIGHTRED); setlinestyle(0,0,1); while(t) { if(fabs(x[0]-x[1])==25&&fabs(y[0]-y[1])==25) {for(i=0;i {key=rand()%8; alter_place_lizi(&x[i],&y[i],key); } }
else if(fabs(x[0]-x[1])==25||fabs(y[0]-y[1])==25) {key=rand()%8; for(i=0;i alter_place_lizi(&x[i],&y[i],key);t++; } else {for(i=0;i {key=rand()%8; alter_place_lizi(&x[i],&y[i],key); } }
for(i=0;i putimage(x[i],y[i],buf[i],COPY_PUT);
/*界面维持0.5秒钟*/ time(&starttime); time(&endtime); for(;difftime(endtime,starttime)<=TIME;time(&endtime));
for(i=0;i getimage(x[i],y[i],x[i]+25,y[i]+25,buf[i]); cleardevice(); switch(t) {case 1:setcolor(t); settextstyle(1, 0, 2); /*三重笔划字体, 水平放大4倍*/ outtextxy(t, t, "I am tired to look after you"); delay(1e10); break;
case 2:setcolor(t); settextstyle(1, 0, 2); /*三重笔划字体, 水平放大4倍*/ outtextxy(t, t, "could you wait for me please?");delay(1e10); break; case 3:setcolor(t); settextstyle(1, 0, 2); /*三重笔划字体, 水平放大4倍*/ outtextxy(t, t, "I can not catch up with you");delay(1e10); break; case 4:setcolor(t); settextstyle(1, 0, 2); /*三重笔划字体, 水平放大4倍*/ outtextxy(t, t, "you walk so quckily");delay(1e10); break; case 5:setcolor(t); settextstyle(1, 0, 2); /*三重笔划字体, 水平放大4倍*/ outtextxy(t, t, "I will not give up and I believe I can keep up with you one day");delay(1e10); break; case 6:setcolor(t); settextstyle(1, 0, 2); /*三重笔划字体, 水平放大4倍*/ outtextxy(t, t, "I can not help stoping as result of your beauty");delay(1e10); break; default:setcolor(t); settextstyle(1, 0, 5); /*三重笔划字体, 水平放大4倍*/ outtextxy(t-3, t-3, "I will go with you forever"); }
}
} main() {time_t starttime,endtime; int i,j; int x[N],y[N],t[N]; make_graphics();
for(i=0;i make_circle(lizi[i].x,lizi[i].y,i); time(&starttime); time(&endtime); for(;difftime(endtime,starttime)<=1.0;time(&endtime)); for(i=0;i{x[i]=lizi[i].x; y[i]=lizi[i].y;
}
sport(x,y); }
|