POV-Ray : Newsgroups : povray.newusers : While Loop Help Server Time
26 Nov 2024 21:42:19 EST (-0500)
  While Loop Help (Message 1 to 6 of 6)  
From: Brent G
Subject: While Loop Help
Date: 18 Oct 2003 23:03:01
Message: <3f91fee5$1@news.povray.org>
This is what I'm trying to get:

object { MyGrass1 translate <-42.5,0,46.9> } 

object { MyGrass2 translate <-37.5,0,46.9> }
object { MyGrass1 translate <-32.5,0,46.9> }
object { MyGrass2 translate <-27.5,0,46.9> }
object { MyGrass1 translate <-22.5,0,46.9> }
object { MyGrass2 translate <-17.5,0,46.9> }
object { MyGrass1 translate <-12.5,0,46.9> }
object { MyGrass2 translate <12.5,0,46.9> }
object { MyGrass1 translate <17.5,0,46.9> }
object { MyGrass2 translate <22.5,0,46.9> }
object { MyGrass1 translate <27.5,0,46.9> }
object { MyGrass2 translate <32.5,0,46.9> }
object { MyGrass1 translate <37.5,0,46.9> } 

object { MyGrass2 translate <42.5,0,46.9> }

object { MyGrass2 translate <-42.5,0,51.9> } 

object { MyGrass1 translate <-37.5,0,51.9> }
object { MyGrass2 translate <-32.5,0,51.9> }
object { MyGrass1 translate <-27.5,0,51.9> }
object { MyGrass2 translate <-22.5,0,51.9> }
object { MyGrass1 translate <-17.5,0,51.9> }
object { MyGrass2 translate <-12.5,0,51.9> }
object { MyGrass1 translate <12.5,0,51.9> }
object { MyGrass2 translate <17.5,0,51.9> }
object { MyGrass1 translate <22.5,0,51.9> }
object { MyGrass2 translate <27.5,0,51.9> }
object { MyGrass1 translate <32.5,0,51.9> }
object { MyGrass2 translate <37.5,0,51.9> } 

object { MyGrass1 translate <42.5,0,51.9> }

Except I can't figure out how to get the stupid while loops to create a 
checkerboard shape :-/ This is what I've gotten so far (the MyGrass 
Objects are both 5x5 shapes):

#declare X = 0;
#while (X <= 5)

         #declare Z = 0;
         #while(Z <= 6)

                 object { MyGrass1 translate <-12.5-(X*5),0,1.9+(Z*5)> }
                 object { MyGrass1 translate <12.5+(X*10),0,1.9+(Z*5)>  }

                 #declare Z = Z + 2;
         #end

         #declare X = X + 2;
#end

Any help would be GREATLY appreciated :-/


Post a reply to this message

From: Mike Williams
Subject: Re: While Loop Help
Date: 19 Oct 2003 00:16:59
Message: <CGssfBAe+gk$Ewly@econym.demon.co.uk>
Wasn't it Brent G who wrote:
> I can't figure out how to get the stupid while loops to create a 
>checkerboard shape :-/ This is what I've gotten so far (the MyGrass 
>Objects are both 5x5 shapes):
>
>#declare X = 0;
>#while (X <= 5)
>
>         #declare Z = 0;
>         #while(Z <= 6)
>
>                 object { MyGrass1 translate <-12.5-(X*5),0,1.9+(Z*5)> }
>                 object { MyGrass1 translate <12.5+(X*10),0,1.9+(Z*5)>  }
>
>                 #declare Z = Z + 2;
>         #end
>
>         #declare X = X + 2;
>#end

You might consider doing something like this:

#declare Chequer = union {
  object {MyGrass1}
  object {MyGrass2 translate <5,0,0>}
  object {MyGrass1 translate <5,0,5>}
  object {MyGrass2 translate <0,0,5>}
}

#declare X = 0;
#while (X <= 5)
   #declare Z = 0;
   #while(Z <= 6)
      object { Chequer translate <-12.5-(X*5),0,1.9+(Z*5)> }
      object { Chequer translate <12.5+(X*5),0,1.9+(Z*5)>  }
      #declare Z = Z + 2;
   #end
   #declare X = X + 2;
#end


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From:
Subject: Re: While Loop Help
Date: 19 Oct 2003 00:42:23
Message: <3f92162f$1@news.povray.org>
// Hi Brent,
//
// as usual there are many solutions, for example the following one:
// (simply copy this *whole* post to POV-Ray and render it)


#declare MyGrass1 =
  sphere { 0, 2.5
    pigment { color rgb <0, 1, 0> }
    finish { ambient 1 }
    }

