1 | n/a | # colormixer |
---|
2 | n/a | |
---|
3 | n/a | from turtle import Screen, Turtle, mainloop |
---|
4 | n/a | |
---|
5 | n/a | class ColorTurtle(Turtle): |
---|
6 | n/a | |
---|
7 | n/a | def __init__(self, x, y): |
---|
8 | n/a | Turtle.__init__(self) |
---|
9 | n/a | self.shape("turtle") |
---|
10 | n/a | self.resizemode("user") |
---|
11 | n/a | self.shapesize(3,3,5) |
---|
12 | n/a | self.pensize(10) |
---|
13 | n/a | self._color = [0,0,0] |
---|
14 | n/a | self.x = x |
---|
15 | n/a | self._color[x] = y |
---|
16 | n/a | self.color(self._color) |
---|
17 | n/a | self.speed(0) |
---|
18 | n/a | self.left(90) |
---|
19 | n/a | self.pu() |
---|
20 | n/a | self.goto(x,0) |
---|
21 | n/a | self.pd() |
---|
22 | n/a | self.sety(1) |
---|
23 | n/a | self.pu() |
---|
24 | n/a | self.sety(y) |
---|
25 | n/a | self.pencolor("gray25") |
---|
26 | n/a | self.ondrag(self.shift) |
---|
27 | n/a | |
---|
28 | n/a | def shift(self, x, y): |
---|
29 | n/a | self.sety(max(0,min(y,1))) |
---|
30 | n/a | self._color[self.x] = self.ycor() |
---|
31 | n/a | self.fillcolor(self._color) |
---|
32 | n/a | setbgcolor() |
---|
33 | n/a | |
---|
34 | n/a | def setbgcolor(): |
---|
35 | n/a | screen.bgcolor(red.ycor(), green.ycor(), blue.ycor()) |
---|
36 | n/a | |
---|
37 | n/a | def main(): |
---|
38 | n/a | global screen, red, green, blue |
---|
39 | n/a | screen = Screen() |
---|
40 | n/a | screen.delay(0) |
---|
41 | n/a | screen.setworldcoordinates(-1, -0.3, 3, 1.3) |
---|
42 | n/a | |
---|
43 | n/a | red = ColorTurtle(0, .5) |
---|
44 | n/a | green = ColorTurtle(1, .5) |
---|
45 | n/a | blue = ColorTurtle(2, .5) |
---|
46 | n/a | setbgcolor() |
---|
47 | n/a | |
---|
48 | n/a | writer = Turtle() |
---|
49 | n/a | writer.ht() |
---|
50 | n/a | writer.pu() |
---|
51 | n/a | writer.goto(1,1.15) |
---|
52 | n/a | writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic"))) |
---|
53 | n/a | return "EVENTLOOP" |
---|
54 | n/a | |
---|
55 | n/a | if __name__ == "__main__": |
---|
56 | n/a | msg = main() |
---|
57 | n/a | print(msg) |
---|
58 | n/a | mainloop() |
---|