[Edu-sig] Interactive Numeracy

Dethe Elza delza@antarcti.ca
Wed, 6 Dec 2000 09:28:35 -0800


On Kirby's Numeracy pages
(http://www.inetarena.com/~pdx4d/ocn/numeracy1.html), he uses python to
write out PovRay data and drive PovRay.  This is nice and gives an immediate
result, which can be added to a web page.  I've been playing with VPython,
though and it gives a more tactile result: you can immediately manipulate
the resulting 3D object(s).  One thing which was holding me back from
wholeheartedly recommending it was the requirement that you uninstall Python
and install VPython.  Well, VPython has been updated to use Python 2.0 and
now it plays nice with others.  You can get it at
http://virtualphoton.pc.cc.cmu.edu/projects/visual/.

Here is a simple python script to demonstrate "triangular" numbers:

<example>
from visual import *
from math import pi, cos, sin

dY = -2*sin(pi/3) # difference in height between rows
dX = 1.0          # stagger balls in next by sphere radius (default is 1)

class triangle:
    """Create a triangle of spheres"""
    def __init__(self, n):
        """Triangle will have n rows"""
        for i in range(n):
            self.yadjust = -n * dY / 2 # amount to move up to center
triangle
            self.line(i + 1)

    def line(self, n):
        """A line will have n spheres"""
        for i in range(n):
            x = (-n + 2*i)*dX;
            y = n*dY + self.yadjust;
            z = 0;
            sphere(pos=(x,y,z))

if __name__ == "__main__":
    triangle(5)
</example>

Let me know if anyone's interested in seeing more of this, I plan on playing
around some more with it as I have time (Ha!).

--Dethe