summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-06-25 17:32:06 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-06-25 17:32:06 (GMT)
commitc7071671c93a529871260d7c5866aa86ca5411d3 (patch)
tree36e8b21b9135c5f250b8d12fcb9d11369a6a2f7d
parentfd851d3a3b038f31d8733a9102b70e17cb045ce4 (diff)
downloadcpython-c7071671c93a529871260d7c5866aa86ca5411d3.zip
cpython-c7071671c93a529871260d7c5866aa86ca5411d3.tar.gz
cpython-c7071671c93a529871260d7c5866aa86ca5411d3.tar.bz2
Merged revisions 73557 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r73557 | r.david.murray | 2009-06-25 13:29:39 -0400 (Thu, 25 Jun 2009) | 3 lines Issue 6340: update by Gregor Lingl of his tdemo_chaos demo program. Functionally equivalent, clearer code, English comments. ........
-rw-r--r--Demo/turtle/tdemo_chaos.py50
1 files changed, 23 insertions, 27 deletions
diff --git a/Demo/turtle/tdemo_chaos.py b/Demo/turtle/tdemo_chaos.py
index 55b4bbd..d4656f8 100644
--- a/Demo/turtle/tdemo_chaos.py
+++ b/Demo/turtle/tdemo_chaos.py
@@ -1,11 +1,13 @@
-# Datei: chaosplotter.py
-# Autor: Gregor Lingl
-# Datum: 31. 5. 2008
+# File: tdemo_chaos.py
+# Author: Gregor Lingl
+# Date: 2009-06-24
-# Ein einfaches Programm zur Demonstration von "chaotischem Verhalten".
+# A demonstration of chaos
from turtle import *
+N = 80
+
def f(x):
return 3.9*x*(1-x)
@@ -15,47 +17,41 @@ def g(x):
def h(x):
return 3.9*x-3.9*x*x
-def coosys():
- penup()
- goto(-1,0)
- pendown()
- goto(n+1,0)
- penup()
- goto(0, -0.1)
+def jumpto(x, y):
+ penup(); goto(x,y)
+
+def line(x1, y1, x2, y2):
+ jumpto(x1, y1)
pendown()
- goto(-0.1, 1.1)
+ goto(x2, y2)
-def plot(fun, start, farbe):
+def coosys():
+ line(-1, 0, N+1, 0)
+ line(0, -0.1, 0, 1.1)
+
+def plot(fun, start, colour):
+ pencolor(colour)
x = start
- pencolor(farbe)
- penup()
- goto(0, x)
+ jumpto(0, x)
pendown()
dot(5)
- for i in range(n):
+ for i in range(N):
x=fun(x)
goto(i+1,x)
dot(5)
def main():
- global n
- n = 80
- ox=-250.0
- oy=-150.0
- ex= -2.0*ox / n
- ey=300.0
-
reset()
- setworldcoordinates(-1.0,-0.1, n+1, 1.1)
+ 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)
-
+ setworldcoordinates(0.5*s,-0.1, N+1, 1.1)
return "Done!"
if __name__ == "__main__":