Fix issue number in comment.
[python.git] / Demo / turtle / tdemo_chaos.py
blobd4656f8914858ff5185930ec2f382c64ddb646c9
1 # File: tdemo_chaos.py
2 # Author: Gregor Lingl
3 # Date: 2009-06-24
5 # A demonstration of chaos
7 from turtle import *
9 N = 80
11 def f(x):
12 return 3.9*x*(1-x)
14 def g(x):
15 return 3.9*(x-x**2)
17 def h(x):
18 return 3.9*x-3.9*x*x
20 def jumpto(x, y):
21 penup(); goto(x,y)
23 def line(x1, y1, x2, y2):
24 jumpto(x1, y1)
25 pendown()
26 goto(x2, y2)
28 def coosys():
29 line(-1, 0, N+1, 0)
30 line(0, -0.1, 0, 1.1)
32 def plot(fun, start, colour):
33 pencolor(colour)
34 x = start
35 jumpto(0, x)
36 pendown()
37 dot(5)
38 for i in range(N):
39 x=fun(x)
40 goto(i+1,x)
41 dot(5)
43 def main():
44 reset()
45 setworldcoordinates(-1.0,-0.1, N+1, 1.1)
46 speed(0)
47 hideturtle()
48 coosys()
49 plot(f, 0.35, "blue")
50 plot(g, 0.35, "green")
51 plot(h, 0.35, "red")
52 # Now zoom in:
53 for s in range(100):
54 setworldcoordinates(0.5*s,-0.1, N+1, 1.1)
55 return "Done!"
57 if __name__ == "__main__":
58 main()
59 mainloop()