[原创]变幻的四面体
win-tc下编译通过程序代码:
#include <Conio.h> #include <graphics.h> #include <stdlib.h> #define closegr closegraph #define NDOT 4 typedef struct { int a,b,x,y,tx,ty; } DotInf; void initgr(void) /* BGI初始化 */ { int gd = DETECT, gm = 0; registerbgidriver(EGAVGA_driver); initgraph(&gd, &gm, ""); } void delta(DotInf dot[],int c) { int i,j; setcolor(c); if (c==0) { for (i=0;i<NDOT;i++) for (j=i+1;j<NDOT;j++) line(dot[i].tx,dot[i].ty,dot[j].tx,dot[j].ty); } else { for (i=0;i<NDOT;i++) for (j=i+1;j<NDOT;j++) line(dot[i].x,dot[i].y,dot[j].x,dot[j].y); } } int main(void) { int i,j,whi=0; DotInf snk[NDOT]; initgr(); /* BGI初始化 */ for (i=0;i<NDOT;i++) { snk[i].a=snk[i].b=snk[i].x=snk[i].y=200; } randomize(); while (!kbhit()) { if (whi<NDOT) whi++; else whi=0; for (i=0;i<350;i++) delay(10); delta(snk,0); delta(snk,2); for (i=0;i<NDOT;i++){ if ((snk[i].x==snk[i].a)&&(snk[i].y==snk[i].b)){ snk[i].a=rand()%600+1; snk[i].b=rand()%400+20; } } for (i=0;i<NDOT;i++){ snk[i].tx=snk[i].x; snk[i].ty=snk[i].y; if (whi>i) continue; if (snk[i].x>snk[i].a) snk[i].x--; else if (snk[i].x<snk[i].a) snk[i].x++; else { if (snk[i].y>snk[i].b) snk[i].y--; else if (snk[i].y<snk[i].b) snk[i].y++; } } } getch(); closegr(); /* 恢复TEXT屏幕模式 */ return 0; }
[[it] 本帖最后由 if_exist 于 2009-7-25 09:30 编辑 [/it]]