summaryrefslogtreecommitdiffstats
path: root/Lib/turtledemo/colormixer.py
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-11-01 17:39:37 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-11-01 17:39:37 (GMT)
commitea13d9d86bf62c6f1d2ba0cc7cc7f9a7c0683e47 (patch)
treec2184842b163da5df6fd30c671c62083c73cb100 /Lib/turtledemo/colormixer.py
parent8291af2354d194fd60079380367f4ecb0eba5397 (diff)
downloadcpython-ea13d9d86bf62c6f1d2ba0cc7cc7f9a7c0683e47.zip
cpython-ea13d9d86bf62c6f1d2ba0cc7cc7f9a7c0683e47.tar.gz
cpython-ea13d9d86bf62c6f1d2ba0cc7cc7f9a7c0683e47.tar.bz2
Issue #10199: Moved Demo/turtle under Lib/
Diffstat (limited to 'Lib/turtledemo/colormixer.py')
-rw-r--r--Lib/turtledemo/colormixer.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/Lib/turtledemo/colormixer.py b/Lib/turtledemo/colormixer.py
new file mode 100644
index 0000000..f5d308d
--- /dev/null
+++ b/Lib/turtledemo/colormixer.py
@@ -0,0 +1,60 @@
+# colormixer
+
+from turtle import Screen, Turtle, mainloop
+import sys
+sys.setrecursionlimit(20000) # overcomes, for now, an instability of Python 3.0
+
+class ColorTurtle(Turtle):
+
+ def __init__(self, x, y):
+ Turtle.__init__(self)
+ self.shape("turtle")
+ self.resizemode("user")
+ self.shapesize(3,3,5)
+ self.pensize(10)
+ self._color = [0,0,0]
+ self.x = x
+ self._color[x] = y
+ self.color(self._color)
+ self.speed(0)
+ self.left(90)
+ self.pu()
+ self.goto(x,0)
+ self.pd()
+ self.sety(1)
+ self.pu()
+ self.sety(y)
+ self.pencolor("gray25")
+ self.ondrag(self.shift)
+
+ def shift(self, x, y):
+ self.sety(max(0,min(y,1)))
+ self._color[self.x] = self.ycor()
+ self.fillcolor(self._color)
+ setbgcolor()
+
+def setbgcolor():
+ screen.bgcolor(red.ycor(), green.ycor(), blue.ycor())
+
+def main():
+ global screen, red, green, blue
+ screen = Screen()
+ screen.delay(0)
+ screen.setworldcoordinates(-1, -0.3, 3, 1.3)
+
+ red = ColorTurtle(0, .5)
+ green = ColorTurtle(1, .5)
+ blue = ColorTurtle(2, .5)
+ setbgcolor()
+
+ writer = Turtle()
+ writer.ht()
+ writer.pu()
+ writer.goto(1,1.15)
+ writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic")))
+ return "EVENTLOOP"
+
+if __name__ == "__main__":
+ msg = main()
+ print(msg)
+ mainloop()