[Edu-sig] some turtle questions

Helene Martin lognaturel at gmail.com
Sun Jan 24 18:35:42 CET 2010

I'm almost sure that there's no way for a turtle to know anything
about the background.  That's an unfortunate limitation!

As for putting a limit on a turtle's travel, you need to write an
appropriate conditional.  For example, if you want your turtle to stay
within a 200x200 square centered around the origin and stop if it gets
out, do something roughly like:

while(math.abs(t.xcor()) < 100 and math.abs(t.ycor()) < 100):
   move turtle

Of course, you could instead use if statements and simulate bouncing
(if my turtle's x coordinate is beyond my bounding box, subtract from
its x coordinate).


Computer Science Teacher
Garfield High School

On Sun, Jan 24, 2010 at 7:29 AM, Brian Blais <bblais at bryant.edu> wrote:
> Hello,
> I am trying to think of things to do with the turtle module with my
> students, and I have some ideas where I am not sure whether the turtle
> module can do it.
> 1) is there a way to determine the current screen pixel color?  I am
> thinking about having the turtle go forward until it reaches an object, say
> a red circle.  I can probably do this by making circle objects (drawn with
> turtles themselves) which know their own position, and check against this
> info.  But I thought it might be useful also for the turtle to know.
> 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.  Is there a way to make it so
> that a forward(50) command, at the edge, either raises an exception (at the
> wall) or simply doesn't move the turtle because of the limit?
> thanks!
> bb
> --
> Brian Blais
> bblais at bryant.edu
> http://web.bryant.edu/~bblais
> http://bblais.blogspot.com/
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig

More information about the Python-list mailing list