[Edu-sig] Design patterns

Kirby Urner urnerk at qwest.net
Wed Aug 24 18:42:04 CEST 2005

> Here's some code, which as yet doesn't actually make use of VPython -- but
> that's where it's going.

And here's where it (the code) went.  

Very minimal, at this point but enough to get VPython actually doing
something with the triangle.  

A student could start with this code and start adding stuff e.g. make it
more colorful, add defaults (e.g. radius), cycle through random triangles in
main() -- using a try loop to catch illegals -- and so on.



class Vpyview(object):
    A viewer: view using VPython

    def __init__(self):
        self._garbage = []
    def display(self, shape):
        self._showedges(shape.edges, shape.verts)

    def _garbagecollect(self):
        for g in self._garbage:
            g.visible = 0
    def _showedges(self, edges, verts):
        for e in edges:
            v0 = vector(verts[e[0]])
            v1 = vector(verts[e[1]])
            edge = cylinder(pos=v0, axis=v1-v0, radius = 0.1)
    def _showverts(self, verts):
        for v in verts:
            v0 = vector(verts[v])
            sph = sphere(pos=v0, radius=0.1)

from visual import *
import time

def main():
    Main call sequence
    thescene = display(title='MVC Demo', center=(0,0,0),
                         background=(.5, .5, .5))
    thescene.autoscale = 0    
    theviewer = Vpyview()    
    theshape = TriAdapter(3,3,3)
    pulser = Pulser(theshape, theviewer)

More information about the Edu-sig mailing list