Subject: | possible cut&paste error in Mandelbrot/mandel.c |
Date: | Wed, 9 Jul 2014 14:18:16 +0000 |
To: | "bug-Imager [...] rt.cpan.org" <bug-Imager [...] rt.cpan.org> |
From: | "Neubauer, Ralf" <ralf.neubauer [...] wido.bv.aok.de> |
Hi,
Mandelbrot/mandel.c contains the lines:
i_color icl[256];
srand(12235);
for(i=1;i<256; i++) {
icl[i].rgb.r = 100+(int) (155.0*rand()/(RAND_MAX+1.0));
icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0));
icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0));
}
icl[0].rgb.r = 0;
icl[0].rgb.g = 0;
icl[0].rgb.g = 0;
The double assignment to rgb.g does not make sense. I assume that should be:
i_color icl[256];
srand(12235);
for(i=1;i<256; i++) {
icl[i].rgb.r = 100+(int) (155.0*rand()/(RAND_MAX+1.0));
icl[i].rgb.g = 100+(int) (155.0*rand()/(RAND_MAX+1.0));
icl[i].rgb.b = 100+(int) (155.0*rand()/(RAND_MAX+1.0));
}
icl[0].rgb.r = 0;
icl[0].rgb.g = 0;
icl[0].rgb.b = 0;
Also to get results in the interval [100, 255] instead of [100, 254] you could assign
100+(int) (156.0*rand()/(RAND_MAX+1.0))
The (int) cast truncates and 155.0 is never reached, because rand()/(RAND_MAX+1.0) < 1.
Ralf