3
# [SNIPPET_NAME: Turtle Color Mixer]
4
# [SNIPPET_CATEGORIES: PyTurtle]
5
# [SNIPPET_DESCRIPTION: Use turtle to show a color mixing screen]
6
# [SNIPPET_DOCS: http://docs.python.org/library/turtle.html]
7
# [SNIPPET_AUTHOR: Grant Bowman <grantbow@ubuntu.com>]
8
# [SNIPPET_LICENSE: PSF]
11
from turtle import Screen, Turtle, mainloop
13
class ColorTurtle(Turtle):
15
def __init__(self, x, y):
18
self.resizemode("user")
24
self.color(self._color)
33
self.pencolor("gray25")
34
self.ondrag(self.shift)
36
def shift(self, x, y):
37
self.sety(max(0,min(y,1)))
38
self._color[self.x] = self.ycor()
39
self.fillcolor(self._color)
43
screen.bgcolor(red.ycor(), green.ycor(), blue.ycor())
46
global screen, red, green, blue
49
screen.setworldcoordinates(-1, -0.3, 3, 1.3)
51
red = ColorTurtle(0, .5)
52
green = ColorTurtle(1, .5)
53
blue = ColorTurtle(2, .5)
60
writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic")))
63
if __name__ == "__main__":