blob: f5d308d443055fcfb5411e71719ac24b06aa6631 [file] [log] [blame]
Martin v. Löwis97cf99f2008-06-10 04:44:07 +00001# colormixer
2
Martin v. Löwis60ebb8b2008-09-21 07:32:10 +00003from turtle import Screen, Turtle, mainloop
Martin v. Löwis97cf99f2008-06-10 04:44:07 +00004import sys
5sys.setrecursionlimit(20000) # overcomes, for now, an instability of Python 3.0
6
7class ColorTurtle(Turtle):
8
9 def __init__(self, x, y):
10 Turtle.__init__(self)
11 self.shape("turtle")
12 self.resizemode("user")
13 self.shapesize(3,3,5)
14 self.pensize(10)
15 self._color = [0,0,0]
16 self.x = x
17 self._color[x] = y
18 self.color(self._color)
19 self.speed(0)
20 self.left(90)
21 self.pu()
22 self.goto(x,0)
23 self.pd()
24 self.sety(1)
25 self.pu()
26 self.sety(y)
27 self.pencolor("gray25")
28 self.ondrag(self.shift)
29
30 def shift(self, x, y):
31 self.sety(max(0,min(y,1)))
32 self._color[self.x] = self.ycor()
33 self.fillcolor(self._color)
34 setbgcolor()
35
36def setbgcolor():
37 screen.bgcolor(red.ycor(), green.ycor(), blue.ycor())
38
39def main():
40 global screen, red, green, blue
41 screen = Screen()
42 screen.delay(0)
43 screen.setworldcoordinates(-1, -0.3, 3, 1.3)
44
45 red = ColorTurtle(0, .5)
46 green = ColorTurtle(1, .5)
47 blue = ColorTurtle(2, .5)
48 setbgcolor()
49
50 writer = Turtle()
51 writer.ht()
52 writer.pu()
53 writer.goto(1,1.15)
54 writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic")))
55 return "EVENTLOOP"
56
57if __name__ == "__main__":
58 msg = main()
59 print(msg)
60 mainloop()