POV-Ray : Newsgroups : povray.advanced-users : Is there a way : Re: Is there a way Server Time
29 Jul 2024 22:27:04 EDT (-0400)
  Re: Is there a way  
From: Tor Olav Kristensen
Date: 17 Sep 2000 19:20:55
Message: <39C5507E.4941A62E@hotmail.com>
Mick Hazelgrove wrote:
> 
> I want to translate an object. I often come across the situation where I
> want to randomly add a increment to a translation either side of zero. ie
> translate x* (+or - increment) usually in a loop.
> 
> I've used mod to alternate either side of zero but I'd like it to be random.

There are many solutions to this problem.
Below you can find two of my suggestions.


If you have prepared your randomization seed 
e.g. like this:

#declare RR = seed(314);


Then to get what you wrote in the first post;

x (+ or -) y

you could write:


x + (2*int(rand(RR) + 0.5) - 1)*y

or 

x + (rand(RR) > 0.5 ? 1 : -1)*y



To get what you wrote in your second post;

x* (+or - increment)

you could write:


x*(2*int(rand(RR) + 0.5) - 1)*increment

or

x*(rand(RR) > 0.5 ? 1 : -1)*increment



Tor Olav
--
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.