POV-Ray : Newsgroups : povray.newusers : Decrement the number of objects as loop progresses Server Time
1 Nov 2024 06:17:16 EDT (-0400)
  Decrement the number of objects as loop progresses (Message 1 to 3 of 3)  
From: Haakon Meland Eriksen
Subject: Decrement the number of objects as loop progresses
Date: 12 Aug 2010 17:10:00
Message: <web.4c64625c4047dedb52d43ba0@news.povray.org>
I would like to do something like this

*
**
***
**
*

and decrement the number of objects in one direction as the loops progress. How
can I do this correctly? This does not work.

#declare IndexX = 0;

#while (IndexX <= 9)
        #declare EndZ = 9;
        #declare IndexZ = 0;

        #while (IndexZ <= EndZ)

                sphere {  <IndexX,1,IndexZ>, 0.1   texture {pigment{color Red}}}
        #declare EndZ = EndZ - 1;
        #declare IndexZ = IndexZ + 1;

        #end

#declare IndexX = IndexX + 1;
#end

Cheers,
Haakon


Post a reply to this message

From: Jim Charter
Subject: Re: Decrement the number of objects as loop progresses
Date: 13 Aug 2010 03:27:16
Message: <4c64f3d4@news.povray.org>
Haakon Meland Eriksen wrote:
> I would like to do something like this
> 
> *
> **
> ***
> **
> *
> 
> and decrement the number of objects in one direction as the loops progress. How
> can I do this correctly? This does not work.
> 
> #declare IndexX = 0;
> 
> #while (IndexX <= 9)
>         #declare EndZ = 9;
>         #declare IndexZ = 0;
> 
>         #while (IndexZ <= EndZ)
> 
>                 sphere {  <IndexX,1,IndexZ>, 0.1   texture {pigment{color Red}}}
>         #declare EndZ = EndZ - 1;
>         #declare IndexZ = IndexZ + 1;
> 
>         #end
> 
> #declare IndexX = IndexX + 1;
> #end
> 
> Cheers,
> Haakon
> 
> 
> 
> 
#declare X = -9;
#declare EndZ = -1;

#while (X <= 9)
   #if ( X < 0 )
     #declare EndZ = EndZ + 1;
   #else
     #declare EndZ = EndZ - 1;
   #end

   #declare Z = 0;
   #while (Z <= EndZ)
     sphere {  <X,1,Z>, 0.1   texture {pigment{color x}}}
     #declare Z = Z + 1;
   #end

   #declare X = X + 1;
#end


Post a reply to this message

From: Haakon Meland Eriksen
Subject: Re: Decrement the number of objects as loop progresses
Date: 14 Aug 2010 19:20:00
Message: <web.4c6723f9c9ab8bc5b52d43ba0@news.povray.org>
Jim Charter <jrc### [at] msncom> wrote:
> Haakon Meland Eriksen wrote:
> > I would like to do something like this
> >
> > *
> > **
> > ***
> > **
> > *
> >
> > and decrement the number of objects in one direction as the loops progress. How
> > can I do this correctly? This does not work.
> >
> > #declare IndexX = 0;
> >
> > #while (IndexX <= 9)
> >         #declare EndZ = 9;
> >         #declare IndexZ = 0;
> >
> >         #while (IndexZ <= EndZ)
> >
> >                 sphere {  <IndexX,1,IndexZ>, 0.1   texture {pigment{color Red}}}
> >         #declare EndZ = EndZ - 1;
> >         #declare IndexZ = IndexZ + 1;
> >
> >         #end
> >
> > #declare IndexX = IndexX + 1;
> > #end
> >
> > Cheers,
> > Haakon
> >
> >
> >
> >
> #declare X = -9;
> #declare EndZ = -1;
>
> #while (X <= 9)
>    #if ( X < 0 )
>      #declare EndZ = EndZ + 1;
>    #else
>      #declare EndZ = EndZ - 1;
>    #end
>
>    #declare Z = 0;
>    #while (Z <= EndZ)
>      sphere {  <X,1,Z>, 0.1   texture {pigment{color x}}}
>      #declare Z = Z + 1;
>    #end
>
>    #declare X = X + 1;
> #end

Thanks, Jim!

My mathematician friends Per and Hung suggested something similiar, and Hung
even made me work it out while he had a cup of coffee, and I came up with these


// Number of X increases as Z increases by 1 is 2*1-1=1,2*2-1=3, 2*3-1=5,
2*4-1=7, 2*5-1=9 and so on.
/*
        *****
         ***
          *



*/
#declare IndexZ = 1;

#while (IndexZ <= 5)
        #declare EndX = 2*IndexZ-1;


        #declare IndexX = 1;
        #while (IndexX <= EndX)

                sphere {  <IndexX,0,IndexZ>, 0.1   texture {pigment{color Red}}
                translate <-IndexZ,0,0>
                }

        #declare IndexX = IndexX + 1;

        #end

#declare IndexZ = IndexZ + 1;
#end



sphere {<0,0,0>, 0.1 pigment {color Green}}
sphere {<0,0,5>, 0.1 pigment {color Blue}}

// Number of X decrement when Z increases by 1 is 1 = 9, 2 = 7, 3 = 5, 4 = 3, 5
= 1
/*

        *
       ***
      *****

*/
#declare IndexZ = 1;

#while (IndexZ <= 5)
        #declare EndX = 2*IndexZ-1;

        #declare IndexX = 1;
        #while (IndexX <= EndX)

                sphere {  <IndexX,0,IndexZ>, 0.1   texture {pigment{color Red}}
                translate <-IndexZ,0,-(EndX-1/2)>
                //translate x*10
                }

        #declare IndexX = IndexX + 1;

        #end

#declare IndexZ = IndexZ + 1;
#end

I'll put up a new macro at http://far.no/fram/index.php?title=Tiles hopefully
before Monday.

Cheers,
Haakon


Post a reply to this message

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