home *** CD-ROM | disk | FTP | other *** search
- #include "gwin.user.h"
- int seed = 0x7f03;
- float random();
- double ran();
- int randseed = 345732;
- main()
- {
- int ix,iy,xold,yold,xanchor,yanchor;
-
- USTART("high2",0.,640.,0.,400.);
-
- upset(G,"colo",1.0);
- uprint(G,10.,90.,"Press left mouse button, hold, drag, release...");
-
- uset(G,"comp");
-
- uset(G,"ncli");
- BNDRYOFF(rport1); /* BNDRYOFF is important! */
- uuev.key = '\0';
-
- while (1==1){
- while(uuev.key != 'a'){
- if(uigrina(G,&ix,&iy,&uuev)) {UEND();exit(0);}
- }
- RectFill(rport1,ix-10,iy-10,ix,iy);
- xold = ix;
- yold = iy;
-
- while (uuev.key != 'A'){
- if(uigrina(G,&ix,&iy,&uuev)) {UEND();exit(0);}
- randomdraw();
- if(ix != xold || iy != yold){
- RectFill(rport1,xold-10,yold-10,xold,yold);
- RectFill(rport1,ix-10,iy-10,ix,iy);
- xold = ix;
- yold = iy;
- }
- }
- }
- UEND();
- }
-
- randomdraw()
- {
- int ix,iy;
-
- ix = 630.0*random(&seed);
- iy = 380.0*random(&seed);
- RectFill(rport1,ix+5,iy+15,ix+7,iy+17);
- }
-
- /* Note, the Manx "ran()" function appears to provide very */
- /* low precision results that are obvious on the screen. The */
- /* following random number generator is an improvement and */
- /* sufficient for this demomstration. You might wish to recompile */
- /* using the "ran()" function instead of the "random()" function */
- /* and observe the unwanted "order" that appears in the distribution. */
-
- float random(ix)
- int *ix;
-
- /* This routine adapted from page 227 of Simulation and */
- /* Modeling Analysis, Law and Kelton, 1982. */
-
- {
- float rand;
- int xhi,xalo,leftlo,fhi,k;
- int a = 16807;
- int b15 = 32768;
- int b16 = 65536;
- int p = 2147483647;
-
- xhi = *ix/b16;
- xalo = (*ix-xhi*b16)*a;
- leftlo = xalo/b16;
- fhi = xhi*a+leftlo;
- k = fhi/b15;
- *ix = (((xalo-leftlo*b16)-p)+(fhi-k*b15)*b16)+k;
- if( *ix < 0 ) *ix = *ix + p;
-
- rand = *ix * 4.656612875e-10;
-
- return(rand);
- }
-
-