some turtle questions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

some turtle questions

Brian Blais
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!



_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: some turtle questions

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!

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 <[hidden email]> 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
> [hidden email]
> http://web.bryant.edu/~bblais
> http://bblais.blogspot.com/
>
>
>
> _______________________________________________
> Edu-sig mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: some turtle questions

kirby urner-4
In reply to this post by Brian Blais
Hi Brian --
 
If you wanna go to a lot of work, but not a huge amount, write wrapper class for the Standard Library turtle that intercepts its commands and updates an on-board data structure, representing pixels x pixels, specifying self position, keep color info stashed per each one.  That's a lot of data, depending on screen resolution.  Consider a thick line option if you have one, make your turtle "wide body".  Or stay with thin.
 
So then if you go turtle.forward(10) you will send it to your self-made forward method.  Stop and smell the pixels, see what color was stashed there, either by another turtle (! -- shared data structure) or by this turtle, or maybe it's still the default untrammeled color.
 
You can add new methods, like "glide" or "explode" that translate to the underlying turtle somehow -- use your imagination.
 
Kirby


 
On Sun, Jan 24, 2010 at 7:29 AM, Brian Blais <[hidden email]> 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!



_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig



_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig
Reply | Threaded
Open this post in threaded view
|

Re: some turtle questions

Daniel Ajoy-2
In reply to this post by Brian Blais
On Mon, 25 Jan 2010 06:00:01 -0500, <[hidden email]> wrote:

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

In FMSLogo:

PIXEL

Description
Outputs a three element list of numbers that represent the red, green, and blue intensity of the pixel currently under the turtle.


> 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).


In FMSLogo:

WINDOW

Description
Tells the turtle to enter "window" mode. From now on, if the turtle is asked to move past the boundary of the graphics window, it will move off screen. The visible graphics window is considered as just part of an infinite graphics plane; the turtle can be anywhere on the plane.

WRAP

Description
Tells the turtle to enter "wrap" mode. From now on, if the turtle is asked to move past the boundary of the graphics window, it will "wrap around" and reappear at the opposite edge of the window. The top edge wraps to the bottom edge, while the left edge wraps to the right edge. (So the window is topologically equivalent to a torus.) This is the turtle's initial mode.


FENCE
Description
Tells the turtle to enter "fence" mode. From now on, if the turtle is asked to move past the boundary of the graphics window, it will move as far as it can and then stop at the edge with an "out of bounds" error message.

Daniel
http://sourceforge.net/projects/fmslogo/files/

_______________________________________________
Edu-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/edu-sig