summaryrefslogtreecommitdiffstats
path: root/Lib/turtledemo/chaos.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/chaos.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/chaos.py')
-rw-r--r--Lib/turtledemo/chaos.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/Lib/turtledemo/chaos.py b/Lib/turtledemo/chaos.py
new file mode 100644
index 0000000..d4656f8
--- /dev/null
+++ b/Lib/turtledemo/chaos.py
@@ -0,0 +1,59 @@
+# File: tdemo_chaos.py
+# Author: Gregor Lingl
+# Date: 2009-06-24
+
+# A demonstration of chaos
+
+from turtle import *
+
+N = 80
+
+def f(x):
+ return 3.9*x*(1-x)
+
+def g(x):
+ return 3.9*(x-x**2)
+
+def h(x):
+ return 3.9*x-3.9*x*x
+
+def jumpto(x, y):
+ penup(); goto(x,y)
+
+def line(x1, y1, x2, y2):
+ jumpto(x1, y1)
+ pendown()
+ goto(x2, y2)
+
+def coosys():
+ line(-1, 0, N+1, 0)
+ line(0, -0.1, 0, 1.1)
+
+def plot(fun, start, colour):
+ pencolor(colour)
+ x = start
+ jumpto(0, x)
+ pendown()
+ dot(5)
+ for i in range(N):
+ x=fun(x)
+ goto(i+1,x)
+ dot(5)
+
+def main():
+ reset()
+ setworldcoordinates(-1.0,-0.1, N+1, 1.1)
+ speed(0)
+ hideturtle()
+ coosys()
+ plot(f, 0.35, "blue")
+ plot(g, 0.35, "green")
+ plot(h, 0.35, "red")
+ # Now zoom in:
+ for s in range(100):
+ setworldcoordinates(0.5*s,-0.1, N+1, 1.1)
+ return "Done!"
+
+if __name__ == "__main__":
+ main()
+ mainloop()