#list28change.py
#/* Copyrighted Pixar 1989 */
#/* From the RenderMan Companion p. 34 */
#/* Listing 2.8 A simple animation */
#/*
# * ColorCube(): create a unit color cube from smaller cubes
# * Parameters:
# * n: the number of minicubes on a side
# * s: a scale factor for each minicube
# */
import cgkit.cri
from cgkit.cgtypes import *
# Load the RenderMan API.
# Replace the library name with whatever renderer you want to use.
ri = cgkit.cri.loadRI("3delight")
cgkit.cri.importRINames(ri, globals())
L= -.5 #* For x: left side */
R= .5 # /* For x: right side */
D= -.5 # /* For y: down side */
U= .5 # /* For y: upper side */
F= .5 # /* For z: far side */
N= -.5 # /* For z: near side */
#/* UnitCube(): define a cube in the graphics environment */
def UnitCube():
Cube=[
[ [L,D,F], [L,D,N], [R,D,N], [R,D,F] ], #/* Bottom face */
[ [L,D,F], [L,U,F], [L,U,N], [L,D,N] ], #/* Left face */
[ [R,U,N], [L,U,N], [L,U,F], [R,U,F] ], #/* Top face */
[ [R,U,N], [R,U,F], [R,D,F], [R,D,N] ], #/* Right face */
[ [R,D,F], [R,U,F], [L,U,F], [L,D,F] ], #/* Far face */
[ [L,U,N], [R,U,N], [R,D,N], [L,D,N] ] #/* Near face */
];
for i in range(6):
RiPolygon(P=Cube[i])
def ColorCube(n, s):
if n<=0:
return
cube = RiObjectBegin()
UnitCube()
RiObjectEnd()
RiAttributeBegin()
RiTranslate(-.5, -.5, -.5 )
RiScale(1.0/n, 1.0/n, 1.0/n)
color=[0,0,0]
for x in range(n):
for y in range(n):
for z in range(n):
color[0] = (x+1)/float(n)
color[1] = (y+1)/float(n)
color[2] = (z+1)/float(n)
RiColor(color)
RiTransformBegin()
RiTranslate (x+.5, y+.5, z+.5)
RiScale(s, s, s)
RiObjectInstance(cube)
RiTransformEnd()
RiAttributeEnd()
color = ( .2, .4, .6 )
NFRAMES = 60 #/* number of frames in the animation */
NCUBES = 5 #/* # of minicubes on a side of the color cube */
FRAMEROT = 3.0 #/* # of degrees to rotate cube between frames */
RiBegin(RI_NULL) #/* Start the renderer */
frame = 1
for frame in range(frame,NFRAMES+1):
if len(str(frame))==1:
print "anim00"+"%d.tif" % frame
filename="anim00"+"%d.tif" % frame
elif len(str(frame))==2:
print "anim0"+"%d.tif" % frame
filename="anim0"+"%d.tif" % frame
else:
print "anim%d.tif" % frame
filename="anim%d.tif" % frame
RiFrameBegin(frame)
RiLightSource("distantlight", RI_NULL)
#/* Viewing transformation */
RiProjection("perspective", RI_NULL)
RiTranslate(0.0, 0.0, 1.5)
RiRotate(40.0, -1.0, 1.0, 0.0)
RiDisplay(filename, RI_FILE, RI_RGBA, RI_NULL)
RiFormat(512, 384, -1.0)
RiShadingRate(1.0)
RiWorldBegin()
RiSides(1); #/* N E W */
scale = (NFRAMES-(frame-1)) / float(NFRAMES)
RiRotate(FRAMEROT*frame, 0.0, 0.0, 1.0)
RiSurface("matte", RI_NULL)
ColorCube(NCUBES, scale) #/* Define the cube */
RiWorldEnd()
RiFrameEnd()
RiEnd()