pyrtl Example

The following is a simple example of a python script to define a scene for pyrtl. Of course, this example does not take full advantage of using python. We are able with a real programming language to use its programming constructs. There is no reason why we couldn't parameterize this scene in a function over time somehow and render a series of frames for an animation.

Keep in mind that the scene below performs an extraordinary amount of anti-aliasing and would be prohibitive to render as written on most computers. This image was rendered on the MACI cluster of high performance computers in parallel using eight alpha workstations in 178 seconds.

# Example 1  Python script for scene description    

import pyrtl


# Create a new world to render an image of
scene = pyrtl.World(25)

# Show progress output while rendering
scene.progress(1)

# Create a light at position (10,20,15) with white colour and radius 1
scene.light((10,20,15),(1,1,1),1)

# Specify the lookat transformation
scene.lookat((-3,3,10),(0,0,0),(0,1,0))

#define a floor for the scene
scene.push()
checkers = pyrtl.Checkers(pyrtl.Material((0.75,0.75,0)),
			  pyrtl.Material((0,0,0.75)))
checkers.scale(30,1,30)
checkers.translate(0,0.02,0)
scene.material(pyrtl.Material((1,1,1)))
scene.texture(checkers)
scene.scale(50,1,50)
scene.floor()
scene.pop()

# put something to lookat in the scene
scene.push()
scene.translate(0,1,0)
turb = pyrtl.Turbulence(pyrtl.Material((0.4,0.3,0.35)),
 			pyrtl.Material((0.2,0.01,0.5)),5);
scene.material(pyrtl.Material((1,1,1)))
scene.texture(turb)
scene.push()
scene.translate(1.3,0,0.1)
scene.sphere()
scene.pop()
scene.push()
scene.clear('texture')
scene.translate(-1.1,0,1.2)
scene.material(pyrtl.Glass((0.9,0.9,0.9),0.1))
scene.sphere()
scene.pop()

scene.image((640,480),(0,0,0))
scene.prender(15,70)

scene.save('ex1.ppm')
      

Mark Tigges
Last modified: Sun Dec 6 15:15:25 PST 1998