Joost
Joost

Reputation: 4134

Python turtlegraphics inconsistency between different OS's

I'm drawing a fairly simple shape using Python's turtle module and the code below:

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

Strangely enough, this produces two different results on Windows (left) and all other OS's I've tried (Ubuntu, Arch, OSX). Areas with an even number of overlapping fillings are still filled on Windows, but blanked out again for others. Can anyone explain me what the reason for this is, and if there is any way to influence it? It seems weird that this behaviour would be so inconsistent.

enter image description here enter image description here

It seems that this is a design choice as well; it is not immediately obvious to me which of the two is the 'correct' version.

Upvotes: 3

Views: 91

Answers (1)

Terry Jan Reedy
Terry Jan Reedy

Reputation: 19154

The issue is whether 'fill' means 'color' or 'switch color' on a particular system. To color twice is to color. To switch twice is to not switch. (This pair is the basis of Spencer Brown's "Laws of Form".) Turtle is implemented on top of Tkinter. Here is a simple Tkinter program that reproduces the left figure on Windows (though without the black lines, which turtle adds). I strongly suspect that you would get the right figure on *nix (I don't have one at the moment).

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

If so, then I suspect the different is a result of the underlying graphics system and which interpretation it gives to 'fill'.

I looked in the tk manual but found nothing about the meaning of filling twice, just '-fill color'.

Upvotes: 1

Related Questions