Descriptions and Examples for the POV-Ray Raytracerby Friedrich A. Lohmüller     Conditional Statements -
Deutsch

Home
- POV-Ray Tutorial

- Conditional
Statements

Branching
#if(...) ... #else ... #end
> in loops
- in macros
- in animations
- turning on/off of parts
#switch(...) #case(..) ...
#range(..) ... #end
- selection by tables

Check for Existence
#ifdef(...) #ifndef(...)
- Check in include files
- Defaults in include files

Loops
Prechecked, Postchecked,
Count-controlled, Early-Exit
#while(...)... #end
#for(...)... #end
- Samples:
- Loops with POV-Ray
- Loops, Sine, Cosine
- Random with POV-Ray

Branching in Loops

Sample for the use of #if ... #else... #end in loops:
a) With a #while loop:
 ```union{ #local Nr = 0; // start #local EndNr = 20; // end #while (Nr< EndNr) sphere{ <0,0,0>,0.25 #if( Nr/2 = int(Nr/2) ) // only with even numbers Nr texture{ pigment{ color rgb<1,0.65,0>} finish { phong 1} } scale<1,1.5,1> #else // with odd numbers Nr texture{ pigment{ color rgb<1,0,0.35>} finish { phong 1} } scale<1.5,1,1> #end // end of "#if( Nr/2 = int (Nr/2)" translate<1,0.25,0> rotate<0,Nr * 360/EndNr,0>} #local Nr = Nr + 1; // next Nr #end // --------------- end of loop rotate<0,0,0> translate<0,0,0> } // end of union -------------------```
a) With a #for loop:
 ```union{ #local EndNr = 20; // end value //#for(Var.,Start,End,Step) #for (Nr, 0, EndNr-1, 1) sphere{ <0,0,0>,0.25 #if( Nr/2 = int(Nr/2) ) // only with even numbersn texture{ pigment{ color rgb<1,0.65,0>} finish { phong 1} } scale<1,1.5,1> #else // with odd numbers texture{ pigment{ color rgb<1,0,0.35>} finish { phong 1} } scale<1.5,1,1> #end // end of "#if( Nr/2 = int (Nr/2)" translate<1,0.25,0> rotate<0,Nr * 360/EndNr,0>} #local Nr = Nr + 1; // next Nr #end // --------------- end of loop rotate<0,0,0> translate<0,0,0> } // end of union -------------------```

top

 © Friedrich A. Lohmüller, 2010 homepage:http://www.f-lohmueller.de