Re: turtle dump

2009-07-18 Thread Peter Otten
Terry Reedy wrote:

 alex23 wrote:
 
 The help in iPython says the same, but also mentions that it's a
 dynamically generated function, so it may not be picking up the
 docstring that way. turtle.ScrolledCanvas.postscript is similarly
 terse, but you can find more info in turtle.Canvas.postscript:
 
   Print the contents of the canvas to a postscript
   file. Valid options: colormap, colormode, file, fontmap,
   height, pageanchor, pageheight, pagewidth, pagex, pagey,
   rotate, witdh, x, y.
 
 How, exactly, did you get that list?
 
 tjr

[Python 3.1]
 import tkinter
 print(tkinter.Canvas.postscript.__doc__)
Print the contents of the canvas to a postscript
file. Valid options: colormap, colormode, file, fontmap,
height, pageanchor, pageheight, pagewidth, pagex, pagey,
rotate, witdh, x, y.

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-17 Thread Peter Otten
Terry Reedy wrote:

 Terry Reedy wrote:
 
 $ file tmp.ps
 tmp.ps: PostScript document text conforming DSC level 3.0, type EPS

 Try changing the file extension from .ps to .eps.
 
 I will. Thank you.
 
 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:

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)
for _ in range(4):
circle(50, 90)
rt(90)
fd(30)
rt(90)
fill(0)
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.

I'm on Kubuntu 9.04 with Python 2.6.2 and OpenOffice 3.0.1.
 
 Hmmm. Crazy idea... in
 
http://us.pycon.org/media/2009/talkdata/PyCon2009/065/SevenWaysToUseTurtle-
PyCon2007.pdf
 Gregor Lingl says that turtle.py has been ported to pygame and jython as
 back ends. It should be possible to instead send output to a file
 instead of an on-screen canvas. Run a program to screen. When output
 looks right, return with a different parameter to send to file.
 
 For instance, an OpenDocumentDrawing file (.odd) using odfpy.
 This assumes that there are elements corresponding to each turtle
 command. Or at least that the fit is close enough.

I can see nothing crazy about that.

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

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.

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-17 Thread Terry Reedy

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

--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-17 Thread Terry Reedy

alex23 wrote:


The help in iPython says the same, but also mentions that it's a
dynamically generated function, so it may not be picking up the
docstring that way. turtle.ScrolledCanvas.postscript is similarly
terse, but you can find more info in turtle.Canvas.postscript:

  Print the contents of the canvas to a postscript
  file. Valid options: colormap, colormode, file, fontmap,
  height, pageanchor, pageheight, pagewidth, pagex, pagey,
  rotate, witdh, x, y.


How, exactly, did you get that list?

tjr

--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-17 Thread David Robinow
 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.

http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/1.4/
 Works for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-17 Thread Terry Reedy

David Robinow wrote:

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.


http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/1.4/
 Works for me.


Thanks. I did not see that referenced from the cairo site. Now if only 
there were a 3.1 version


tjr

--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Diez B. Roggisch
superpollo wrote:

 hi there.
 
 is there a way to dump the content of a turtle window to a file or a
 file object?

Why should I want to dump a turtle? They are very benign creatures, dumping
them is going to hurt them needlessly.

Without a cheek-in-tongue: how are we supposed to know what aturtle window
is, how you create it, what features it uses? You need to give more
details, such as the module you are using, on what system that runs and so
forth.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread superpollo

Diez B. Roggisch wrote:

superpollo wrote:



hi there.

is there a way to dump the content of a turtle window to a file or a
file object?



Why should I want to dump a turtle? They are very benign creatures, dumping
them is going to hurt them needlessly.



lol. ;-) the title was indeed supposed to stir a bit of curiosity upon 
the reader...



Without a cheek-in-tongue: how are we supposed to know what aturtle window
is, how you create it, what features it uses? You need to give more
details, such as the module you are using, on what system that runs and so
forth.


