Skip to content

Instantly share code, notes, and snippets.

@jl2
Created August 11, 2010 23:49
Show Gist options
  • Save jl2/520031 to your computer and use it in GitHub Desktop.
Save jl2/520031 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Really simple example of usint cgkit's RenderMan
# Interface binding to generate a RIB file.
from __future__ import print_function
from cgkit.ri import *
from math import *
import sys
def x(t, u,v):
return ((2 + 2 * sin(2*pi*t)) + sin(u)*cos(v)*cos(v))*cos(u)
def y(t, u,v):
return ((2 + 2 * cos(2*pi*t)) + sin(u)*cos(v)*cos(v))*sin(u)
def z(t, u,v):
return sin(2*pi*t+v)+sin(u)*cos(v)*sin(v)
def main(args):
if len(args)<1:
print("No argument given!")
return
RiBegin(RI_NULL)
RiFormat(512,512, 1)
usteps = 24
vsteps = 48
tsteps = 64
t = 0
umin = -pi
vmin = -pi
umax = pi
vmax = pi
tdiff = 1.0/tsteps
udiff = (umax-umin)/usteps
vdiff = (vmax-vmin)/vsteps
fname=args[0]
for i in range(0, tsteps):
# print('{0}'.format(t), file=sys.stderr)
RiFrameBegin(i);
RiDisplay('output/{0}{1:04d}.tif'.format(fname, i),
"file","rgba", RI_NULL)
RiLightSource("distantlight", RI_NULL)
RiProjection("perspective", RI_NULL)
RiTranslate(0.0, 0.0, 6.0)
RiRotate(45.0, -1.0,1.0,0.0)
RiWorldBegin()
u = umin
for j in range(0,usteps):
v = vmin
for k in range(0,vsteps):
v += vdiff
RiAttributeBegin()
RiColor([0,1,0])
RiSurface("plastic",RI_NULL)
RiTranslate(x(t, u,v),
z(t, u,v),
y(t, u,v))
RiSphere(pi/40,-pi/40,pi/40, 360.0, RI_NULL)
RiAttributeEnd()
v += vdiff
u += udiff
RiWorldEnd()
RiFrameEnd()
t += tdiff
RiEnd()
if __name__=='__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment