Re: [Edu-sig] some turtle questions

2010-01-25 Thread kirby urner
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 bbl...@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
 bbl...@bryant.edu
 http://web.bryant.edu/~bblais
 http://bblais.blogspot.com/




 ___
 Edu-sig mailing list
 edu-...@python.org
 http://mail.python.org/mailman/listinfo/edu-sig


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] some turtle questions

2010-01-24 Thread 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 bbl...@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
 bbl...@bryant.edu
 http://web.bryant.edu/~bblais
 http://bblais.blogspot.com/



 ___
 Edu-sig mailing list
 edu-...@python.org
 http://mail.python.org/mailman/listinfo/edu-sig


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Edu-sig] some turtle questions

2010-01-24 Thread Alf P. Steinbach

* 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 bbl...@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!

--
http://mail.python.org/mailman/listinfo/python-list