Implicit Modelling Python Examples

 


 



Example One - a sphere
 

#
# Graphics Jungle Project  - Examples of using pycsoft 
#file:  one.py
# Use pybv to view this file
#
# Author :   Brian Wyvill
# This version January 2000
#
# run this file by typing :     pybv one
#

title = "pycsoft examples single softy"

#show a single primitive
def showsofty():
    o = pycsoft.CSoft()
    o.sphere(0.5)
    return o

#add to the display menu
def blobtrees():
        return [
                ('softy',showsofty,())
        ]

Running the above:
 

pybv one


Example Two - Two spheres
 
#
# Graphics Jungle Project  - Examples of using pycsoft 
#file:  two.py
# Use pybv to view this file
#
# Author :   Brian Wyvill
# This version January 2000
#
# run this file by typing :     pybv two

title = "pycsoft examples single softy"

def two(o):
        o.begin()
        o.colour((0.9, 0.1, 0.1 ))
        o.push()
        o.translate(-0.575,0,0)
        o.sphere()
        o.pop()
        o.colour((0.0, 0.8, 0 ))
        o.push()
        o.translate(0.575,0,0)
        o.sphere()
        o.pop()
        o.blend()

#show a single primitive
def showtwo():
        o = pycsoft.CSoft()
        two(o)
        return o

#add to the display menu
def blobtrees():
        return [
                ('two',showtwo,())
        ]

Running the above:
 

pybv two
 
Example Three - a spiral of spheres
 
 
#
# Graphics Jungle Project  - Examples #of using pycsoft 
#file:  recurse.py
# Use pybv to view this file
#
# Author :   Brian Wyvill
# This version January 2000
#
# run this file by typing :     pybv recurse
#

title = "pycsoft examples recursive spiral of softys"

def softy(o):
   o.sphere(0.5)

def two(o):
        o.begin()
        o.colour((0.9, 0.1, 0.1 ))
        o.push()
        o.translate(-0.575,0,0)
        o.sphere()
        o.pop()
        o.colour((0.0, 0.8, 0 ))
        o.push()
        o.translate(0.575,0,0)
        o.sphere()
        o.pop()
        o.blend()

#show a single primitive
def showtwo():
        o = pycsoft.CSoft()
        two(o)
        return o

def aline(o,n):
        d=0
        if (n>0):
                d=1.0/n
                print d
        o.push()
        o.rotate(2,30)
        o.translate(0.65,0,0)
        o.scale(0.9,0.9,0.9)
        o.colour((1-d, 0.3, d ))
        softy(o)
        if (n>0):
                aline(o,n-1)
        o.pop()

#show a single primitive
def showline():
        o = pycsoft.CSoft()
        line(o, 5)
        return o

def line(o, n):
        o.begin()
        aline(o,n)
        o.blend()
 

#now make some horns
def prehorns(o):
        o.begin()
        o.push()
        o.translate(-2.5,0,0)
        line(o,10)
        o.pop()

        o.push()
        o.rotate(1,180)
        o.translate(-2.5,0,0)
        line(o,10)
        o.pop()

        o.colour((0.3, 0.3, 1 ))
        o.push()
        o.translate(0,-0.6,0)
        o.sphere(2.0)
        o.pop()
        o.blend()

def horns(o):
        prehorns(o)

#show a single primitive
def showhorns():
        o = pycsoft.CSoft()
        horns(o)
        return o

#add to the display menu
def blobtrees():
        return [
                ('two',showtwo,()),
                ('spiral',showline,()),
                ('horns',showhorns,())
        ]


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 

 
Running the above:
pybv recurse