in fact i was looking for a *platform independent* way to draw into a 
graphics file (say, a postscript or a png) using the turtle module. so i 
understand that dumping a window is not a good expression... maybe 
redirecting graphics commands to a file instead of a window?


bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread alex23
On Jul 16, 9:18 pm, superpollo u...@example.net wrote:
 lol. ;-) the title was indeed supposed to stir a bit of curiosity upon
 the reader...

Which isn't really useful when trying to obtain assistance... you want
certainty, not curiosity.

 in fact i was looking for a *platform independent* way to draw into a
 graphics file (say, a postscript or a png) using the turtle module. so i
 understand that dumping a window is not a good expression... maybe
 redirecting graphics commands to a file instead of a window?

You didn't actually answer Diez question. The turtle module is only a
recent (2.6/3.0) addition to Python and is probably obscure enough not
to have tracked across everyone's radar.

So _if_ you're talking about the standard lib turtle module, you're
not looking to 'dump a window', you're looking to write the contents
of turtle.Canvas to file. Canvas only supports writing to postscript,
so you'll have to do something like this (untested):

import turtle
screen = turtle.Screen()
# go go gadget turtle...
screen._canvas.postscript(file='turtle.ps')

Or it may be open('turtle.ps','w').write(screen._canvas.postscript
())... I couldn't find a definitive answer. Try looking through the Tk
docs, it should be covered there.

Note that this is a postscript _text_ file, so you'll also need to
find something to render it with.

Hope this helps point you in the right direction.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread superpollo

alex23 wrote:

On Jul 16, 9:18 pm, superpollo u...@example.net wrote:


lol. ;-) the title was indeed supposed to stir a bit of curiosity upon
the reader...



Which isn't really useful when trying to obtain assistance... you want
certainty, not curiosity.



ok. my bad.




in fact i was looking for a *platform independent* way to draw into a
graphics file (say, a postscript or a png) using the turtle module. so i
understand that dumping a window is not a good expression... maybe
redirecting graphics commands to a file instead of a window?



You didn't actually answer Diez question. The turtle module is only a
recent (2.6/3.0) addition to Python and is probably obscure enough not
to have tracked across everyone's radar.



actually i am still using 2.3.4, which means that...


screen = turtle.Screen()


... is not possible



Hope this helps point you in the right direction.


it certainly did, tahnks.

bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Bearophile
Superchicken:
 is there a way to dump the content of a turtle window to a file or a file 
 object?

A possible low-tech solution is to append to a list the sequence of
your plotting commands (using a decorator too, even, something like
the logging decorator), and then save all of them at the end into a
text file :-)

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Peter Otten
superpollo wrote:

 alex23 wrote:
 On Jul 16, 9:18 pm, superpollo u...@example.net wrote:
 
lol. ;-) the title was indeed supposed to stir a bit of curiosity upon
the reader...
 
 
 Which isn't really useful when trying to obtain assistance... you want
 certainty, not curiosity.
 
 
 ok. my bad.
 
 
in fact i was looking for a *platform independent* way to draw into a
graphics file (say, a postscript or a png) using the turtle module. so i
understand that dumping a window is not a good expression... maybe
redirecting graphics commands to a file instead of a window?
 
 
 You didn't actually answer Diez question. The turtle module is only a
 recent (2.6/3.0) addition to Python and is probably obscure enough not
 to have tracked across everyone's radar.
 
 
 actually i am still using 2.3.4, which means that...
 
 screen = turtle.Screen()
 
 ... is not possible

Tested on 2.4:

 import turtle
 turtle.reset()
 for i in range(4):
... turtle.forward(50)
... turtle.right(90)
...
 turtle._canvas.postscript(file=tmp.ps)
''

I think the big rewrite has happened in 2.6, so the above should also work 
in 2.3.

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread superpollo

Peter Otten wrote:

Tested on 2.4:



import turtle
turtle.reset()
for i in range(4):


