Open GoogleCodeExporter opened 9 years ago
I've been thinking about this. It's certainly useful, but it's going to be
tricky.
Things don't actually get drawn when commands are executed. They get pushed on
to a stack of draw commands that are executed at a later time.
So, when one pynguin says collides(x) it needs to return an answer right now,
but the answer now may be different from the answer when things actually get
around to getting drawn.
So, this would need to introduce some kind of a synchronization to work
reliably.
That said, a simple version should not be too difficult. It would probably work
for your maze example. You would draw your maze completely, and only after it
was finished send in a pynguin to explore the maze.
If you want to give it a try, look at something around here:
http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qgraphicsscene.html#ite
mAt
Original comment by miss...@hotmail.com
on 15 Jul 2010 at 5:49
http://code.google.com/r/aresnickety-pynguin/source/detail?r=57f601ab1d21f4a8bfe
310785a85e799e9f0a27e is a start; amazingly, I couldn't figure out how to
request a code review directly.
Original comment by aresnick...@gmail.com
on 18 Jul 2010 at 2:12
The way I did it is terrible and fragile, it turns out =) I think instead I
want an event for intersection, and also to be able to choose whether or not to
pay attention to the path the turtle is drawing (as part of the intersection
code). Also, there are weird artifacts with choosing resolution and step size
that mean that it doesn't always perform as expected.
Original comment by aresnick...@gmail.com
on 18 Jul 2010 at 1:56
> I didn't see an easy way to check if an Element was drawn yet
If it has not been drawn yet, then it just won't be there at all.
> choosing resolution and step size
When looking for an intersection, you'd definitely need to use a
small forward() step for each move.
If you're willing to wait for things to get drawn, maybe you could
draw, check for intersections, and then back up to the point where
the intersection actually occurred.
Thinking about it some more, I wonder if you might also run in to
trouble because you will be running GUI code from the non-GUI thread.
It's an interesting puzzle. It would be nice to get it working right.
Original comment by miss...@hotmail.com
on 18 Jul 2010 at 7:25
Try after Revision d60de268743f
There is a new pynguin method colorat() that should return the color at the
spot where the pynguin is currently.
It is not pulled in to the default functions yet, so you will need to use:
p.colorat()
If you are checking this function repeatedly, it also slows down progress
greatly. It works, but there may be a better way to do this...
Original comment by miss...@hotmail.com
on 16 Aug 2011 at 4:19
Original issue reported on code.google.com by
aresnick...@gmail.com
on 15 Jul 2010 at 4:51