[Edu-sig] background docs on Tractor Art

Kirby Urner kurner at oreillyschool.com
Sat Jun 4 02:23:55 CEST 2011


I'm thinking OOP, more than any other paradigm, encourages
a rich set of metaphors, which may be touted as an advantage
if you're ever up against the well in an OOP-hostile room (been
there done that).  "Anti-imperativists" can be pretty militant.

Inheritance is a most obvious metaphor, from whence come any
number of ancestor, parent, child, multi-parent paradigms.
All that assumed knowledge from "real life" infuses the shop
talk, giving a boost in understanding provided the metaphors
aren't too misleading.

The Turtle has become ubiquitous as an obvious "self" in
some environment that might in turn be subclassed if we
like.  Some joke about "turtles all the way down".  It's the
ultimate avatar or sim, usually seen as "3rd person" but
could be "1st person" as well (change of viewpoint).

However, I went with a Tractor instead of Turtle precisely
because the turtle metaphors have been milked pretty
thoroughly and needn't be the last word.  With a Tractor,
we get new etymologies, such as traction, tractare, to drag,
to plow, to leave a rut or mark, to record, to do work
(tractatus).

One of the easiest ways to show off metaphors is not to
subclass a the Tractor type however, but to simply
rename it.

Generic:
>>> from farmworld import Tractor as Worker, Farm as Factory

More specific:
>>> from farmworld import Tractor as government_worker, Farm as Area_51

Students immediately appreciate the analogies between
a horse-like fuel burning engine that does the work of hundreds
of humans, being akin to some generic "doer" or "agent",
with the Farm being akin to said worker's "environment"
or "workplace".

One is starting to think in a more OO fashion when one can mentally
juxtapose what is common among objects.

The Tractor class simply "mows the lawn" in an XY grid.

Actually, a tractor leaves no record in the field itself (self.field is
a list of lists), unless you invoke the plow method (why not
plough = plow?) to make a mark (replace an ASCII character
with a different one -- peek and poke come to mind, from
old timer BASIC coders).

Ed asked me if I'd considered Unicode for the Farm cells.

Indeed, a big part of the Lessons is to mentally add a 3rd
dimension to each cell.  Given this is a Farm, I use the
word silo, which has the interesting property of pointing
either up, above the plane (a grain silo), or below (a missile
silo).  If this XY grid were a bitmap (BMP), or tif file,
with each cell a pixel, then the silo could be about
color depth.

As it is, even though we're getting by with Latin-1, we can
suggest a 32-bit deep silo, with various UTF encodings
compressing that 32-bit pattern.  The mapping to ASCII is
suggestive, and the fact that we're getting by with single
bytes merely highlights the primitivist aesthetic across
all modules.

The Tractor then needs to be subclassed.  It's still an
iterator, meaning it exports the iterator interface (the Java
way of talking) with __iter__ and __next__.

The Sensor tractor does something most Logo-based
turtles don't do:  it senses its environment (of course
Logo lets you write these procedures right?  You can
query the color value at a screen position?).

The Sensor tractor doesn't just look straight down, at
the cell over which it sits -- (Y, X) -- it looks in the 8
directions perpendicular to the edges of a Stop sign:
NW N NE E SE S SW W.

If any of these happen to be off the field, there's a
default value.  Tractors know to StopIteration when
they hit a field boundary or fence.

With a Sensor Tractor, we can play Conway's Game
of Life, by checking the neighborhood.  Rather than
subclass again, we just write a function taking
Sensor tractors for granted.  With a Sensor Tractor,
we may also implement Wolfram's 256 rules, simply
by reading the three cells to the north (NW N NE)
and following some simple substitution rules.

http://4dsolutions.net/ocn/python/OST/lifegame.py
http://4dsolutions.net/ocn/python/OST/nks.py

The CropCircle Tractor is different.  It is inwardly driven
by a generator for the Mandelbrot Set (others might
be swapped in, as the "brains" for this Tractor).  The
CropCircle subclass stretches a complex plane of
given size over whatever 2d array (list of lists).  When
its plow method is fired, it doesn't just make a mark,
like the ancestor / parent.  It computes a mark based on
what the Mandelbrot Set would be here, after so many
iterations of its generator.  The resulting output, after
the field has been mowed, is a Mandelbrot in rough
outline, a primitive example of "ASCII art":

http://4dsolutions.net/ocn/python/OST/ostcanvas.py
http://www.flickr.com/photos/17157315@N00/5645244292/in/set-72157625646071793

Kirby

Much more about Tractors etc.:
http://groups.google.com/group/mathfuture/browse_thread/thread/d2390406c11f8503?pli=1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20110603/c30a0041/attachment.html>


More information about the Edu-sig mailing list