Turtle graphic begin_fill() function does not work correctly on MAC

蹲街弑〆低调 提交于 2021-01-27 23:18:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!