some turtle questions

Lee Harr missive at hotmail.com
Wed Jan 27 17:24:01 EST 2010


> I am trying to think of things to do with the turtle module

> 1) is there a way to determine the current screen pixel color?


This would not use the included turtle module, but you could use
the turtle module from the pygsear collection:

http://www.nongnu.org/pygsear/

It requires pygame, but if you have that installed already it is
pretty easy to get it working.


Code to get a drawn color would look like:

>>> from pygsear.Drawable import Turtle
>>> t=Turtle()
>>> t.bg.get_at((0,0))
(0, 0, 0, 255)
>>> t.forward(100)
>>> t.position
[400.0, 200.0]
>>> t.bg.get_at((400,300))
(255, 255, 255, 255)
>>> t.left(90)
>>> t.set_color((255,0,0))
>>> t.forward(100)
>>> t.position
[300.0, 200.0]
>>> t.bg.get_at((350,200))
(255, 0, 0, 255)
>>>



> 2) is there a way to put a limit on the extent the turtle can
> travel? it seems I can keep moving off of the screen.

You could write a subclass for interactive use. Maybe like this:

from pygsear.Drawable import Turtle
class T2(Turtle):
    def forward(self, dist):
        Turtle.forward(self, dist)
        if not self.onscreen(slack=10):
            self.backward(dist)


... but I'm not sure that's the best approach. Often when doing
something interesting the turtle will go offscreen for a bit and
come back later to finish up the visible portion of his drawing.

 		 	   		  
_________________________________________________________________
Hotmail: Free, trusted and rich email service.
https://signup.live.com/signup.aspx?id=60969



More information about the Python-list mailing list