#include #include extern unsigned short errno; extern unsigned short patwhite[]; unsigned short circle[16][32][2] = { {{0x0003,0},{0x0003,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, /* 1 */ {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x0006,0},{0x000f,0},{0x000f,0},{0x0006,0},{0,0},{0,0},{0,0},{0,0},/* 2 */ {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x000c,0},{0x001e,0},{0x003f,0},{0x003f,0}, /* 3 */ {0x001e,0},{0x000c,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x003c,0},{0x007e,0},{0x00ff,0},{0x00ff,0}, /* 4 */ {0x00ff,0},{0x00ff,0},{0x007e,0},{0x003c,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x00fc,0},{0x01fe,0},{0x03ff,0},{0x03ff,0}, /* 5 */ {0x03ff,0},{0x03ff,0},{0x03ff,0},{0x03ff,0}, {0x01fe,0},{0x00fc,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x00f0,0},{0x03fc,0},{0x07fe,0},{0x07fe,0}, /* 6 */ {0x0fff,0},{0x0fff,0},{0x0fff,0},{0x0fff,0}, {0x07fe,0},{0x07fe,0},{0x03fc,0},{0x00f0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x01e0,0},{0x07f8,0},{0x0ffc,0},{0x1ffe,0}, /* 7 */ {0x1ffe,0},{0x3fff,0},{0x3fff,0},{0x3fff,0}, {0x3fff,0},{0x1ffe,0},{0x1ffe,0},{0x0ffc,0}, {0x07f8,0},{0x01e0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x07e0,0},{0x1ff8,0},{0x3ffc,0},{0x7ffe,0}, /* 8 */ {0x7ffe,0},{0xffff,0},{0xffff,0},{0xffff,0}, {0xffff,0},{0xffff,0},{0xffff,0},{0x7ffe,0}, {0x7ffe,0},{0x3ffc,0},{0x1ff8,0},{0x07e0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x0fc0,0},{0x3ff0,0},{0x7ff8,0},{0xfffc,0}, /* 9 */ {0xfffe,0x0001},{0xfffe,0x0001},{0xffff,0x0003},{0xffff,0x0003}, {0xffff,0x0003},{0xffff,0x0003},{0xffff,0x0003},{0xffff,0x0003}, {0xfffe,0x0001},{0xfffe,0x0001},{0xfffc,0},{0x7ff8,0}, {0x3ff0,0},{0x0fc0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x1f80,0},{0x7fe0,0},{0xfff8,0x0001},{0xfffc,0x0003}, /* 10 */ {0xfffc,0x0003},{0xfff3,0x0007},{0xfffe,0x0007},{0xffff,0x000f}, {0xffff,0x000f},{0xffff,0x000f},{0xffff,0x000f},{0xffff,0x000f}, {0xffff,0x000f},{0xfffe,0x0007},{0xfffe,0x0007},{0xfffc,0x0003}, {0xfffc,0x0003},{0xfff8,0x0001},{0x7fe0,0},{0x1f80,0}, {0,0},{0,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x3f00,0},{0xffc0,0},{0xfff0,0x0003},{0xfff8,0x0007}, /* 11 */ {0xfffc,0x000f},{0xfffc,0x000f},{0xfffe,0x001f},{0xfffe,0x001f}, {0xffff,0x003f},{0xffff,0x003f},{0xffff,0x003f},{0xffff,0x003f}, {0xffff,0x003f},{0xffff,0x003f},{0xfffe,0x001f},{0xfffe,0x001f}, {0xfffc,0x000f},{0xfffc,0x000f},{0xfff8,0x0007},{0xfff0,0x0003}, {0xffc0,0},{0x3f00,0},{0,0},{0,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0x7e00,0},{0xff80,0x0001},{0xffe0,0x0007},{0xfff0,0x000f}, /* 12 */ {0xfff8,0x001f},{0xfffc,0x003f},{0xfffc,0x003f},{0xfffe,0x007f}, {0xfffe,0x007f},{0xffff,0x00ff},{0xffff,0x00ff},{0xffff,0x00ff}, {0xffff,0x00ff},{0xffff,0x00ff},{0xffff,0x00ff},{0xfffe,0x007f}, {0xfffe,0x007f},{0xfffc,0x003f},{0xfffc,0x00fc},{0xfff8,0x001f}, {0xfff0,0x000f},{0xffe0,0x0007},{0xff80,0x0001},{0x7e00,0}, {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0xfe00,0x0001},{0xff80,0x0007},{0xffe0,0x001f},{0xfff0,0x003f}, /* 13 */ {0xfff8,0x007e},{0xfffc,0x00ff},{0xfffc,0x00ff},{0xfffe,0x01ff}, {0xfffe,0x01ff},{0xffff,0x03ff},{0xffff,0x03ff},{0xffff,0x03ff}, {0xffff,0x03ff},{0xffff,0x03ff},{0xffff,0x03ff},{0xffff,0x03ff}, {0xffff,0x03ff},{0xfffe,0x01ff},{0xfffe,0x01ff},{0xfffc,0x00ff}, {0xfffc,0x00ff},{0xfff8,0x007f},{0xfff0,0x003f},{0xffe0,0x001f}, {0xff80,0x0007},{0xfe00,0x0001},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}, {{0xfc00,0x0003},{0xff80,0x001f},{0xffe0,0x007f},{0xfff0,0x00ff}, /* 14 */ {0xfff8,0x01ff},{0xfffc,0x03ff},{0xfffc,0x03ff},{0xfffe,0x07ff}, {0xfffe,0x07ff},{0xfffe,0x07ff},{0xffff,0x0fff},{0xffff,0x0fff}, {0xffff,0x0fff},{0xffff,0x0fff},{0xffff,0x0fff},{0xffff,0x0fff}, {0xffff,0x0fff},{0xffff,0x0fff},{0xfffe,0x07ff},{0xfffe,0x07ff}, {0xfffe,0x07ff},{0xfffc,0x03ff},{0xfffc,0x03ff},{0xfff8,0x01ff}, {0xfff0,0x00ff},{0xffe0,0x007f},{0xff80,0x001f},{0xfc00,0x0003}, {0,0},{0,0},{0,0},{0,0}}, {{0xf800,0x0007},{0xff00,0x003f},{0xffc0,0x00ff},{0xffe0,0x01ff}, /* 15 */ {0xfff0,0x03ff},{0xfff8,0x07ff},{0xfffc,0x0fff},{0xfffc,0x0fff}, {0xfffe,0x1fff},{0xfffe,0x1fff},{0xfffe,0x1fff},{0xffff,0x3fff}, {0xffff,0x3fff},{0xffff,0x3fff},{0xffff,0x3fff},{0xffff,0x3fff}, {0xffff,0x3fff},{0xffff,0x3fff},{0xffff,0x3fff},{0xfffe,0x1fff}, {0xfffe,0x1fff},{0xfffe,0x1fff},{0xfffc,0x0fff},{0xfffc,0x0fff}, {0xfff8,0x07ff},{0xfff0,0x03ff},{0xffe0,0x01ff},{0xffc0,0x00ff}, {0xff00,0x003f},{0xf800,0x0007},{0,0},{0,0}}, {{0xf800,0x001f},{0xff00,0x00ff},{0xffc0,0x03ff},{0xffe0,0x07ff}, /* 16 */ {0xfff0,0x0fff},{0xfff8,0x1fff},{0xfffc,0x3fff},{0xfffc,0x3fff}, {0xfffe,0x7fff},{0xfffe,0x7fff},{0xfffe,0x7fff},{0xffff,0xffff}, {0xffff,0xffff},{0xffff,0xffff},{0xffff,0xffff},{0xffff,0xffff}, {0xffff,0xffff},{0xffff,0xffff},{0xffff,0xffff},{0xffff,0xffff}, {0xffff,0xffff},{0xfffe,0x7fff},{0xfffe,0x7fff},{0xfffe,0x7fff}, {0xfffc,0x3fff},{0xfffc,0x3fff},{0xfff8,0x1fff},{0xfff0,0x0fff}, {0xffe0,0x07ff},{0xffc0,0x03ff},{0xff00,0x00ff},{0xf800,0x001f}} }; int starnum = 1; struct star { int num; /* number of star */ int x,y,z; /* spacial coordinates of center */ short xpix,ypix; /* screen coordinates for upper left */ unsigned short pict[32][2]; /* pixels for image */ short imwd,imht; /* size of image */ }; /* size of star = 32 pixels at 10 */ int screenplace(blob,xcen,ycen,radius) struct star *blob; int *xcen,*ycen,*radius; { *radius = (int) (160.0/blob->z); if (*radius <= 0) *radius = 1; *xcen = (int) ((10.0*blob->x)/blob->z); *ycen = (int) ((10.0*blob->y)/blob->z); } int copypict(blob,xcen,ycen,radius) struct star *blob; int xcen,ycen,radius; { int i,j; blob->xpix = xcen - radius + 360; blob->ypix = ycen - radius + 150; for (i=0;i<32;i++) for (j=0;j<2;j++) blob->pict[i][j] = circle[radius-1][i][j]; blob->imwd = 2*radius; blob->imht = 2*radius; } int clippict(blob,xcen,ycen,radius) struct star *blob; int xcen,ycen,radius; { int xshift,yshift; int j; unsigned short wrapbits,mask; copypict(blob,xcen,ycen,radius); if (blob->xpix < 0) { xshift = - blob->xpix; blob->xpix = 0; mask = ~(~0 >> xshift); if (xshift < 16) for (j=0;j<32;j++) { blob->pict[j][0] >>= xshift; wrapbits = blob->pict[1][j] & mask; wrapbits <<= (16 - xshift); blob->pict[j][0] |= wrapbits; blob->pict[j][1] >>= xshift; } else for (j=0;j<32;j++) { blob->pict[j][0] = blob->pict[j][1]; blob->pict[j][0] >>= (xshift-16); } blob->imwd -= xshift; } else if (blob->xpix + blob->imwd >= 720) { xshift = blob->xpix + blob->imwd - 720 +1; blob->imwd -= xshift; } if (blob->ypix < 0) { yshift = - blob->ypix; blob->ypix = 0; for (j=0;j<32-yshift;j++) { blob->pict[j][0] = blob->pict[j+yshift][0]; blob->pict[j][1] = blob->pict[j+yshift][1]; } blob->imht -= yshift; } else if (blob->ypix + blob->imht >= 300) { yshift = blob->ypix + blob->imht - 300 +1; blob->imht -= yshift; } } int movestar(blob) struct star *blob; { int xcen,ycen,radius; blob->z -= 3; screenplace(blob,&xcen,&ycen,&radius); if (xcen+radius<-360 || xcen-radius>=360 || ycen+radius<-150 || ycen-radius>=150) return(1); if (xcen-radius<-360 || xcen+radius>=360 || ycen-radius<-150 || ycen+radius>=150) clippict(blob,xcen,ycen,radius); else copypict(blob,xcen,ycen,radius); return(0); } int displaystar(wn,errwn,blob) int wn,errwn; struct star *blob; { int rc; rc = wrastop(wn,blob->pict,4,0,0,0,0,blob->xpix,blob->ypix, blob->imwd,blob->imht,SRCSRC,DSTOR,0); if (rc == -1) { wprintf(errwn,"display of blob %d failed\n",blob->num); wdelete(wn); kill(getpid(),SIGQUIT); } } int erasestar(wn,errwn,blob) int wn,errwn; struct star *blob; { int rc; rc = wrastop(wn,blob->pict,4,0,0,0,0,blob->xpix,blob->ypix, blob->imwd,blob->imht,SRCSRC,DSTCAM,0); if (rc == -1) { wprintf(errwn,"erase of blob %d failed\n",blob->num); wdelete(wn); kill(getpid(),SIGQUIT); } } int makestar(blob) struct star *blob; { blob->num = starnum; starnum++; blob->x = (rand() % 800)*10 - 4000; blob->y = (rand() % 500)*10 - 2500; blob->z = (rand() % 30)*10 + 10; } int main() { struct star stars[30]; int i,j,k,rc; int wn,wn2; srand(getpid()); winit(); wn = wcreate(1,0,24,80,NBORDER); if (wn == -1) { printf("wcreate failed\n"); wexit(1); } wn2 = wcreate(0,0,25,80,NBORDER); if (wn2 == -1) { printf("second wcreate failed\n"); wdelete(wn); wexit(1); } for (i=0;i<30;i++) { makestar(&stars[i]); while (movestar(&stars[i]) != 0) makestar(&stars[i]); displaystar(wn2,wn,&stars[i]); } for (j=0;j<100;j++) for (i=0;i<30;i++) { erasestar(wn2,wn,&stars[i]); while (movestar(&stars[i]) != 0) makestar(&stars[i]); displaystar(wn2,wn,&stars[i]); } wdelete(wn); wdelete(wn2); wexit(0); }