POV-Ray : Newsgroups : povray.general : random placement of objects : Re: random placement of objects Server Time
5 Nov 2024 03:17:44 EST (-0500)
  Re: random placement of objects  
From: Chris Amshey
Date: 8 Jul 2003 15:50:02
Message: <web.3f0b1fc6206e568c61b99e900@news.povray.org>
netquest wrote:
>Hello,
>
>I'm in the process of creating a number of basic objects using the *declare*

Roughly speaking,

#declare Xcount = -5;
#while (Xcount < 5)
 #declare Zcount = -5;
 #while (Zcount < 5)
   #if(rand(RObjects) > 0.5)
      object { ArrayOfObjects[floor(10*rand(RObjects))] }
   #end
   #declare Zcount = Zcount + MaxSize;
 #end
 #declare Xcount = Xcount + MaxSize;
#end

Of course, over the area you want, and you could use #switch instead of an
array, but basically, iterate over the two axis in steps big enough to avoid
a collision, and choose randomly whether or not to place an object.

For a less grid-like look, you could iterate in steps of twice-maxsize and
place an object at xcount,zcount +/- maxsize, (or combine the two randoms -
randomly place an object or not, randomly placed near the current point).

You get the idea, I hope. Don't forget to seed() your randoms and initialize
your array and so on.

--Chris


Post a reply to this message

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