[Edu-sig] More re Saturday Academy course

kirby urner kirby.urner at gmail.com
Sun May 21 15:33:26 CEST 2006


A useful aspect of mixing Python with some POV-Ray training, aside
from the immediate access to graphics, is a golden opportunity to go
over string substitution, especially using dictionary key arguments.

Here is a tiny namespace that outputs colored balls, randomly
positioned and sized.  In class, I asked for a hundred of 'em.  Note
that lottaspheres simply dumps to stdout (IDLE in this case).  Writing
to a file might be the more sophisticated way to go, but I'm focusing
on one feature at a time, and cut and paste works just fine for demo
purposes:

from random import randint

def somesphere():

    xyz = tuple([ randint(-5,5) for r in range(3) ])
    coords = "<%s, %s, %s>" % xyz
    radius = randint(1,4)/2.0
    color = ['Orange','Blue','Green','Yellow','Gold'][randint(0,4)]

    specs = {'theplace':coords, 'thecolor':color, 'theradius':radius }

    mysphere = """
sphere {
    %(theplace)s, %(theradius)s
    texture {
      pigment { color %(thecolor)s }
    }
}
    """ % specs

    return mysphere

def lottaspheres(n):
    for i in range(n):
        print somesphere()


Actually, the output of the above left something to be desired,
aesthetically.  With tweaking, more could be done.  Like, I'd suggest
smaller spheres.

Anyway, the point is it's easy to toss out any number of such tiny
functions, all aimed at saving typing in POV-Ray and giving us pretty
stuff to look at.  And one point of doing *that* is students see
string substitution in action.

On a related note, I see POV-Ray as an excellent vehicle for
introducing and/or revisiting XYZ coordinates as a topic.  The Z axis
is into the screen, with positive X to the right, Y up.  Simply
rendering three colorized axes, say from -5 to 5, and then
test-placing various objects to get a feel for things.

Important in ray tracing:  to locate the point the camera.

Somehow, our culture has devised these third person viewpoints that
disavow their first personhood, e.g. when you're looking at some
polyhedron in a math textbook, you're not usually encouraged to think
about the question "from where am I looking?"

Computer graphics, on the other hand, is refreshing in that it
acknowledges the relevance of viewpoint or vantage point (camera
location), even if the scene is quite devoid of persons.  In this
sense, we're closer to the world of movie directors.

Likewise, ray tracing encourages to think about the so-called
"secondary characteristics" of otherwise Platonic objects nesting in
some Cartesian-Fermatian XYZ space.  We think about color, texture,
reflectivity, shadows.

I like the interdisciplinary feel of this.

"Pure math" (which historically turns up its nose at such special case
details, or even graphics of any kind) is too confining and
restraining, especially when we're trying to develop sophisticated and
powerful imaginations in young people.

That's why we should be using more ray tracer and less chalkboard.
Beyond Flatland.

Kirby


More information about the Edu-sig mailing list