#declare MyGrass2 =
  sphere { 0, 2.5
    pigment { color rgb <1, 1, 0> }
    finish { ambient 1 }
    }

camera { location <1, 3, -2>*50 look_at 0 translate 60*z angle 30 }

#declare X = 0;
#while (X <= 5)

  #declare Z = 0;
  #while(Z <= 6)

    #if (mod(X+Z,2)=0) // also try "X*Z" instead of "X+Z"!
        object { MyGrass1 translate <-12.5-X*5, 0, 51.9+Z*5> }
        object { MyGrass2 translate < 12.5+X*5, 0, 51.9+Z*5> }
      #else
        object { MyGrass2 translate <-12.5-X*5, 0, 51.9+Z*5> }
        object { MyGrass1 translate < 12.5+X*5, 0, 51.9+Z*5> }
      #end

    #declare Z = Z + 1;
  #end

  #declare X = X + 1;
#end


// A different solution is to prefix this code with the line
//
// #declare GrassType = 1;
//
// and replace the #if-line by the two lines
//
// #declare GrassType = 3-GrassType; // 1 --> 2;  2 --> 1
// #if (GrassType = 1)
//
// or even (with a third grass):
//
// #switch (GrassType)
//
//   #case (1)
//     object { MyGrass1 ... }
//     object { MyGrass2 ... }
//     #declare GrassType = 2;
//     #break
//
//   #case (2)
//     object { MyGrass2 ... }
//     object { MyGrass3 ... }
//     #declare GrassType = 3;
//     #break
//
//   #case (3)
//     object { MyGrass3 ... }
//     object { MyGrass1 ... }
//     #declare GrassType = 1;
//
//   #end
//
//
// If the number of grass objects isn't too large you can also
// read their type from a string (or from an array of strings,
// one for each row.) If the MyGrasses are stored in an array
// MyGrass, the following lines would look up the type of grass
// and put the corresponding piece of grass into the scene:
//
// #declare Index = X*7+Z; // first row: 0...6, then 7...13, etc.
// #declare TypeCharacter = substr(GrassTypeString,Index+1,1)
// #declare TypeNumber = val(TypeCharacter);
// object { MyGrass[TypeNumber] translate ... }
//
// or in one line:
//
// object { MyGrass[val(substr(GrassTypeString,X*7+Z+1,1))] translate ... }
//
// where GrassTypeString begins like "121212121212" or
// (with more grass types) "12345432123454321" etc.
// In a similar way you could even encode rotations of
// the patches of grass: rotate val(...)*90*y
//
// This collection of ideas should solve more POV-problems
// than you had (until now ... :)
// Happy POVing!
//
//    Sputnik


Post a reply to this message

From: gonzo
Subject: Re: While Loop Help
Date: 19 Oct 2003 02:55:32
Message: <3f923564@news.povray.org>
Brent G <pov### [at] bc-hqcom> wrote in message
news:3f91fee5$1@news.povray.org...
> Except I can't figure out how to get the stupid while loops to create a
> checkerboard shape :-/ This is what I've gotten so far (the MyGrass
> Objects are both 5x5 shapes):
>


How about this, minimal changes to what you already have...

#declare My_Grass = array[2] { MyGrass1, MyGrass2 }

#declare OddEven = 0;

#declare X = 0;
 #while (X <= 5)


          #declare Z = 0;
          #while(Z <= 6)

                  #declare OddEven = ( ! OddEven );

                  object { My_Grass[OddEven] translate
<-12.5-(X*5),0,1.9+(Z*5)> }
                  object { My_Grass[OddEven] translate
<12.5+(X*5),0,1.9+(Z*5)> }

                  #declare Z = Z + 1;
          #end

          #declare X = X + 1;
 #end

RG


Post a reply to this message

From: Brent G
Subject: Re: While Loop Help
Date: 19 Oct 2003 04:44:18
Message: <3f924ee2$1@news.povray.org>
Thank for all the great help everybody!


Post a reply to this message

From: Brent G
Subject: Re: While Loop Help
Date: 19 Oct 2003 04:47:35
Message: <3f924fa7$1@news.povray.org>
> // If the number of grass objects isn't too large you can also
> // read their type from a string (or from an array of strings,
> // one for each row.) If the MyGrasses are stored in an array
> // MyGrass, the following lines would look up the type of grass
> // and put the corresponding piece of grass into the scene:

Do you mean how many different types are not too large? Or how large 
each type is? Since each MyGrass is actually a mesh of a rather large 
number of triangles :)


Post a reply to this message

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