473,587 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving output of Turtle Graphics?

I accidentally stumbled across the Turtle Graphics module (turtle.py)
the other day and have been having some fun with it.

Now I'm wondering if there is a way to build into a script the saving
of each window just before it is cleared. For example, here are a
couple that I've saved by screen capture:
<http://www.rcblue.com/Misc/RandomTriangles .jpg>
<http://www.rcblue.com/Misc/RandomTriangles 2.jpg>

They were produced by this script:

=============== =============== =============== ============
# randomTriangles .py

import turtle as T
from random import *

def twoRndN(low=0, high=1):
"""
generate two random floats x, y in the range [low, high) such that x <= y
"""
x, y = uniform(low, high), uniform(low, high)
if x <= y:
return x, y
else:
return y, x

T.setup(width=1 000, height=700, startx=0, starty=0)
T.title("Random Triangles with random R,G,B")

colorRange = "all"
if colorRange == "random":
lowR, highR = twoRndN()
lowG, highG = twoRndN()
lowB, highB = twoRndN()

count = 0
for n in range(300):
wdth = randrange(0,7,3 )
T.width(wdth)
T.speed("fastes t")
if colorRange == "dark":
R = uniform(.1, .5)
G = uniform(.1, .5)
B = uniform(.1, .5)
elif colorRange == "pastel":
R = uniform(.5, .9)
G = uniform(.5, .9)
B = uniform(.5, .9)
elif colorRange == "all":
R = uniform(0, 1)
G = uniform(0, 1)
B = uniform(0, 1)
# set RGB for one color of your choice
elif colorRange == "manual":
R = .45
G = .2
B = .2
elif colorRange == "random":
R = uniform(lowR, highR)
G = uniform(lowG, highG)
B = uniform(lowB, highB)

T.color(R,G,B)
T.begin_fill()
# 2 connected lines will fill as a triangle
for x in range(2):
coord = (randint(-500,500), randint(-350,350))
T.goto(coord)
T.end_fill()

