POV-Ray : Newsgroups : povray.general : for loops Server Time
5 Aug 2024 16:14:21 EDT (-0400)
  for loops (Message 1 to 7 of 7)  
From: Jose Garcia
Subject: for loops
Date: 10 Sep 2002 17:29:38
Message: <3d7e6442@news.povray.org>
~
does Povray support    for loops   , if so, then how?

I want to create a row of 10 spheres along the x-axis.

Instead of copying the sphere code 10 times, I tried to use a for loop, but
nothing doing.

  #include "colors.inc"


   camera {
    location <0, 0, -10>
    look_at  <0, 0,  0>
  }

  for (int x = 0, x < 10; x++)
{
                      sphere {

    <x, 0, 0>, .5                        // I wanted to draw 10 spheres,
with x starting at 0, going to 10
    texture {
      pigment { color Red }
    }
  }
   }


  light_source { <0, 0, -5> color White}


Is it possible to use a for loop, or is the easiest way to use the brute
force method?

thanks....

out


Post a reply to this message

From: Micha Riser
Subject: Re: for loops
Date: 10 Sep 2002 17:53:39
Message: <3d7e69e3@news.povray.org>
Jose Garcia wrote:

> ~
> does Povray support    for loops   , if so, then how?

the only loop structure is while-loops. but as you maybe know you can 
simulate for-loops with while

#declare i = 0;
#while (i<=10);
>                       sphere {
> 
>     <i, 0, 0>, .5                        // I wanted to draw 10 spheres,
> with x starting at 0, going to 10
>     texture {
>       pigment { color Red }
>     }
>   }
>    }
#declare i = i + 1;
#end

- Micha

-- 
objects.povworld.org - The POV-Ray Objects Collection
book.povworld.org    - The POV-Ray Book Project


Post a reply to this message

From: Kevin Loney
Subject: Re: for loops
Date: 10 Sep 2002 17:57:34
Message: <3d7e6ace@news.povray.org>
try this

#declare x = 0;
#while(x<10)
    sphere {
        <x, 0, 0>, .5
        texture {
            pigment { color Red }
        }
    }
    #declare x=x+1;
#end

--
Kevin
http://www.geocities.com/qsquared_1999/
#macro _(r)#if(r<12)#local i=asc(substr("oqshilacefg",r,1))-97;
disc{<mod(i,7)-3,div(i,7)-1,6>,z,.4pigment{rgb 10}}_(r+1)
#end#end _(1)//KL


Post a reply to this message

From: Peter Hertel
Subject: Re: for loops
Date: 10 Sep 2002 18:02:33
Message: <3d7e6bf9@news.povray.org>
> Is it possible to use a for loop, or is the easiest way to use the brute
> force method?

Hi!
Yes, POV-Ray supports loops

This creates 10 red spheres along the x axis:

camera {
    location <5, 0, -10>
    look_at  <5, 0,  0>
}

#declare Q = 0;
#while (Q < 10)

sphere {<Q,0,0>,.5
    texture {pigment { rgb <1,0,0> }}
}

#declare Q = Q+1;
#end

light_source { <0,0,-5> rgb 1}

Hope that helps!

(Check out the docs [6.2.6.4]  The #while...#end Directive)

-Peter


Post a reply to this message

From: Ken
Subject: Re: for loops
Date: 10 Sep 2002 21:09:49
Message: <3D7E98D2.F60889E2@pacbell.net>
Jose Garcia wrote:
> 
> ~
> does Povray support    for loops   , if so, then how?

Check this out -

http://www.students.tut.fi/~warp/povQandT/whileloops.html

-- 
Ken Tyler


Post a reply to this message

From: Gwen & Emory Stagmer
Subject: Re: for loops
Date: 11 Sep 2002 00:50:47
Message: <3D7ECCCF.ADD397E4@comcast.net>
No, don't actually try that!! x is a pre-defined vector
( <1,0,0> ) and re-defining it would be "a bad thing"...
Here's a variation (just to play around with vectors!):

#declare myvec = x;
#declare endvec = x*10;
#while (myvec <= endvec)
    sphere
	{
	myvec, .5 texture{ pigment { color rgb myvec/10 } }
	}
    #declare myvec = myvec + x;
#end

'because I can'...

    Emory


Kevin Loney wrote:
> 
> try this
> 
> #declare x = 0;
> #while(x<10)
>     sphere {
>         <x, 0, 0>, .5
>         texture {
>             pigment { color Red }
>         }
>     }
>     #declare x=x+1;
> #end
> 
> --
> Kevin
> http://www.geocities.com/qsquared_1999/
> #macro _(r)#if(r<12)#local i=asc(substr("oqshilacefg",r,1))-97;
> disc{<mod(i,7)-3,div(i,7)-1,6>,z,.4pigment{rgb 10}}_(r+1)
> #end#end _(1)//KL


Post a reply to this message

From: Kevin Loney
Subject: Re: for loops
Date: 11 Sep 2002 10:07:41
Message: <3d7f4e2d$1@news.povray.org>
oops, whats was I thinking :-P

thanks for pointing that out

--
Kevin
http://www.geocities.com/qsquared_1999/
#macro _(r)#if(r<12)#local i=asc(substr("oqshilacefg",r,1))-97;
disc{<mod(i,7)-3,div(i,7)-1,6>,z,.4pigment{rgb 10}}_(r+1)
#end#end _(1)//KL


Post a reply to this message

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