Descriptions and Samples for the POV-Ray Raytracer by Friedrich A. Lohmüller
    deutsche Version

Guitar Body overview Winding Staircase

A Wheel - with and without #while Statement

Sample for the using of "#while"

Objects: "torus", "cylinder"
Methods: "declare", "union", "#while"

b) Without while-Loop

...
#declare Number_of_spokes = 16; 
#declare W = 360/Number_of_spokes;  
//-------------------------------------------------- wheel
union{
torus{0.9,0.20 scale <1,1,1> rotate<90,0,0>
         texture{Rimtex}} // rim
torus{1.0,0.25 scale <1,1,1> rotate<90,0,0>
         texture{Tiretex}} // tire
cylinder {<0,0,-0.48>,<0,0, 0.48>,0.05
         texture{Hubtex}} // hub
//------------------- without #while-Schleife: --------<<1

union{
 cylinder {<-1,0, 0>,<1,0, 0>,0.05 rotate<0,0, 0*W>}
 cylinder {<-1,0, 0>,<1,0, 0>,0.05 rotate<0,0, 1*W>}
 cylinder {<-1,0, 0>,<1,0, 0>,0.05 rotate<0,0, 2*W>}
 cylinder {<-1,0, 0>,<1,0, 0>,0.05 rotate<0,0, 3*W>}
 cylinder {<-1,0, 0>,<1,0, 0>,0.05 rotate<0,0, 4*W>}
 cylinder {<-1,0, 0>,<1,0, 0>,0.05 rotate<0,0, 5*W>}
 cylinder {<-1,0, 0>,<1,0, 0>,0.05 rotate<0,0, 6*W>}
 cylinder {<-1,0, 0>,<1,0, 0>,0.05 rotate<0,0, 7*W>}
 texture{Rimtex}}

//---------------------------------------------- end --<<2
translate<0,1.25,0> rotate<0,40,0>} // end of union 
//---------------------------------------------- end ----

Instead of many detailed single descriptions of statements which change only little, we can use in these cases the loop technologie. This technology does not only reduce the work of writing the scenery file (sure: with "cut and paste" no big problem!), but it allows also to change the values for the number of elements and the step value very easy.

b) With while-Loop

...
//or from <<1  until <<2 --- with while-loop ----->>1
#declare Nr = 0;  
#declare EndNr = Number_of_spokes/2;

#while ( Nr < EndNr )
  cylinder {< -1, 0, 0>,< 1, 0, 0>, 0.05
            rotate< 0, 0, 180/EndNr * Nr >
            texture{Rimtex}}
  #declare Nr = Nr +1;
#end // ------------------------------------------>>2
... 
Sample while loop
Click here for the complete scene description for POV-Ray:
".txt" file or ".pov" file

POVRAY uses as loop the while-loop. Whether the part between "#while"-statement and the according "#end"-statement will be executed or not is decided according the conditions inside of the round brackets behind the "#while"-statement. This is decided before the statements of this parts are executed.
This is a so-called "pre-checked loop" - well known from many programming languages. The also well known statement "repeat ... until" for a so-called "post-checked loop" does not exist in POVRAY until now. This is not a big problem because it is possible to transform every loop of one kind to a loop of the other kind just by transforming the conditions of the loop.


Guitar Body overview Winding Staircase

© Friedrich A. Lohmüller, 2004
email email: (legacy email redacted)
homepage:www.f-lohmueller.de