|
In this section I want to demonstrate some elementary
applications of the while loop in POV-Ray.
In this applications the while loop is used for the regular placing of objects.
The following samples want to demonstrate single and nested loop.
Note: All POV-Ray scene files of the following samples are downloadable
(extension: .pov, alternativly also as .txt text files!).
Most of the sample POV-Ray scene files use the include file
"axis_xyz.inc" for the coordinate system. This file can be downloaded here:
as a ".inc" file or
as a ".txt" file
(Save it renaming the extension to ".inc"!).
|
|
First we consider a single loop which places little spheres along the x axis
from x = -5 to x = +5:
//------------------------------------
#declare Ball =
sphere{<0,0,0>,0.5
texture{pigment{color Red}
finish {ambient 0.15
diffuse 0.85
phong 1}
}
}
#declare NrX = -5; // start
#declare EndNrX = 5; // end
#while (NrX < EndNrX+1)
object{Ball translate <NrX,0,0>}
#declare NrX = NrX + 1; //next Nr
#end // ------------- end of loop ----
|
Scene file for POV-Ray: .pov or:
.txt
|
|
If we nest an existing loop in another loop which steps through the values
from z = 0 to z = +5, we get a rectangular field covered by identical objects:
|
//------------------------------------
#declare Boxy =
box {<0,0,0>,< 1,1,1> scale 0.5
texture{pigment{color White}
finish {ambient 0.1
diffuse 0.9}}}
#declare DistanceX = 1.00;
#declare DistanceZ = 1.00;
#declare NrX = 0; // startX
#declare EndNrX = 7; // endX
#while (NrX < EndNrX) // <-- loop X
#declare NrZ = 0; // start
#declare EndNrZ = 7; // end
#while (NrZ < EndNrZ) // <- loop Z
object{Boxy
translate<NrX*DistanceX, 0,
NrZ*DistanceZ>}
#declare NrZ = NrZ + 1; // next NrZ
#end // --------------- end of loop Z
#declare NrX = NrX + 1;// next NrX
#end // ------------- end of loop X --
|
Scene file for POV-Ray: .pov or:
.txt
|
|
It is posibble to nest a nested loop in an additional loop,
which steps through the values from y = 0 to y = +5. With this we get
a box formed by identically formed objects:
|
//------------------------------------
#declare DX = 1.00;
#declare DY = 1.00;
#declare DZ = 1.00;
#declare NrX = 0; // startX
#declare EndNrX = 5; // endX
#while (NrX < EndNrX)
#declare NrY = 0; // startY
#declare EndNrY = 5; // endY
#while (NrY < EndNrY)
#declare NrZ = 0; // startZ
#declare EndNrZ = 5; // endZ
#while (NrZ < EndNrZ)
object{Boxy
translate
<NrX*DX,NrY*DY,NrZ*DZ>
}
#declare NrZ = NrZ+1;// next NrZ
#end // ---------- end of loop Z
#declare NrY = NrY+1;// next NrY
#end // ---------- end of loop Y
#declare NrX = NrX+1;// next NrX
#end // ----------- end of loop X ----
|
Scene file for POV-Ray: .pov or:
.txt
|
|
With this sample our possibilities regarding to pure linear
transformations with loops seam to be exhausted in our three dimensional world.
|