Our first pycao file.

In this page, we shall see how to set up pycao and run our first file.

Installation perequisites:

• pycao requires povray,python, scipy, numpy and pygobject (gi). Please install them on your system.

Installation:

• I suppose that you install Pycao in “/home/myName” Please adapt the following to your directory name.

• Download the pycao.tar on github https://github.com/evainlau/pycao

and drop it off in /home/myName/

• Open the file /home/myName/pycao/template.py and change the first line of this file so that the value of the variable pycaoDir=”/home/myName” by what corresponds to your case

• Save the file and exit.

Run your first file:

• copy the file /home/myName/pycao/template.py to /home/myName/theFileNameOfYourChoice.py
• in a terminal, run the command “python /home/myName/theFileNameOfYourChoice.py” and you should see the first 3D picture you have created with pycao
# a plane represented graphically as a half space
ground=plane(Z,origin) # a plane with normal the vector Z=vector(0,0,1) containing the origin
ground.color='Gray' # The possible colors are the colors described in colors.inc in povray or a rgb color.

wall=Cube(1,2,3) # The two opposite corners of the cube are origin and point(1,2,3)
wall.color="Brown"
wall.move_at(origin+1.5*Z) # the cube is moved above the plane

cyl=Cylinder(start=origin+2*Y,end=origin+2*Y+Z,radius=0.5) # a vertical Cylinder
cyl.color='SpicyPink'

axis=Segment(point(0,4,0),point(0,4,1))
cyl2=ICylinder(axis,0.5) #an infinite cylinder of radius 0.5
cyl2.material="pigment { brick Black Green brick_size 2 mortar 0.2 }"

s=Sphere(point(0,6,0),1)
s.color='<1.5,0.5,0.5,1,0>'

light=Light() # a light
light.location=(origin+6.8*Z-2*X+Y)

camera=Camera()
camera.file="firstFile.pov"
camera.location=origin-5*X+0*Y+2*Z
camera.povraylights="light_source {<"+ str(light.location[0])+","+str(light.location[1])+","+str(light.location[2])+ "> color White " + "}\n\n"
camera.actors=[wall,ground,cyl,cyl2,s] # what is seen by the camera
camera.lookAt=cyl.center
camera.zoom(0.1)

camera.shoot # takes the photo, ie. creates the povray file, and stores it in camera.file
camera.show # show the photo, ie calls povray.


Make a few changes to the file and see the result:

• open theFileNameOfYourChoice.py with an editor
• increase the value of the camera.zoom
• run the command “python theFileNameOfYourChoice.py” again and you should see the same 3D picture as above, but larger

Exercises/Games:

• The file we played with has plenty of comments. Read them and try to modify some values to see how this impacts the 3D picture.
• The file cameras.py shows other options for the camera. Read them, and, if you are interested, change the options in your file.