[Edu-sig] some turtle questions
Alf P. Steinbach
alfps at start.no
Sun Jan 24 15:44:36 EST 2010
* Helene Martin:
> I'm almost sure that there's no way for a turtle to know anything
> about the background. That's an unfortunate limitation!
The "background" for the turtle is just a Tkinter canvas. So yes, it's
technically possible to inspect things there, since there is method to obtain
the canvas. But unfortunately the canvas is not a bitmapped picture: it just
maintains a list of objects to draw (vector graphics, metafile graphics).
And so there's no practical way to obtain the "current screen pixel color" as
Brian asks for: there are no pixels in that canvas...
Blatant plug: I included some perhaps interesting turtle examples in ch 2 of my
writings at <url: http://tinyurl.com/programmingbookP3>. It starts with some
silly figures, then graph drawing, then some recursive figures (idealized tree,
C-curve, dragoncurve).
Helene: since I'm not on the original list, could you perhaps forward to that
list or to the original poster?
Thanks,
- Alf
> 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).
>
> Best,
>
> Hélène.
> Computer Science Teacher
> Garfield High School
> http://garfieldcs.com
>
> 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!
More information about the Python-list
mailing list