|
![](/i/fill.gif) |
Nicolas wrote:
>
> can anybody explain me what is rand and seed ?
>
> Nicolas
Very simply rand will add some random number to an objects definition.
The seed function is used as a way to change where the sequence of the
random generator starts. It can be almost any number you can think of
and in most cases just picking any number is alright.
Examples:
This is a simple sphere with a radius of 1
sphere{<0,0,0>, 1}
Now if I add rand to it like this it will have a random sized
radius -
#declare R = seed ( 123 );
sphere{<0,0,0>, 1*rand (R) }
Another possible use for rand is to add some random translation
to an object. This can be done with the following example -
#declare R = seed ( 456 );
sphere{<rand (R), rand (R), rand (R)>, 1*rand (R) }
In the example above you will have no control over where the sphere
will be located at. every one of its 3D locations will be picked at
random by the computer.
You can also add a randlom value to the pigment of an object
like in this example -
#declare R = seed ( 789 );
sphere{<0,0,0>, 1
pigment{rgb < rand (R), rand (R), rand (R)>
}
}
You may never knwo what color you get this way and it will only
change if you change the seed value.
These are really simple uses for the rand functions. They offer
even more power when used with while loops. This next one will show
you how to make ten spheres, located randomaly in a line, each with a
different size and color -
camera{
location<0, 2,-3>
look_at 0
}
light_source{<0,50,-40>rgb 1}
#declare R = seed ( 789 );
#declare Count = 0;
#while (Count < 10)
sphere{<rand (R) * Count, rand (R), rand (R)* Count>, rand (R) * Count
pigment{rgb < rand (R), rand (R), rand (R)>
}
}
#declare Count = Count = 1;
#end;
There is now way to predict what the spheres will look like and what
size and location they will be at but it should be interesting to see
when it renders. The color for each sphere will also be different when
used in a while loop and you don't have to change the seed value to get
random colors like you did in the single sphere example before.
I hope this helps you understand a little bit anyway.
--
Ken Tyler
mailto://tylereng@pacbell.net
Post a reply to this message
|
![](/i/fill.gif) |