|
![](/i/fill.gif) |
Simon Lemieux <lem### [at] yahoo com> wrote:
> I'm currently trying to use rand to determine random location of
> objects in my scene. I would like rand to give the exact same
> result every time it runs.
It will do this on its own, you have to go through special effort to
get it to work differently.
> Here is an example of code that should normally give a cloud of
> dots, brighter if there is more objects with antialiasing:
> #declare n = 100 *2;
> #declare i = 0;
> #declare b = 3;
> #while (i<n)
> sphere { <rand(seed(i)), rand(seed(i+1)), 0>, 0.01 pigment { color rgb 1 }
> finish { ambient 1 } translate <-0.5, -0.5, 0> scale 2}
> #declare i = i+2;
> #end
> But this code give two Very well aligned lines (made of dots...),
> what is the problem?
You are not only seeding the random number generator within the loop,
you are seeding it *for every call*. You need to create one stream and
use it.
(And some general advice, always use at least one capital letter in
variable names, to avoid possible conflict with future features...and
indent!)
#declare N = 100*2;
#declare I = 0;
#declare S = seed(54321);
#while (I<N)
sphere { <rand(S), rand(S), 0>, 0.01
pigment { color rgb 1 }
finish { ambient 1 }
translate <-0.5, -0.5, 0>
scale 2
}
#declare I = I+2;
#end
And of course, this will only make random spheres in a plane, for a 3D
cloud you need to add a third rand(S) to the sphere location vector.
--
Christopher James Huff - chr### [at] mac com
Home Page: http://homepage.mac.com/chrishuff/
POV-Ray TAG e-mail: chr### [at] povray org
POV-Ray TAG web site: http://tag.povray.org/
Post a reply to this message
|
![](/i/fill.gif) |