Python turtlegraphics不同OS之间的不一致

时间:2015-11-05 08:20:37

标签: python turtle-graphics graph-coloring

我使用Python的turtle模块和下面的代码绘制了一个相当简单的形状:

import turtle

turtle.color('black', '#fef00e')
turtle.begin_fill()
turtle.left(180)
turtle.forward(100)
for i in range(5):
    turtle.right(90)
    turtle.forward(100+50*i)
turtle.end_fill()
turtle.done()

奇怪的是,这会在Windows上生成两个不同的结果(左)和我尝试过的所有其他操作系统(Ubuntu,Arch,OSX)。在Windows上仍然填充具有偶数重叠填充的区域,但是对于其他区域再次消隐。任何人都可以解释一下这是什么原因,以及是否有任何影响它的方法?这种行为如此不一致似乎很奇怪。

enter image description here enter image description here

这似乎也是一种设计选择;对我来说,这两个中哪一个是“正确的”版本并不是很明显。

1 个答案:

答案 0 :(得分:1)

问题在于是否填写'意味着颜色'或者'切换颜色'在特定的系统上。要着色两次就是着色。要切换两次是不切换。 (这对是Spencer Brown" Form of Form"的基础。)Turtle是在Tkinter之上实现的。这是一个简单的Tkinter程序,可以在Windows上重现左图(虽然没有黑色线条,乌龟添加)。我强烈怀疑你会在* nix上得到正确的数字(我现在没有。)

from tkinter import *
root = Tk()
canv = Canvas(root, width=800, height=800)
canv.pack()
l = canv.create_polygon(
        500,400, 400,400, 400,300, 550,300,
        550,500, 300,500, 300,200, 500,400, fill='yellow')
root.mainloop()

如果是这样,那么我怀疑不同的是底层图形系统的结果以及它给予填充的解释。

我查看了tk manual,但没有发现填充两次的含义,只是' -fill color'。

相关问题