POV-Ray : Newsgroups : povray.advanced-users : #while loop help Server Time
1 Nov 2024 23:17:05 EDT (-0400)
  #while loop help (Message 1 to 10 of 14)  
Goto Latest 10 Messages Next 4 Messages >>>
From: Todd Taylor
Subject: #while loop help
Date: 1 Sep 2000 18:04:46
Message: <39b027fe$1@news.povray.org>
Hello all...:)

I am hoping this is the proper newsgroup (my first post,
at that.

I need a #while loop that places an object in a 2d grid
with say 5 objects in a row and 5 objects per column.

X  X  X  X  X
X  X  X  X  X
X  X  X  X  X
X  X  X  X  X
X  X  X  X  X

Essentially, I am placing a copy of an object 25 times
in a 5x5 grid.  However, the code below does not work:

For the keen ones amongst you, I am trying to create a
hexagonally tiled floor with the hexagons rounded at the
edges and a small amount of grout between each
hexagon.

David Fontaine has helped me greatly in getting me to
this point, but getting the hexagons to tile correctly has
been a major headache.  I suspect my "understanding"
of the #while - #end loops is not fully correct, although
I don't know where I am going wrong looking at code
and the help docs. :)

Any help is greatly appreciated. :)

Thanks!
Todd
tta### [at] netrelatedcom

#include "colors.inc"

camera {
        location <0,10,0.05>
        look_at <0,0,0>
        rotate <0,0,0>}

light_source { <4,4,-6> color rgb <1,1,1>}

#declare Tile = union {
  union{
   intersection {
      cylinder { <-.5,0,sqrt(3)/2>,<.5,0,sqrt(3)/2>,.1 }
      plane { x,0 rotate 30.01*y }
      plane { -x,0 rotate -30.01*y }
   }
   sphere{<.5,0,sqrt(3)/2>,.1}
  }
  union{
   intersection {
      cylinder { <-.5,0,sqrt(3)/2>,<.5,0,sqrt(3)/2>,.1 }
      plane { x,0 rotate 30.01*y }
      plane { -x,0 rotate -30.01*y }
      rotate 60*y
   }
   sphere{<.5,0,sqrt(3)/2>,.1 rotate 60*y}
  }

on{ 
   intersection {
      cylinder { <-.5,0,sqrt(3)/2>,<.5,0,sqrt(3)/2>,.1 }
      plane { x,0 rotate 30.01*y }
      plane { -x,0 rotate -30.01*y }
      rotate 120*y
   }
   sphere{<.5,0,sqrt(3)/2>,.1 rotate 120*y}
  }
  union{
   intersection {
      cylinder { <-.5,0,sqrt(3)/2>,<.5,0,sqrt(3)/2>,.1 }
      plane { x,0 rotate 30.01*y }
      plane { -x,0 rotate -30.01*y }
      rotate 180*y
   }
   sphere{<.5,0,sqrt(3)/2>
,.1 rotate 180*y}
  }
  union{
   intersection {
      cylinder { <-.5,0,sqrt(3)/2>,<.5,0,sqrt(3)/2>,.1 }
      plane { x,0 rotate 30.01*y }
      plane { -x,0 rotate -30.01*y }
      rotate 240*y
   }
   sphere{<.5,0,sqrt(3)/2>,.1 rotate 240*y}
  }
  union{
   intersection {
      cylinder { <-.5,0,sqrt(3)/2>,<.5,0,sqrt(3)/2>,.1 }
      plane { x,0 rotate 30.01*y }
      plane { -x,0 rotate -30.01*y }
      rotate 300*y
   }
   sphere{<.5,0,sqrt(3)/2>,.1 rotate 300*y}
  }
   prism { -.1,.1,7 <-1,0>,<-.5,sqrt(3)/2>,<.5,sqrt(3)/2>,
           <1,0>,<.5,-sqrt(3)/2>,<-.5,-sqrt(3)/2>,<-1,0> }
  pigment { color rgb<0,0,1> }
  finish { ambient .6 metallic reflection .6}
}

#declare grout_size=.05;
#declare TileWidth=2;
#declare RoundEdgeWidth=.05;
#declare Count1=-25;
#declare Count2=-25;

#while (Count1<=25)
 #while (Count2<=25)
  object { Tile
   translate
<Count1*(1.5*TileWidth+2*grout_size+2*RoundEdgeWidth),0,Count2*(sqrt(3)+2*gr
out_size+2*RoundEdgeWidth)>
  }
  #declare Count2=Count2+1;
 #end
 #declare Count1=Count1+1;
#end

union {
 plane {y,0
  pigment { color rgb<1,1,1> }
 }
 object

  Tile
 }
}


Post a reply to this message

From: Marc-Hendrik Bremer
Subject: Re: #while loop help
Date: 1 Sep 2000 18:10:47
Message: <39b02967@news.povray.org>
You have to reset count2 within the first #while-loop. It is at 26 after the
first loop an remains there.

Todd Taylor schrieb in Nachricht <39b027fe$1@news.povray.org>...

