povray.py
author Dmitriy Morozov <dmitriy@mrzv.org>
Tue, 21 Jun 2011 16:48:36 -0700
changeset 18 7d5e8fdf69f2
parent 17 9f4bf1795d51
permissions -rw-r--r--
Pipe radius is centralized in edges.py

def cylinder(u,v,r,c):
    return \
'''cylinder
{
    <%(ux)f, %(uy)f, %(uz)f>,
    <%(vx)f, %(vy)f, %(vz)f>,
    %(r)f
    texture { pigment { color rgb <%(cr)f, %(cg)f, %(cb)f> } }
}\n''' % \
       {  'ux': u.x,
          'uy': u.z,
          'uz': u.y,
          'vx': v.x,
          'vy': v.z,
          'vz': v.y,
          'r': r,
          'cr': c[0],
          'cg': c[1],
          'cb': c[2] }

def sphere(c,r,color):
    return \
'''sphere
{
    <%(x)f, %(y)f, %(z)f>, %(r)f
    texture { pigment { color rgb <%(cr)f, %(cg)f, %(cb)f> } }
}\n''' % \
        { 'x': c.x,
          'y': c.z,
          'z': c.y,
          'r': r,
          'cr': color[0],
          'cg': color[1],
          'cb': color[2] }


def camera(pos, at):
    return '''
camera
{
    location <%(lx)f, %(ly)f, %(lz)f>
    look_at <%(atx)f, %(aty)f, %(atz)f>
}\n''' % { 'lx':  pos.x,
           'ly':  pos.z,
           'lz':  pos.y,
           'atx': at.x,
           'aty': at.z,
           'atz': at.y }

def spotlight(pos, at):
    return '''
light_source
{
    <%(lx)f, %(ly)f, %(lz)f> color White
    spotlight
    point_at <%(atx)f, %(aty)f, %(atz)f>
}\n''' % { 'lx':  pos.x,
           'ly':  pos.z,
           'lz':  pos.y,
           'atx': at.x,
           'aty': at.z,
           'atz': at.y }