count += 1
if count 5:
clr = randint(0,5)
if clr == 0:
T.clear()
count = 0
T.done()
=============== =============== =============== =
(The docs for Turtle graphics for Tk are at
<http://www.python.org/doc/2.5/lib/module-turtle.html>)

But how could I have saved them "automatically" ?

The script as shown will clear (T.clear() -- the 3rd line from the
bottom) the window after producing 6 to maybe 15 superimposed
triangles, so clearing will take place maybe 30 times. How can I save
as images each of the 30 windows just before they are cleared?

Thanks,

Dick Moores

Apr 7 '07 #1
7 20689
Dick Moores wrote:
I accidentally stumbled across the Turtle Graphics module (turtle.py)
the other day and have been having some fun with it.

Now I'm wondering if there is a way to build into a script the saving of
each window just before it is cleared. For example, here are a couple
that I've saved by screen capture:
<http://www.rcblue.com/Misc/RandomTriangles .jpg>
<http://www.rcblue.com/Misc/RandomTriangles 2.jpg>
Turtle module uses Tk canvas element to draw graphics ('_canvas'
attribute). I've written module, that exports canvas graphics to SVG
file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
for you.

w.
Apr 7 '07 #2
At 06:50 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu =B3a?= wrote:
>Dick Moores wrote:
I accidentally stumbled across the Turtle Graphics module (turtle.py)
the other day and have been having some fun with it.

Now I'm wondering if there is a way to build into a script the saving of
each window just before it is cleared. For example, here are a couple
that I've saved by screen capture:
<http://www.rcblue.com/Misc/RandomTriangles .jpg>
<http://www.rcblue.com/Misc/RandomTriangles 2.jpg>

Turtle module uses Tk canvas element to draw graphics ('_canvas'
attribute). I've written module, that exports canvas graphics to SVG
file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
for you.
I afraid I'm totally unfamiliar with SVG. Would it be possible for
you or someone else on the list to show how to use your module to
export the simple product of this simple script to an SVG file?

=============== =============== =============== ==
import turtle as T
from random import randint
T.setup(width=1 000, height=700, startx=0, starty=0)
T.color(1, .5, .5)
T.begin_fill()
# 2 connected lines will fill as a triangle
for x in range(2):
coord = (randint(-500,500), randint(-350,350))
T.goto(coord)
T.end_fill()

T.done()
=============== =============== =============== ===

Thanks,

Dick Moores
Win XP Pro SP2
Python 2.5
Python IDE: Ulipad 3.6
Apr 7 '07 #3
Dick Moores wrote:
>Turtle module uses Tk canvas element to draw graphics ('_canvas'
attribute). I've written module, that exports canvas graphics to SVG
file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
for you.

I afraid I'm totally unfamiliar with SVG. Would it be possible for you
or someone else on the list to show how to use your module to export the
simple product of this simple script to an SVG file?

=============== =============== =============== ==
import turtle as T
import canvasvg
from random import randint
T.setup(width=1 000, height=700, startx=0, starty=0)
T.color(1, .5, .5)
T.begin_fill()
# 2 connected lines will fill as a triangle
for x in range(2):
coord = (randint(-500,500), randint(-350,350))
T.goto(coord)
T.end_fill()
canvasvg.saveal l("image.svg" , T._canvas)
T.done()
=============== =============== =============== ===
w.
Apr 7 '07 #4
At 08:48 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu =B3a?= wrote:
>Dick Moores wrote:
Turtle module uses Tk canvas element to draw graphics ('_canvas'
attribute). I've written module, that exports canvas graphics to SVG
file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
for you.
I afraid I'm totally unfamiliar with SVG. Would it be possible for you
or someone else on the list to show how to use your module to export the
simple product of this simple script to an SVG file?

=============== =============== =============== ==
import turtle as T
import canvasvg
from random import randint
T.setup(width=1 000, height=700, startx=0, starty=0)
T.color(1, .5, .5)
T.begin_fill()
# 2 connected lines will fill as a triangle
for x in range(2):
coord = (randint(-500,500), randint(-350,350))
T.goto(coord)
T.end_fill()

canvasvg.savea ll("image.svg" , T._canvas)
T.done()
=============== =============== =============== ===
OK, thanks, now I've got

=============== =============== =============== ==============
<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG
1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg
height="246.000 " viewBox="8.000 338.000 504.000 246.000"
width="504.000" xmlns="http://www.w3.org/2000/svg"><line fill="none"
stroke="#ff8080 " stroke-linecap="round" x1="500.0" x2="20.0"
y1="350.0" y2="426.0"/><line fill="none" stroke="#ff8080 "
stroke-linecap="round" x1="20.0" x2="368.0" y1="426.0"
y2="569.0"/><line fill="none" stroke="#ff8080 " stroke-linecap="round"
x1="360.0" x2="368.0" y1="569.0" y2="569.0"/><polygon fill="#ff8080"
points="368.0 569.0 358.0 572.0 360.0 569.0 358.0 566.0"/><polygon
fill="#ff8080" fill-rule="evenodd" points="500.0,3 50.0 20.0,426.0
368.0,569.0" stroke-linejoin="round "/></svg>
=============== =============== =============== ===============

What do I do to see this?

Dick

Apr 7 '07 #5
Dick Moores wrote:
What do I do to see this?
For example Opera 9 and Firefox 1.5+ are able to view SVG files;
there is a free plugin for IrfanView.

w.
Apr 7 '07 #6
Dick Moores wrote:
OK, thanks, now I've got
[an svg file]
What do I do to see this?
You can convert it to a jpeg using ImageMagick's convert.

Peter
Apr 7 '07 #7
At 09:31 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu =B3a?= wrote:
>Dick Moores wrote:
What do I do to see this?

For example Opera 9 and Firefox 1.5+ are able to view SVG files;
there is a free plugin for IrfanView.
Ha. I had tried it with Firefox 2 already, but I stupidly changed the
extension to HTM first. I'll also get the IrfanView plugin.

Thanks for all the help, and especially for your canvasvg.py module.

Dick
Apr 7 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6717
by: dbrown2 | last post by:
I typically use IDLE for editing and debug. On Windows at least, IDLE and the standard turtle graphics module do not mix. I think both use Tkinter. For now I use IPython and Jedit when using the turtle module but it's not a great solution for me. Is there any known work-around to use turtle with IDLE? If not is there a planned fix for...
1
10511
by: Elaine Jackson | last post by:
Newbie. Playing with the 'turtle' module and wondering if there's a way to save the graphics you make with it. The documentation itself has nothing to say about this, nor (as far as I can tell) does the FAQ list at python-dot-org. Any pointers would be very much appreciated. (In related news, I would also like to find out what's going on...
4
5011
by: Brent W. Hughes | last post by:
If the Turtle gets himself into a large (or infinite) loop, is there any way to stop him other than Ctrl-Alt-Del? Brent
2
10764
by: jevitop | last post by:
Hi, im looking for help on how to make a turtle graphics program. My head will explode trying to figure this out. if anyone can help me please do it, i'll appriciate it!!! Can anyone post the source code for the program???
5
20279
by: Vin | last post by:
Hi, I am using the following code to draw whatever the user draws using x,y. // draws lines directly on a winform. CreateGraphics().DrawLine(APen, x, y, OldX, OldY); Now how do I save the drawing on to a bmp file on my harddisk? C# code in this regard would be very helpful. I tried all forums but invain.
2
2509
by: Mark Denardo | last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage Function: What I'm trying to do is take in an image, crop off the edges around an ellipse region I set up, and then return the cropped image from the function. I sort of have this working, but not thoroughly. If I take the output image of this function and draw it on my...
5
6622
by: tomy | last post by:
Hi All I am a newbie to turtle graphics in python, so sorry if you find this question too easy. How can I get smoother lines in turtle graphics? I am using python on windows. Thanks in advance
4
6835
by: hello123 | last post by:
I saw this program from a website... Any solution ? Turtle Graphics: The Logo language, which is particularly popular among personal computer user, made the concept of turtle graphics famous. Imagine a mechanical turtle that walks around the room under control of c++ program. The turtle holds a pen in one of the two positions, up or down....
1
2477
by: Alexander.Oot | last post by:
I think the speed function may be broken from the turtle graphics package "from turtle import * speed('fastest') forward(50)"
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.