问题
I am trying to draw a "Yellow" star by using module turtle. When I run my program on Windows OS, it works correctly. However, when I run it on macOS, the graphic is wrong. Result on macOS
Result on Windows OS
import turtle
# Setup a screen and a turtle
win = turtle.Screen()
bob = turtle.Turtle()
# set the background color for the flag
win.bgcolor("red")
# Draw a star
# change the turtle color to yellow
bob.color("yellow")
# to center we have to go backward for half of a side length
bob.penup()
bob.back(100)
bob.pendown()
bob.begin_fill()
for i in range(5):
bob.forward(200)
bob.right(144)
bob.end_fill()
win.exitonclick()
回答1:
This is not a turtle problem, but an issue with the underlying tkinter library. The fill on the two operating systems is different when there are crossing lines involved. The solution is to draw the star without crossing lines:
from turtle import Screen, Turtle
win = Screen()
win.bgcolor("red")
bob = Turtle()
bob.color("yellow")
bob.penup()
bob.goto(24.5, 33.1)
bob.pendown()
bob.begin_fill()
for i in range(5):
bob.forward(80)
bob.right(144)
bob.forward(80)
bob.left(72)
bob.end_fill()
bob.hideturtle()
win.exitonclick()
This should look the same on both implementations:
来源:https://stackoverflow.com/questions/55044046/turtle-graphic-begin-fill-function-does-not-work-correctly-on-mac