POV-Ray : Newsgroups : povray.general : Macros and arrays : Re: Macros and arrays Server Time
7 Aug 2024 17:27:34 EDT (-0400)
  Re: Macros and arrays  
From: JRG
Date: 13 Aug 2001 08:29:29
Message: <3b77c829@news.povray.org>
> 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?

You guessed well. Why don't you just write as foolows:

#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 LotsOfObjects=array[1000]
 #declare i=0;
 #declare rnd2=seed(783);
 #while (i<1000)
   #if (rand(rnd2)<0.5)
     #declare LotsOfObjects[i]=Object1()
   #else
     #declare LotsOfObjects[i]=Object2()
   #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.