"""
Kirby Urner
4D Solutions
First published: Apr 27 2007
Upgraded: Apr 29, 2007: refactored to use polyhedra module
Upgraded: May 3, 2007: added 'Many Mes' test of scaling, translating
Simple framework for studying VPython
Dependencies (outside of Standard Library):
http://www.4dsolutions.net/ocn/python/stickworks.py
http://www.4dsolutions.net/ocn/python/polyhedra.py
"""
from visual import sphere, color, display, cylinder
from random import randint
from stickworks import Vector, Edge
from polyhedra import Tetrahedron, Icosahedron
from math import sqrt
red = color.red
green = color.green
blue = color.blue
orange = color.orange
cyan = color.cyan
somecolors = [red, green, blue, orange, cyan ]
phi = (1 + sqrt(5))/2.0
def makespheres(n=100):
for i in range(n):
x, y, z = randint(-10, 10), randint(-10,10), randint(-10,10)
theball = sphere(pos=(x,y,z),
radius = 0.1 * randint(1,5),
color = somecolors[randint(0,len(somecolors)-1)])
def makecyls(n=100):
for i in range(n):
x, y, z = randint(-10, 10), randint(-10,10), randint(-10,10)
thecyl = cylinder(pos=(0,0,0), axis=(x,y,z),
radius = 0.1 * randint(1,5),
color = somecolors[randint(0,len(somecolors)-1)])
def maketent():
sometetra = Tetrahedron()
sometetra.draw()
def makeicosa():
someicosa = Icosahedron()
someicosa.draw()
def manymes(n = 30):
for i in range(n):
color = somecolors[randint(0,len(somecolors)-1)]
Edge.color = color
icosa = Icosahedron() * randint(1, 5)
moveit = Vector( (randint(-25,25), randint(-25,25), randint(-25,25)) )
icosa = icosa + moveit
icosa.draw()
def test():
scene2 = display(title='Some VPython Tests',
width=600, height=600,
center=(0,0,0),
background=(0,1,1))
"""list the functions"""
thetests = [
makespheres,
makecyls,
maketent,
makeicosa,
manymes]
while True:
print """
Choose:
0 Balloon Qyoob
1 Silly Cyls
2 Tetra Tent
3 I, Icosa
4 Many Mes
Q Outta here!
"""
ans = raw_input('Choice? ')
if ans in 'Qq':
break
thetests[int(ans)]()
print "View output, hit Enter to continue..."
ok = raw_input()
for obj in scene2.objects:
obj.visible = False
scene2.visible = False
return
if __name__ == '__main__':
test()
# code highlighted using py2html.py version 0.8