POV-Ray : Newsgroups : povray.newusers : Is there a for operator? Server Time
1 Nov 2024 12:24:19 EDT (-0400)
  Is there a for operator? (Message 1 to 9 of 9)  
From: Mathuin
Subject: Is there a for operator?
Date: 2 Oct 2008 17:40:00
Message: <web.48e53e6c9c501ab1d8a103ef0@news.povray.org>
I have a scene file which has stuff like this:

#macro bigthing(_this, _that, _other)
..... do this big thing
#end // bigthing

#macro blah(_index)
bigthing(ThisArr[_index], ThatArr[_index], OtherArr[_index])
#end // blah

blah(1)
blah(2)
blah(3)
..... and so forth

Is there any way I can condense the multiple blah() calls into something like:

#for _index in 1..10
blah(_index)
#end // for

That would rule.  Thanks!


Post a reply to this message

From: Blue Herring
Subject: Re: Is there a for operator?
Date: 2 Oct 2008 18:05:14
Message: <48e5459a$1@news.povray.org>
Mathuin wrote:
> I have a scene file which has stuff like this:
> 
> #macro bigthing(_this, _that, _other)
> ..... do this big thing
> #end // bigthing
> 
> #macro blah(_index)
> bigthing(ThisArr[_index], ThatArr[_index], OtherArr[_index])
> #end // blah
> 
> blah(1)
> blah(2)
> blah(3)
> ..... and so forth
> 
> Is there any way I can condense the multiple blah() calls into something like:
> 
> #for _index in 1..10
> blah(_index)
> #end // for
> 
> That would rule.  Thanks!

There's no "for" but you can use "while" for the same purpose.  For example:

#declare Count = dimension_size(ThisArr, 1);
#declare Ct = 0;
#while(Ct < Count)
   blah(Ct)
   #declare Ct = Ct + 1;
#end

-- 
// The Mildly Infamous Blue Herring
#version 3.61;#include"functions.inc"global_settings{assumed_gamma
2.2}isosurface{function{-f_strophoid(x/2-.45,y,z*3,1,1.2,1,1.5)-.05}
contained_by{box{<-2.1,-1,-1/3>,<1.4,1,1/3>}}max_gradient 12inverse
hollow pigment{rgbf 1}interior{media{samples 8 emission<3,80,150>/255
density{crackle metric 1color_map{[0rgb 6][.03rgb 0][1rgb 0]}scale<1,
2,1>warp{turbulence<.5,.75,.5>}scale 1/3}}}translate z*3}


Post a reply to this message

From: StephenS
Subject: Re: Is there a for operator?
Date: 2 Oct 2008 18:15:00
Message: <web.48e546aeee785af61852a520@news.povray.org>
"Mathuin" <mat### [at] gmailcom> wrote:
....
> Is there any way I can condense the multiple blah() calls into something like:
>
> #for _index in 1..10
> blah(_index)
> #end // for
Would #switch, #case, #range, help?

Stephen S


Post a reply to this message

From: Mathuin
Subject: Re: Is there a for operator?
Date: 2 Oct 2008 18:35:01
Message: <web.48e54c5cee785afd8a103ef0@news.povray.org>
Blue Herring <pov### [at] bherringcotsenet> wrote:
> Mathuin wrote:
> > I have a scene file which has stuff like this:
> >
> > #macro bigthing(_this, _that, _other)
> > ..... do this big thing
> > #end // bigthing
> >
> > #macro blah(_index)
> > bigthing(ThisArr[_index], ThatArr[_index], OtherArr[_index])
> > #end // blah
> >
> > blah(1)
> > blah(2)
> > blah(3)
> > ..... and so forth
> >
> > Is there any way I can condense the multiple blah() calls into something like:
> >
> > #for _index in 1..10
> > blah(_index)
> > #end // for
> >
> > That would rule.  Thanks!
>
> There's no "for" but you can use "while" for the same purpose.  For example:
>
> #declare Count = dimension_size(ThisArr, 1);
> #declare Ct = 0;
> #while(Ct < Count)
>    blah(Ct)
>    #declare Ct = Ct + 1;
> #end

I should have remembered that from C!  Thanks!

