home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d571 / gwin.lha / Gwin / Examples / speedy.c < prev    next >
C/C++ Source or Header  |  1991-12-22  |  2KB  |  86 lines

  1. #include "gwin.user.h"
  2. int seed = 0x7f03;
  3. float random();
  4. double ran();
  5. int randseed = 345732;
  6. main()
  7. {
  8. int ix,iy,xold,yold,xanchor,yanchor;
  9.  
  10.    USTART("high2",0.,640.,0.,400.);
  11.  
  12.    upset(G,"colo",1.0);
  13.    uprint(G,10.,90.,"Press left mouse button, hold, drag, release...");
  14.  
  15.    uset(G,"comp");
  16.  
  17.    uset(G,"ncli");
  18.    BNDRYOFF(rport1);   /* BNDRYOFF is important! */
  19.    uuev.key = '\0';
  20.  
  21.    while (1==1){
  22.       while(uuev.key != 'a'){
  23.          if(uigrina(G,&ix,&iy,&uuev)) {UEND();exit(0);}
  24.       }
  25.       RectFill(rport1,ix-10,iy-10,ix,iy);
  26.       xold = ix;
  27.       yold = iy;
  28.  
  29.       while (uuev.key != 'A'){
  30.          if(uigrina(G,&ix,&iy,&uuev)) {UEND();exit(0);}
  31.          randomdraw();
  32.          if(ix != xold || iy != yold){
  33.             RectFill(rport1,xold-10,yold-10,xold,yold);
  34.             RectFill(rport1,ix-10,iy-10,ix,iy);
  35.             xold = ix;
  36.             yold = iy;
  37.          }
  38.       }
  39.    }
  40.    UEND();
  41. }
  42.  
  43. randomdraw()
  44. {
  45. int ix,iy;
  46.  
  47.    ix = 630.0*random(&seed);
  48.    iy = 380.0*random(&seed);
  49.    RectFill(rport1,ix+5,iy+15,ix+7,iy+17);
  50. }
  51.  
  52. /* Note, the Manx "ran()" function appears to provide very             */
  53. /* low precision results that are obvious on the screen.  The          */
  54. /* following random number generator is an improvement and             */
  55. /* sufficient for this demomstration.  You might wish to recompile     */
  56. /* using the "ran()" function instead of the "random()" function       */
  57. /* and observe the unwanted "order" that appears in the distribution.  */
  58.  
  59. float random(ix)
  60.    int *ix;
  61.  
  62. /*     This routine adapted from page 227 of Simulation and  */
  63. /*     Modeling Analysis, Law and Kelton, 1982.              */
  64.  
  65. {
  66.    float rand;
  67.    int xhi,xalo,leftlo,fhi,k;
  68.    int a   = 16807;
  69.    int b15 = 32768;
  70.    int b16 = 65536;
  71.    int p   = 2147483647;
  72.  
  73.    xhi = *ix/b16;
  74.    xalo = (*ix-xhi*b16)*a;
  75.    leftlo = xalo/b16;
  76.    fhi = xhi*a+leftlo;
  77.    k = fhi/b15;
  78.    *ix = (((xalo-leftlo*b16)-p)+(fhi-k*b15)*b16)+k;
  79.    if( *ix < 0 ) *ix = *ix + p;
  80.  
  81.    rand = *ix * 4.656612875e-10;
  82.  
  83.    return(rand);
  84. }
  85.  
  86.