POV-Ray : Newsgroups : povray.newusers : Is there a better way of achieving this simple thing : Re: Is there a better way of achieving this simple thing Server Time
29 Jul 2024 00:36:52 EDT (-0400)
  Re: Is there a better way of achieving this simple thing  
From: Tim Attwood
Date: 14 Apr 2007 23:55:12
Message: <4621a220$1@news.povray.org>
> Is there a better way than this of achieving the pyramid of spheres?

I would probably do something like...

#include "handy.inc"

#macro Sphere_Pyramid(Layers, Rad)
   #local S=sphere{<0,0,0>,Rad};
   #local A=Layers;
   #while (A>0)
      GridOf(S,<-A*Rad+Rad,(Layers-A)*1.41*Rad+Rad,-A*Rad+Rad>,
             <0,0,2*Rad>,<2*Rad,0,0>,A,A)
   #local A=A-1;
   #end
#end

union{ Sphere_Pyramid(8,0.25)
   translate <0,-1,0>
   pigment{Silver}
   rotate <0,60,0>
}

Where the #include "handy.inc" has some macros I re-use often.
That way next time I feel like tracing a grid of something I don't
have to re-write the code...

// a grid of object starting at a location and repeating at IncPos and 
IncPos2
#macro GridOf(Obj StartPos IncPos IncPos2 Num Num2)
  #local _COUNT2 = 0;
  #local _CPOS2 = StartPos;
  #while (_COUNT2 < Num2)
    #local _COUNT = 0;
    #local _CPOS = _CPOS2;
    #while (_COUNT < Num)
      object {Obj translate _CPOS}
      #local _CPOS = _CPOS + IncPos;
      #local _COUNT = _COUNT + 1;
    #end
    #local _CPOS2 = _CPOS2 + IncPos2;
    #local _COUNT2 = _COUNT2 + 1;
  #end
#end


Post a reply to this message

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