Reputation: 948
first time posting a question here. I am attempting to recreate the classic pong game in Python using turtle graphics. However, I've noticed something strange and I'm not quite sure if this is a bug or an error I've made. I created a paddle class that takes in a positional argument. I've set the right paddle and left paddle to 350 and -350 on the X-axis respectively. My screen size is 800 in width and 600 in height. However, the left paddle seems to be further away from the edge of the screen than the right paddle. It's slight, but it's definitely there. As you can see in the image here.
Upvotes: 0
Views: 216
Reputation: 41905
The hierarchy of canvas classes, that standalone turtle is built atop, introduces chrome: borders, title bar, scroll bars, etc. The drawing area is slightly smaller than the requested window size. And this likely varies by platform (e.g. Unix vs. Windows).
To draw a red square right against the borders of an 800 x 600 window, I have to introduce some fudge factors to make it fit on my system:
from turtle import Screen, Turtle
screen = Screen()
screen.setup(800, 600)
turtle = Turtle()
turtle.color('red')
turtle.penup()
turtle.goto(2 - 400, 11 - 300)
turtle.pendown()
for _ in range(2):
turtle.forward(800 - 13)
turtle.left(90)
turtle.forward(600 - 13)
turtle.left(90)
screen.exitonclick()
There's more chrome overhead in the Y dimension due to the title bar. I don't know of anyway within turtle to calculate this -- one might be able to do so by dropping down to the underlying tkinter library.
Or simply live with it.
Upvotes: 0