# Creating Photo-realistic Images and Animations

Author(s):

### 4. Creating the Dodecahedron

We will create an image of a dodecahedron in four steps, introducing new elements as required. Our first image will simply show the background color. Then we will create images of one cylinder, five cylinders in the shape of a pentagon, and finally the fully assembled dodecahedron. To clarify the exposition, the new or modified code at each step will appear in bold type.

#### Background Color:

Cut and paste the following two lines into your editor. Save the file as dodec-01.pov.

// povray +P +I dodec-01.pov +W640 +H360 +A
background{ color rgb<0.2, 0.2, 0.45> }

The first line is a comment containing the shell command for rendering the image. Here is what it means:

• povray” is the name of the rendering engine

• +P pauses the rendering window when rendering finishes instead of closing out this window

• +I dodec-01.pov indicates which scene description file is to be used as input

• +W640 +H360 give the width and height pixel dimensions of the resulting image

• +A indicates that anti-aliasing is turned on

The second line indicates that the background of the scene will be dark blue. This is given by a red-green-blue 3-vector whose components can run from 0 to 1.

If you are using Windows or Mac GUI interface, you can simply click the “Run” button. If you are using Linux, you can cut and paste the first line (excluding the double slash which indicates a comment) into your shell. This first line is not required, but I find it a convenient way to reproduce the exact scene when running the code at a later time.

What you should see is a 640x360 dark blue scene.

#### Single Cylinder:

Our dodecahedron will be constructed using 30 cylinders, so let's start by creating an image with a single cylinder. Cut and paste the following code into your editor and save the file as dodec-02.pov. (Changes from dodec-01.pov above are indicated in boldface.)

// povray +P +I <strong>dodec-02.pov</strong> +W640 +H360 +A<br /><br />background{ color rgb<0.2, 0.2, 0.45> }<br /><br /><strong>camera {<br />        location <0, -8, 0><br />        up <0, 0, 1><br />        right <-1.78, 0, 0><br />        look_at <0, 0, 0><br />        angle 60<br />}<br /><br />light_source {<br />        <100, -100, 100><br />        color rgb<1, 1, 1><br />}<br /><br />cylinder {<0, 0, -1>,   <0, 0, 1>,  0.06<br />        texture{ <br />           pigment{rgb<1, 1, 1>} <br />        }<br />}</strong>

The rendered image should look like Figure 2:

Figure 2: A cylinder

In order to see the object, we need a camera and the object must be illuminated.

To describe the camera, we give it's location in 3-space, the direction of its “up” and “right” vectors, the direction it is looking and the viewing angle. A large viewing angle corresponds to a wide angle lens, allowing more of the scene to be rendered. The right vector might at first seem strange since it points in the negative x direction. I've done that because POV-Ray uses a left handed coordinate system by default. Specifying the right vector in this way transforms the coordinate system into the familiar right handed system that mathematicians and physicists love so well (positive z axis up, positive x axis to the right and positive y axis into the screen). The factor of 1.78 gives the relative width to height of the image: in this case, common 16:9 format seen in high definition video. Similarly, to define the light source we give its location in 3-space and its color vector (using red-green-blue components).

To verify that the coordinate system behaves as expected, let's add a translate directive to the description of the cylinder:

cylinder {<0,0,-2>,<0,0,2>,0.15
texture{
pigment{rgb<1,1,1>}
}
<strong>translate<1,0,0></strong>
}

This translates the cylinder to the right along the x axis. Repeating by translating along the positive y and z axes give the expected results (Figure 3):

Figure 3: Translation

You can define the light scattering properties of a surface by using primitives that give specular reflectivity, diffuse reflectivity, transparency and so on. Or you can use one of the hundreds of predefined textures. To do that, a texture definition file must be included with your scene file. Save the following code as dodec-03.pov and render it (Figure 4). (Changes from dodec-02.pov above are indicated in boldface.)

// povray +P +I <strong>dodec-03.pov</strong> +W640 +H360 +A<br /><br /><strong>#include "golds.inc"</strong>

background{ color rgb<0.2,0.2,0.45>}

camera {
location <0, -8, 0>
up <0, 0, 1>
right <-1.78, 0, 0>
look_at <0, 0, 0>
angle 60
rotate <0, 0, 0>
}

light_source {
<100,-100,100>
color rgb<1,1,1>*1.5
}

<strong>cylinder {<0,0,-2>,   <0,0,2>,  0.15<br />        texture { T_Gold_5A }<br />}<br /></strong>

Figure 4: Changing the texture

Michael Grady (Southern Utah Univ.), "Creating Photo-realistic Images and Animations," Convergence (September 2010), DOI:10.4169/loci003351