How To Properly Interact With Turtle Canvas/screen Sizing?
I am attempting to draw some images using Python Turtle and the screen sizing/canvas sizing is eluding me. Here is what I have to create the current image: import turtle import mat
Solution 1:
You've a couple of flaws in your logic. First, you call tracer(False)
but never call screen.update()
when you finish drawing, which is why your circle is incomplete.
Second, although turtle crawls atop tkinter, it uses a different default coordinate system than Canvas
. So we need to adjust for that in our Canvas.postscript()
method invocation:
from turtle import Turtle, Screen
WIDTH, HEIGHT = 15_000, 15_000
fileName = "test"
screen = Screen()
screen.setup(WIDTH, HEIGHT)
screen.tracer(False)
turtle = Turtle()
turtle.hideturtle()
turtle.pensize(5)
turtle.penup()
turtle.goto(-WIDTH/2, -HEIGHT/2)
turtle.begin_fill()
for _ inrange(2):
turtle.forward(WIDTH)
turtle.left(90)
turtle.forward(HEIGHT)
turtle.left(90)
turtle.end_fill()
turtle.goto(0, -HEIGHT/4)
turtle.pencolor('white')
turtle.pendown()
turtle.circle(HEIGHT/4)
screen.update()
canvas = screen.getcanvas()
canvas.postscript(file=fileName + ".eps", width=WIDTH, height=HEIGHT, x=-WIDTH/2, y=-HEIGHT/2)
You'll note that the image width/height (not fully shown above) is 200 inches, which is the inch equivalent of 15_000 points (using 75 points per inch instead of 72.)
I leave the final step of conversion to JPG to you.
Post a Comment for "How To Properly Interact With Turtle Canvas/screen Sizing?"