takluyver / mobilechelonian

Turtles on a notebook
Other
100 stars 37 forks source link

t.backward() going down instead of moving back #7

Closed ghost closed 7 years ago

ghost commented 7 years ago

I think there is a bug in the code of the method backward(). The turtle goes down, instead of moving back.

from mobilechelonian import Turtle
t = Turtle()
t.speed(5)

t.forward(100)
t.backward(100) 

image

takluyver commented 7 years ago

Weird. It looks like the code uses the same maths as forward(), but with the signs switched. Can you see the mistake?

ghost commented 7 years ago

I agree with you : it's weird. Il have looked into the code. I have not found the bug.

Another test

t.forward(100)
t.left(90)
t.backward(50)

That should give image

Bug it gives image

ghost commented 7 years ago

I think there's a problem of a quarter of turn.

I can't find the problem in the code because i don't understand what self.bearing means exactly, for example what means

I have seen the merge request #5 with a change between cos and sin.

There is at self.bearing = 90 at https://github.com/takluyver/mobilechelonian/blob/master/mobilechelonian/__init__.py#L38

takluyver commented 7 years ago

Bearing is like compass bearing: 0 means north (or upwards), 90 is east (right), and so on. self.bearing = 90 tells it to start pointing right.

Maybe it was fixed in #5 but the fix isn't released yet.

takluyver commented 7 years ago

I think #5 may well have fixed it - I've just made a 0.4 release, can you install it and have a go?

ghost commented 7 years ago

I upgraded to 0.4 release.

test 1 : ok

from mobilechelonian import Turtle
t = Turtle()
t.speed(5)

t.forward(100)
t.backward(100)

image

test 2 : ok

from mobilechelonian import Turtle
t = Turtle()
t.speed(5)

t.forward(100)
t.left(90)
t.backward(50)

image

Conclusion

I think the bug is fixed ! Thanks !

takluyver commented 7 years ago

Hooray! Thanks to @FranciscoMoya who fixed it :-)