海龟图形 begin_fill() 函数在 MAC 上无法正常工作 [英] Turtle graphic begin_fill() function does not work correctly on MAC

查看:38
本文介绍了海龟图形 begin_fill() 函数在 MAC 上无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用模块乌龟绘制一个黄色"星星.当我在 Windows 操作系统上运行我的程序时,它可以正常工作.但是,当我在 macOS 上运行它时,图形是错误的.

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()

解决方案

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:

这篇关于海龟图形 begin_fill() 函数在 MAC 上无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