~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Demo/turtle/tdemo_chaos.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:52:42 UTC
  • mfrom: (39033.1.3 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609145242-9m268zc6u87rp1vp
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Datei: chaosplotter.py
 
2
# Autor: Gregor Lingl
 
3
# Datum: 31. 5. 2008
 
4
 
 
5
# Ein einfaches Programm zur Demonstration von "chaotischem Verhalten".
 
6
 
 
7
from turtle import *
 
8
 
 
9
def f(x):
 
10
    return 3.9*x*(1-x)
 
11
 
 
12
def g(x):
 
13
    return 3.9*(x-x**2)
 
14
 
 
15
def h(x):
 
16
    return 3.9*x-3.9*x*x
 
17
 
 
18
def coosys():
 
19
    penup()
 
20
    goto(-1,0)
 
21
    pendown()
 
22
    goto(n+1,0)
 
23
    penup()
 
24
    goto(0, -0.1)
 
25
    pendown()
 
26
    goto(-0.1, 1.1)
 
27
 
 
28
def plot(fun, start, farbe):
 
29
    x = start
 
30
    pencolor(farbe)
 
31
    penup()
 
32
    goto(0, x)
 
33
    pendown()
 
34
    dot(5)
 
35
    for i in range(n):
 
36
        x=fun(x)
 
37
        goto(i+1,x)
 
38
        dot(5)
 
39
 
 
40
def main():
 
41
    global n
 
42
    n = 80
 
43
    ox=-250.0
 
44
    oy=-150.0
 
45
    ex= -2.0*ox / n
 
46
    ey=300.0
 
47
 
 
48
    reset()
 
49
    setworldcoordinates(-1.0,-0.1, n+1, 1.1)
 
50
    speed(0)
 
51
    hideturtle()
 
52
    coosys()
 
53
    plot(f, 0.35, "blue")
 
54
    plot(g, 0.35, "green")
 
55
    plot(h, 0.35, "red")
 
56
    for s in range(100):
 
57
        setworldcoordinates(0.5*s,-0.1, n+1, 1.1)
 
58
 
 
59
    return "Done!"
 
60
 
 
61
if __name__ == "__main__":
 
62
    main()
 
63
    mainloop()