POV-Ray Raytracer Descriptions and Examples by Friedrich A. Lohmüller
   Random with POV-Ray (Part 4)
Italiano Italiano
Français français
Deutsch Deutsch

Home
- POV-Ray Tutorial

Random in POV-Ray
   - RandomNumbers in Loops
   - quadratic + cubic
   - Colors + Scale
  > Tilting + Bending
   - Trees by Random
   - Include File 'rand.inc'
   - Filled height_field
   - Random Flower

  - Insert Menu Add-on
    & Download
 
                                       
 Randomized Tilting and Bending      

How to tilt a serie of objects irregularly.
We use a serie of cylinders, which we arrange in one line with a while loop.

//------------------------------------
#declare Mast =
cylinder{ <0,0,0>,<0,2,0>,0.1
 texture{
  pigment{ color rgb<0.40,0.25,0.15>}
  normal { bumps 0.5
           scale <0.005,0.25,0.005>}
  finish { phong 0.5}
 } // end of texture
} // end of cylinder -----------------

#declare NrX = -10;     // start
#declare EndNrX = 10;   // end
#while (NrX < EndNrX+1)
   object{ Mast
           translate<0,0,Nr*1.5>
         } // end of object

 #declare NrX = NrX + 1;  //next Nr
#end // ------------ end of loop -----

Because the expression "rand(Random_1)" gives random values between 0 and 1, we are getting with the expression "rand(Random_1) - 0.5" values between -0.5 and +0.5. Consequently the expression " 2 * ( rand(Random_1) - 0.5 )" delivers us values between -1 and 1.
To get the rotation around the z axis of i.e. maximal +/-10 degrees we have to multiply the previous expression by the maximal amount of the angle:

//-------------------------------------
#declare NrX = -10;     // start
#declare EndNrX = 10;   // end
#while (NrX < EndNrX+1)
object{
  Mast
  rotate<0,0,10*2*(rand(Random_1)-0.5)>
  translate<0,0,Nr*1.5>
} // end of object

 #declare NrX = NrX + 1;  //next Nr
#end // -------------- end of loop ----

This scene can easily be improved as the following images show:

click for higher resolution
Click on the image for a higher resolution!

0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
top

© Friedrich A. Lohmüller, 2013
www.f-lohmueller.de