Previously, it picked out two adjacent bits in the result of rand().
Unfortunately, these adjacent bits (at least on NetBSD) have a certain
amount of dependance. After a period (perhaps a thousand or so?), it
starts to repeat the pattern of those two bits. (I think; I haven't
actually tested that directly.) This presumably is locking it into a
an an N-way attractor on the "snowflake", such that if you zoom in a
ways, you will start to see some spots *quickly* are colored, and
others are *never* colored.
What I've done now is to pick up two widely-spaced bits in a single
rand() call. (Perhaps we would do as well to pick up something like
bit #16 from two consecutive rand() calls?) These widely-spaced bits
have a lower statistical dependance on one another (if I can get away
with using that term for an arithmetic operation; though since stats
has more to do with sampling and less to do with true randomness, I
may be safe).
The net effect, at leats on NetBSD, is far better snowflake if you zoom
in on it.
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@324
7f0cb862-5218-0410-a997-
914c9d46530a
for ( i = 0; i < 10; i++ )
{
- int random = (rand() >> 10) % num_trans;
- double new_x = affine[random].a00 * current_x + affine[random].a01 * current_y + affine[random].b0 ;
- double new_y = affine[random].a10 * current_x + affine[random].a11 * current_y + affine[random].b1 ;
-
+ int random = rand( );
+ double new_x;
+ double new_y;
+ random = (((random >> 10)) & 2) + (((random >> 20) ) & 1);
+ new_x = affine[random].a00 * current_x + affine[random].a01 * current_y + affine[random].b0 ;
+ new_y = affine[random].a10 * current_x + affine[random].a11 * current_y + affine[random].b1 ;
+
glVertex2d ( new_x, new_y ) ;
current_x = new_x ;
current_y = new_y ;