... turtle.forward(50)
... turtle.right(90)
...


turtle._canvas.postscript(file=tmp.ps)


''

I think the big rewrite has happened in 2.6, so the above should also work 
in 2.3.


Peter



mr otten, you are great.

bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Michiel Overtoom


I got success with the following code (python 2.6.2):

import turtle
turtle.reset()
for i in range(4):
   turtle.forward(50)
   turtle.right(90)
can=turtle.getscreen().getcanvas()
can.postscript(file=tmp.ps)


--
The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing. - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread alex23
On Jul 16, 10:11 pm, superpollo u...@example.net wrote:
 actually i am still using 2.3.4, which means that...

  screen = turtle.Screen()

 ... is not possible

Ah, sorry about that. My belief that turtle was a new module was based
on a line from 
http://us.pycon.org/media/2009/talkdata/PyCon2009/065/SevenWaysToUseTurtle-PyCon2007.pdf

   Since Python 2.6/3.0, Python has had a new turtle module.

At which point I stopped reading and missed the following line:

   Its development was based entirely on the previous one.

In my defence, I _had_ been drinking.

Thankfully Peter stepped up with a more appropriate solution, and
Michiel pointed out the more suitable API calls over dealing directly
with the underlying implementation :) Good work guys!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Terry Reedy

Michiel Overtoom wrote:


I got success with the following code (python 2.6.2):

import turtle
turtle.reset()
for i in range(4):
   turtle.forward(50)
   turtle.right(90)
can=turtle.getscreen().getcanvas()
can.postscript(file=tmp.ps)


Is raw postscript (.ps) the only thing tk can write from canvas?
I would like to be able to import into OpenOffice document (drawing 
object) and it can import encapsulated postscript (.eps) and about 20 
other things but not, apparently, .ps.


Help on method postscript:
postscript(self, *args, **kw) method of turtle.ScrolledCanvas instance

is spectacularly useless. I did not see anything similar in the list of 
about 100 attributes. The image_type of the canvas is 'photo bitmap' but 
I see no method to write that.



--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Peter Otten
Terry Reedy wrote:

 Michiel Overtoom wrote:
 
 I got success with the following code (python 2.6.2):
 
 import turtle
 turtle.reset()
 for i in range(4):
turtle.forward(50)
turtle.right(90)
 can=turtle.getscreen().getcanvas()
 can.postscript(file=tmp.ps)
 
 Is raw postscript (.ps) the only thing tk can write from canvas?
 I would like to be able to import into OpenOffice document (drawing
 object) and it can import encapsulated postscript (.eps) and about 20
 other things but not, apparently, .ps.
 
 Help on method postscript:
 postscript(self, *args, **kw) method of turtle.ScrolledCanvas instance
 
 is spectacularly useless.

http://docs.python.org/library/turtle.html#turtle.getcanvas

The module is a bit messy, but the accompanying documentation seems OK to 
me. 

 I did not see anything similar in the list of
 about 100 attributes. The image_type of the canvas is 'photo bitmap' but
 I see no method to write that.

That's probably a bitmap that you can draw on the canvas. The Canvas is 
actually that of Tkinter, and according to

http://www.tcl.tk/man/tcl8.5/TkCmd/canvas.htm#M59

it writes Encapsulated Postscript 3.0. Also:

$ file tmp.ps
tmp.ps: PostScript document text conforming DSC level 3.0, type EPS

Try changing the file extension from .ps to .eps.

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Terry Reedy

Peter Otten wrote:

Terry Reedy wrote:



Help on method postscript:
postscript(self, *args, **kw) method of turtle.ScrolledCanvas instance

is spectacularly useless.


This is from interactive help.


http://docs.python.org/library/turtle.html#turtle.getcanvas


That method, following your lead, is how I got to .postscript.
The doc says

 Return the Canvas of this TurtleScreen. Useful for insiders who know 
