takluyver / mobilechelonian

Turtles on a notebook
Other
100 stars 37 forks source link

The turtle doesn't seem to be able to round... #9

Open choldgraf opened 7 years ago

choldgraf commented 7 years ago

If you give it a left or right command that has lots of decimals, then the turtle performs this action, but hangs and will not respond to commands afterwards.

In my case, I can recreate this by:

won't work

t.right(40.435435)
t.forward(60)

will work

t.right(np.round(40.435435))
t.forward(60)
takluyver commented 7 years ago

I think it's this line that decides when it has reached one point, so that it can go onto the next. You're probably running into floating point issues. Maybe it needs to check with a tolerance.

t3rodrig commented 6 years ago

I have the same problem:

bob = Turtle()
n = 7
ang = round(360/n, 1)
ds = 50
for i in range(2):
    bob.forward(ds)
    bob.left(ang)

does not work properly. The angle has just 1 decimal number, but the turtle does not draw the second line.

takluyver commented 6 years ago

I think the turtle's angle changes in steps, and it overshoots the correct angle and then gets stuck turning one degree left and one degree right. Here's the code for that:

https://github.com/takluyver/mobilechelonian/blob/0.5/mobilechelonian/mobilechelonianjs/turtlewidget.js#L232-L248

Pull requests welcome :-)

ghost commented 5 years ago

I would like to speed up drawing circle I use speed(10) method but not work. As I know, drawing circle is using n-side line to finish this job speed method only can help line section. why?