turtle dump

Terry Reedy tjreedy at udel.edu
Fri Jul 17 16:32:51 EDT 2009


Peter Otten wrote:
> Terry Reedy wrote:
>
>> I tried it. Unfortunately, OOo does not open it correctly. It just
>> displays the first three lines of metadate - Title, Creator, Date -- as
>> image text. Photoshop does read the image, and does an ok job of
>> conversion once anti-aliasing is turned off.
> 
> I snatched some code from the module and modified it to save a sample image:

Thank you for the example.

> 
> from turtle import *
> 
> def switchpen():
>     if isdown():
>         pu()
>     else:
>         pd()
> 
> def demo2():
>     """Demo of some new features."""
>     speed(1)
>     st()
>     pensize(3)
>     setheading(towards(0, 0))
>     radius = distance(0, 0)/2.0
>     rt(90)
>     for _ in range(18):
>         switchpen()
>         circle(radius, 10)
>     write("wait a moment...")
>     while undobufferentries():
>         undo()
>     reset()
>     lt(90)
>     colormode(255)
>     laenge = 10
>     pencolor("green")
>     pensize(3)
>     lt(180)
>     for i in range(-2, 16):
>         if i > 0:
>             begin_fill()
>             fillcolor(255-15*i, 0, 15*i)
>         for _ in range(3):
>             fd(laenge)
>             lt(120)
>         laenge += 10
>         lt(15)
>         speed((speed()+1)%12)
>     end_fill()
> 
>     lt(120)
>     pu()
>     fd(70)
>     rt(30)
>     pd()
>     color("red","yellow")
>     speed(0)
>     fill(1)

begin_fill() in 3.x

>     for _ in range(4):
>         circle(50, 90)
>         rt(90)
>         fd(30)
>         rt(90)
>     fill(0)

end_fill() in 3.x

>     lt(90)
>     pu()
>     fd(30)
>     pd()
>     shape("turtle")
> 
>     tri = getturtle()
>     tri.resizemode("auto")
>     turtle = Turtle()
>     turtle.resizemode("auto")
>     turtle.shape("turtle")
>     turtle.reset()
>     turtle.left(90)
>     turtle.speed(0)
>     turtle.up()
>     turtle.goto(280, 40)
>     turtle.lt(30)
>     turtle.down()
>     turtle.speed(6)
>     turtle.color("blue","orange")
>     turtle.pensize(2)
>     tri.speed(6)
>     setheading(towards(turtle))
>     count = 1
>     while tri.distance(turtle) > 4:
>         turtle.fd(3.5)
>         turtle.lt(0.6)
>         tri.setheading(tri.towards(turtle))
>         tri.fd(4)
>         if count % 20 == 0:
>             turtle.stamp()
>             tri.stamp()
>             switchpen()
>         count += 1
>     tri.write("CAUGHT! ", font=("Arial", 16, "bold"), align="right")
> 
> if __name__ == "__main__":
>     demo2()
>     Screen().getcanvas().postscript(file="demo2.eps")
> 
> I could successfully insert the picture into Writer.

Whereas I still get just three lines of metadata.
The size of my demo2.eps is given as 65,628 bytes.
'Size on disk is given as a bit more but I presume that counts to the 
end of the last 4k block.

> I'm on Kubuntu 9.04 with Python 2.6.2 and OpenOffice 3.0.1.

WinXP with updates, Python 3.1, and OO 3.1.0

So either tk 8.5(?) on windows is producing something different or OO3.1 
  on windows is reading differently. If your file size is different, 
could you email it so I could try to import it here?

> But still, turtle is an educational tool, its main advantage is that it can 
> show beginners how the image is generated.

It is also available with Python as installed. And I want to do simple 
animations (of algoritms) as well as static pictures.

> If you want to generate high-quality graphics easily you need different 
> primitives.
> 
> http://cairographics.org
> 
> has Python bindings, but I don't know if it's available on Windows.

Effectively not, as far as I can tell. PyCairo appears to be *nix and 
require later binaries than those available from gtk site referenced 
from cairo site.

Terry Jan Reedy




More information about the Python-list mailing list