POV-Ray : Newsgroups : povray.newusers : While Loop Help : Re: While Loop Help Server Time
2 Nov 2024 17:20:19 EDT (-0400)
  Re: While Loop Help  
From:
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

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