POV-Ray : Newsgroups : povray.general : Macros and arrays : Macros and arrays Server Time
7 Aug 2024 17:29:43 EDT (-0400)
  Macros and arrays  
From: Gail Shaw
Date: 13 Aug 2001 08:12:37
Message: <3b77c435@news.povray.org>
I'm busy writing a macro to create piles of objects and I've run into a
rather nasty problem.

Below is a very simplified example of what I'm trying to do

I'd like the code to produce a lot of red spheres, a lot of blue
spheres and a lot of boxes of various shades of gray. What I get
are a lot of blue spheres and a lot of light gray boxes.

I'm guessing (not knowing exactly how macros work) that
when the objects are put into the first array the macros are
executed and the results put in the array. Is there any way inside
pov-ray to have the macros storred in the array and only executed
when the objects are written out?

I could probably do this fairly easily in VB (except for the trace) but
I'd rather do it in Pov.

Thanks
Gail
*************************************************************************
* gsh### [at] monotixcoza                *   Step into the abyss,           *
* http://www.rucus.ru.ac.za/~gail/   *   and let go.          Babylon 5 *
*************************************************************************
* The difficult we do immediately, the impossible takes a little longer *
*************************************************************************

#declare rnd=seed(1328);

#declare Land=height_field{ /* anything here */ }

#macro Object1()
  sphere {0,0.1
  #if (rand(rnd)>0.5)
    pigment {rgb <1,0,0>}
  #else
    pigment {rgb <0,0,1>}
  #end
 }
#end

#macro Object2()
   box {<-0.1,0,-0.1>,<0.1,0.1,0.1> pigment {rgb rand(rnd)}}
#end

#declare ObjectArray=array[2]
#declare ObjectArray[0]=Object1()
#declare ObjectArray[1]=Object2()

#declare LotsOfObjects=array[1000]
#declare i=0;
#declare rnd2=seed(783);
#while (i<1000)
  #if (rand(rnd2)<0.5)
    #declare LotsOfObjects[i]=ObjectArray[0]
  #else
    #declare LotsOfObjects[i]=ObjectArray[1]
  #end
  #declare i=i+1;
#end
#declare i=0;
#declare rnd2=seed(8452);
union {
#while (i<1000)
  declare Pos=<rand(rnd2),100,rand(rnd2)>
  object {LotsOfObjects[i] translate trace(Land,Pos,-y)}
  #declare i=i+1;
#end
}


Post a reply to this message

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