>
> --
> // The Mildly Infamous Blue Herring
> #version 3.61;#include"functions.inc"global_settings{assumed_gamma
> 2.2}isosurface{function{-f_strophoid(x/2-.45,y,z*3,1,1.2,1,1.5)-.05}
> contained_by{box{<-2.1,-1,-1/3>,<1.4,1,1/3>}}max_gradient 12inverse
> hollow pigment{rgbf 1}interior{media{samples 8 emission<3,80,150>/255
> density{crackle metric 1color_map{[0rgb 6][.03rgb 0][1rgb 0]}scale<1,
> 2,1>warp{turbulence<.5,.75,.5>}scale 1/3}}}translate z*3}


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Is there a for operator?
Date: 7 Oct 2008 16:50:57
Message: <48ebcbb1$1@news.povray.org>
> There's no "for" but you can use "while" for the same purpose.  

Although it would be nice to have a for loop as well. I understand
the concept of semantic sugar, but there must be a reason why every 
programming language in popular use has such a construct. And in
SDL in particular I think most loops I've ever seen were actually
counter-based loops (placing objects, subdivide angles, arrays).


Post a reply to this message

From: andrel
Subject: Re: Is there a for operator?
Date: 7 Oct 2008 17:07:04
Message: <48EBCFC7.6090009@hotmail.com>
On 07-Oct-08 22:55, Christian Froeschlin wrote:
> 
>> There's no "for" but you can use "while" for the same purpose.  
> 
> Although it would be nice to have a for loop as well. I understand
> the concept of semantic sugar, but there must be a reason why every 
> programming language in popular use has such a construct. 

And preferably with a counter whose scope is limited to the loop.

Would you like to have arbitrary next item functions or just simply 
numeric increment?

> And in
> SDL in particular I think most loops I've ever seen were actually
> counter-based loops (placing objects, subdivide angles, arrays).


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Is there a for operator?
Date: 8 Oct 2008 15:45:07
Message: <48ed0dc3@news.povray.org>
andrel wrote:

> Would you like to have arbitrary next item functions or just simply 
> numeric increment?

an increment would be just fine


Post a reply to this message

From: Mathuin
Subject: Re: Is there a for operator?
Date: 9 Oct 2008 00:35:00
Message: <web.48ed8874ee785afd8a103ef0@news.povray.org>
andrel <a_l### [at] hotmailcom> wrote:
> Would you like to have arbitrary next item functions or just simply
> numeric increment?

I think arbitrary next-item functions are best.

If this is the example loop:

#declare Count=0;
#while (Count<MaxItems)
  blah(Count)
  #declare Count=Count+1;
#end // while (Count<MaxItems)

This form would be perfectly familiar to all the C users out there:

#for (Count=0; Count<MaxItems; Count=Count+1)
  blah(Count)
#end // for (Count=0; Count<MaxItems; Count=Count+1)

Other languages are different, of course, but C seems to be "common ground".

I don't think assignments, comparisons, or statements can be passed as macro
arguments, but if they could be, something like this would almost work:

#macro for(init, check, inc, body)
#declare init
#while (check)
  body
  #declare inc
#end // macro for

>
> > And in
> > SDL in particular I think most loops I've ever seen were actually
> > counter-based loops (placing objects, subdivide angles, arrays).

That's what I've seen in other source files -- wish I had more experience, but
I'm still the new guy. :-P


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Is there a for operator?
Date: 9 Oct 2008 18:41:52
Message: <48ee88b0@news.povray.org>
Mathuin wrote:

> I don't think assignments, comparisons, or statements can be passed as macro
> arguments, but if they could be, something like this would almost work:
> 
> #macro for(init, check, inc, body)

well, in case somebody loves odd syntactic constructs, here
is a somewhat silly macro for a counter-based loop, although
in this form not nestable for multiple loops:

#macro FROM_TO(FROM,TO)
#local i = FROM;
#while (i < TO)
   FOR(i)
   #declare i = i + 1;
#end
#end

Ponder it for a while and scroll down if confused ;)





...





Scroll some more





...





// Here is how to actually write a loop with it:
#macro FOR(I)
   sphere {<I,0,0>,1 pigment {color rgb 1}}
#end FROM_TO(0,10)





... and what a good thing that macros can be redefined ;)


Post a reply to this message

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