what to do with a Tkinter Canvas.


The module is a bit messy, but the accompanying documentation seems OK to 
me. 


?? I am not an 'insider' ;-).


I did not see anything similar in the list of
about 100 attributes. 


Of Canvas, mostly methods. I can understand that no one who could write 
decent doc strings for the 100 methods has actually volunteered to do so.



The image_type of the canvas is 'photo bitmap' but

I see no method to write that.


That's probably a bitmap that you can draw on the canvas. The Canvas is 
actually that of Tkinter, and according to


http://www.tcl.tk/man/tcl8.5/TkCmd/canvas.htm#M59

it writes Encapsulated Postscript 3.0. Also:

$ file tmp.ps
tmp.ps: PostScript document text conforming DSC level 3.0, type EPS

Try changing the file extension from .ps to .eps.


I will. Thank you.

tjr

--
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread alex23
  Help on method postscript:
  postscript(self, *args, **kw) method of turtle.ScrolledCanvas instance
  is spectacularly useless.

 This is from interactive help.

The help in iPython says the same, but also mentions that it's a
dynamically generated function, so it may not be picking up the
docstring that way. turtle.ScrolledCanvas.postscript is similarly
terse, but you can find more info in turtle.Canvas.postscript:

  Print the contents of the canvas to a postscript
  file. Valid options: colormap, colormode, file, fontmap,
  height, pageanchor, pageheight, pagewidth, pagex, pagey,
  rotate, witdh, x, y.

 The doc says

  Return the Canvas of this TurtleScreen. Useful for insiders who know
 what to do with a Tkinter Canvas.

  The module is a bit messy, but the accompanying documentation seems OK to
  me.

 ?? I am not an 'insider' ;-).

I don't think the intent of the turtle module is to be a primer in Tk,
but more of an educational tool. The lack of image export niceties has
a lot to do with the limitations of Tk, but was probably (and I'm
conjecturing here) felt to be outside the scope of what the module
aims to achieve.

 Of Canvas, mostly methods. I can understand that no one who could write
 decent doc strings for the 100 methods has actually volunteered to do so.

I think they all _have_ doc strings, or at least the code they
eventually call does, but I'd have to look into the module itself to
see if they could be brought over dynamically.

You may be interested in the final page of Greg Lingl's PyCon talk,
Seven Ways to use Turtle[1] which states:

  The turtle module is designed in a way so that essentially all of
the turtle
  graphics machinery is based on a class TurtleScreenBase, which
provides the
  interface to the underlying graphics toolkit Tkinter.

  So it‘s easy to port turtle.py to different graphics toolkits/
libraries,
  simply by replacing this Tkinter base class with an appropriate
different one.

  I‘ve done two ports: Pygame  Jython

If you're after bitmap, I'd suggest contacting Greg and asking about
the Pygame port. His contact info can be found at the original site
for the revised turtle module[2], hopefully it's still up to date.

1: us.pycon.org/media/2009/talkdata/PyCon2009/065/SevenWaysToUseTurtle-
PyCon2007.pdf
2: http://xturtle.rg16.at/download.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turtle dump

2009-07-16 Thread Terry Reedy

Terry Reedy wrote:


$ file tmp.ps
tmp.ps: PostScript document text conforming DSC level 3.0, type EPS

Try changing the file extension from .ps to .eps.


I will. Thank you.


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.


Hmmm. Crazy idea... in
http://us.pycon.org/media/2009/talkdata/PyCon2009/065/SevenWaysToUseTurtle-PyCon2007.pdf
Gregor Lingl says that turtle.py has been ported to pygame and jython as 
back ends. It should be possible to instead send output to a file 
instead of an on-screen canvas. Run a program to screen. When output 
looks right, return with a different parameter to send to file.


For instance, an OpenDocumentDrawing file (.odd) using odfpy.
This assumes that there are elements corresponding to each turtle 
command. Or at least that the fit is close enough.


Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list