[Edu-sig] teaching python using turtle module

Gregor Lingl gregor.lingl at aon.at
Mon Nov 30 19:31:52 EST 2009



kirby urner schrieb:
> I'm glad turtle graphics intersected my thinking re extended precision
> decimals (Decimal type) on edu-sig just now.
>
> I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod:
>
> http://www.4dsolutions.net/ocn/python/tmod.py (runnable source)
> http://www.flickr.com/photos/17157315@N00/4147429781/  (GUI view)
>   
Nice tiny app! Albeit not an example for using the if statement ;-)
Just to show you how turtle.py enables you to implement this
using quite different approaches to doing geometry, I'd like to add
two more implementations.

Besides you may notice that these do not rely on rather complicated
calculations of distances and angles, using the Pythagorean theorem
and trigonometrics but only on a few more fundamental properties of
the figure.

##### Version 2 - using coordinate geometry without coordinates ;-)
# a different implementation for Kirby's "Plane Net for T-module"

from turtle import *
from math import sqrt

PHI = (sqrt(5)-1)/2

def planeNet(h=500):             
   setup(560,560)
   title("Plane Net for T-module")
   penup()
   back(h/2); left(90); back(h/2); right(90)
   pendown()

   forward(h); left(90)
   forward(h*PHI); A = pos(); forward(h-h*PHI); left(90)
   forward(h*PHI); B = pos(); forward(h-h*PHI); left(90)
   forward(h); C = pos()

   for P in A, B, C:
      goto(P)


##### Version 3 - stamping simple transforms of the shape of
#####  an isosceles rectangular triangle:

from turtle import Screen, Turtle
from math import sqrt

GOLDEN_RATIO = (sqrt(5)-1)/2

def planeNet(h=500.0, phi=GOLDEN_RATIO):             
   s = Screen(); s.setup(560,560); s.title("Plane Net for T-module")
   s.register_shape("recttriangle", ((0, 0), (h, 0), (0, h)))
   designer = Turtle(shape="recttriangle")
   designer.color("black","")
   designer.penup()
   designer.goto(-h/2, h/2)

   for width, height in ((1, 1-phi), (phi, 1-phi), (phi, 1)):
      designer.shapesize(width, height)
      designer.stamp()
      designer.forward(h)
      designer.right(90)
   designer.hideturtle()

Hoping, you will find this a bit interesting,
best regards

Gregor



> Here's the graphical output:
>
> http://www.flickr.com/photos/17157315@N00/4148139184/in/photostream/
> (Python 3.1)
>
> If you actually wanna fold the T, you need to snip off the cap and
> reverse it, per this diagram:
>
> http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html
>
> 120 of them, 60 folded left, 60 folded right, all of volume 1/24, make
> the volume 5 rhombic triacontahedron.
>
> http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html
>
> If you blow up the volume by 3/2, to 7.5, the radius becomes phi /
> sqrt(2) -- what we're showing with Decimals.
>
> The reason this seems unfamiliar is the unit of volume is the
> tetrahedron formed by any four equi-radiused balls in inter-tangency.
>
> I'm spinning this as Martian Math these days, yakking on
> math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et
> al.
>
> Kirby
>
>   



More information about the Python-list mailing list