donkirkby / live-py-plugin

Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser
https://donkirkby.github.io/live-py-plugin
MIT License
291 stars 57 forks source link

Turtle mode #351

Closed donkirkby closed 1 year ago

donkirkby commented 2 years ago

Implement the mode() method on the screen class. Looks like there's already support in TNavigator, you just have to call t._setmode() for all active mock turtles. Check whether the module method is properly wired to call the screen method.

The mode() method came for free with #353, but there's something wrong with the setworldcoordinates() method. If you've already changed to world mode, the shift doesn't look the same as for the regular turtle. If you haven't changed to world mode, you get this error:

AttributeError: 'Canvas' object has no attribute 'find_all'

evelyndai commented 1 year ago

I'd like to be assigned to this ticket. Thank you!

donkirkby commented 1 year ago

I took a closer look at setworldcoordinates(), @evelyndai, and I realized it's not a bug. Here's the example from the docs we were looking at:

import turtle as t

t.getscreen().reset()
t.getscreen().setworldcoordinates(-50,-7.5,50,7.5)

for _ in range(8):
    t.left(45)
    t.fd(2)   # a regular octagon

t.done()

That makes the lower left corner (-50, -7.5), and the upper right corner (50, 7.5), no matter what the size of the window is. When you run that code in PyCharm with live coding, you can then resize the window and the aspect ratio will change as you drag the window corner around.

I was worried that my live turtle drew the octagon with a different aspect ratio from the standard library's turtle, but that's only because the window was a different size. When I made the windows the same size, the octagons looked the same.

So, if you're happy with your fix to find_all(), I'll merge your branch in.

Thanks again for participating in the sprint.

donkirkby commented 1 year ago

I got confused, and now I see that I already merged your branch during the sprint. Closing this issue now.