>#declare grout_size=.05;
>#declare TileWidth=2;
>#declare RoundEdgeWidth=.05;
>#declare Count1=-25;
>#declare Count2=-25;
>
>#while (Count1<=25)
> #while (Count2<=25)
>  object { Tile
>   translate
><Count1*(1.5*TileWidth+2*grout_size+2*RoundEdgeWidth),0,Count2*(sqrt(3)+2*g
r
>out_size+2*RoundEdgeWidth)>
>  }
>  #declare Count2=Count2+1;
> #end
> #declare Count1=Count1+1;
>#end
>


Post a reply to this message

From: Warp
Subject: Re: #while loop help
Date: 3 Sep 2000 14:27:55
Message: <39b2982b@news.povray.org>
Marc-Hendrik Bremer <Mar### [at] t-onlinede> wrote:
: You have to reset count2 within the first #while-loop.

  Loops are so often misunderstood and misused that I should make an entry
about them in the VFAQ. I just don't know where to start and what to ask.
  I'll think about something.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: ingo
Subject: Re: #while loop help
Date: 3 Sep 2000 16:10:41
Message: <8FA4E57A0seed7@204.213.191.228>
Warp wrote:

>  Loops are so often misunderstood and misused that I should make an
>  entry about them in the VFAQ. I just don't know where to start and what 
>  to ask. 
>  I'll think about something.

Think about it with an absolute non-programmer mind.
When I first encouterd a loop, it took men an hour to realize that I had 
to do the incrementing myself. I expected it to be automatic.
It took me a day to figure out I had to reset the counter of the inner 
loop myself. For me it seemed very logical that once I had gone through 
the loop the counter would not exist anymore until the loop was enterd 
again.

Now that I'm slowly learning some python, i did it wrong twice in pov. In 
python it indeed is all (more or less) automatic.

while i in range(25):
  while j in range(25):
    do some tings here inside the loops

coninue program outside the loop


Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: Bob Hughes
Subject: Re: #while loop help
Date: 3 Sep 2000 16:42:57
Message: <39b2b7d1$1@news.povray.org>
"ingo" <ing### [at] homenl> wrote in message
news:8FA4E57A0seed7@204.213.191.228...
| python it indeed is all (more or less) automatic.
|
| while i in range(25):
|   while j in range(25):
|     do some things here inside the loops
|
| continue program outside the loop

That looks awfully easy.  Why the word "in" though?  Just so you don't think
it's too simple?

Bob


Post a reply to this message

From: Chris Huff
Subject: Re: #while loop help
Date: 3 Sep 2000 17:08:25
Message: <chrishuff-F3A9F1.16100403092000@news.povray.org>
In article <8FA4E57A0seed7@204.213.191.228>, ing### [at] homenl (ingo) 
wrote:

> Think about it with an absolute non-programmer mind.

Easier said than done.


> When I first encouterd a loop, it took men an hour to realize that I had 
> to do the incrementing myself. I expected it to be automatic.

This is done for flexibility and ease of coding...a variable is just a 
variable, whether you use it as a counter or not, how is POV supposed to 
know it needs to be incremented when the loop ends? Also, there are 
times when you want to increment the loop by a different amount, and 
times when you don't even want to use an incrementing variable for 
control. Loops aren't only used for making several copies of an object.


> It took me a day to figure out I had to reset the counter of the inner 
> loop myself. For me it seemed very logical that once I had gone through 
> the loop the counter would not exist anymore until the loop was enterd 
> again.

This could make sense if you created the variable inside the outer loop 
in many other languages, but if you create it outside both loops, why 
would you expect it to be destroyed when the outer one loops back to 
it's start?
Anyway, POV seems to only have variables local to files and macros. With 
a separate keyword for modifying variables, like what my #set patch 
implements, it would be possible to use variables local to any block, 
like #if statements and #while loops, but I don't expect that to happen 
for a while, if ever.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Warp
Subject: Re: #while loop help
Date: 4 Sep 2000 09:21:31
Message: <39b3a1da@news.povray.org>
Ok, I added an entry about the while loops and made a page about it:

http://iki.fi/warp/povVFAQ/whileloops.html

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: ingo
Subject: Re: #while loop help
Date: 4 Sep 2000 11:17:28
Message: <8FA5ADEABseed7@204.213.191.228>
Bob Hughes wrote:

>That looks awfully easy.  

That why I like it.

>Why the word "in" though?  Just so you don't
>think it's too simple?

Don't ask me...


Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: ingo
Subject: Re: #while loop help
Date: 4 Sep 2000 11:20:07
Message: <8FA5B4D28seed7@204.213.191.228>
Warp wrote:

>  Ok, I added an entry about the while loops and made a page about it:
>
>http://iki.fi/warp/povVFAQ/whileloops.html
>

excellent!

Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: ingo
Subject: Re: #while loop help
Date: 4 Sep 2000 11:29:12
Message: <8FA5BA95Bseed7@204.213.191.228>
Chris Huff wrote:

<snip>
>it would be possible to use variables local to any block, 
>like #if statements and #while loops, but I don't expect that to happen 
>for a while, if ever.

Neither do I, nor do I want it. It was just to illustrate how "illogic" a 
total non-programmer can think(me, two years ago, after only two days 
playing with POV). 
Compare it to chess. You can learn anybody the moves each piece can make, 
but he'll only be able to play chess after he grasps the concept behind 
the game.


Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

Goto Latest 10 Messages Next 4 Messages >>>

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