Skip to content

Instantly share code, notes, and snippets.

@iuriguilherme
Last active January 25, 2023 19:46
Show Gist options
  • Save iuriguilherme/7b5843bf3a78850d859d384002b6871d to your computer and use it in GitHub Desktop.
Save iuriguilherme/7b5843bf3a78850d859d384002b6871d to your computer and use it in GitHub Desktop.
Spiral Minimal Example to break TurtleScreen
"""
Spiral Minimal Example v3
"""
import tkinter
import turtle
i = 1
## YMMV
## j = 2 will raise `ZeroDivisionError: float division by zero` because screen scale is zero
j = 2
## j = 3 will raise `_tkinter.TclError: expected floating-point number but got "floating"` because turtle.pos() will be (inf, inf) which is NaN and tk.getdouble() can't handle it
#j = 3
## j = 4 will raise `OverflowError: int too large to convert to float` because it will be too large for turtle.forward()
#j = 4
root = tkinter.Tk()
canvas = tkinter.Canvas(root)
canvas.pack(expand = True, fill = 'both')
screen = turtle.TurtleScreen(canvas)
screen.mode('world')
screen.tracer(int(3e6))
pen = turtle.RawTurtle(screen)
while True:
pen.forward(i)
pen.left(90)
pen.forward(i)
pen.right(90)
pos = pen.pos()
print(f"\ni: {i}\nj: {j}\nscreen scale:\n\tx = {screen.xscale}\n\ty = {screen.yscale}\nturtle position:\n\tx = {pos[0]}\n\ty = {pos[1]}\n")
screen.setworldcoordinates(llx = -pos[0], lly = -pos[1], urx = pos[0], ury = pos[1])
i *= j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment