~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Demo/turtle/tdemo_chaos.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-07-23 18:52:17 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090723185217-orj9vm2mappvz4ze
Tags: 3.1-0ubuntu1
* Python 3.1 final release.
* Update to the 3.1 release branch, 20090723.
* Add explicit build dependency on tk8.5-dev.

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
 
1
# File: tdemo_chaos.py
 
2
# Author: Gregor Lingl
 
3
# Date: 2009-06-24
4
4
 
5
 
# Ein einfaches Programm zur Demonstration von "chaotischem Verhalten".
 
5
# A demonstration of chaos
6
6
 
7
7
from turtle import *
8
8
 
 
9
N = 80
 
10
 
9
11
def f(x):
10
12
    return 3.9*x*(1-x)
11
13
 
15
17
def h(x):
16
18
    return 3.9*x-3.9*x*x
17
19
 
 
20
def jumpto(x, y):
 
21
    penup(); goto(x,y)
 
22
 
 
23
def line(x1, y1, x2, y2):
 
24
    jumpto(x1, y1)
 
25
    pendown()
 
26
    goto(x2, y2)
 
27
 
18
28
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)
 
29
    line(-1, 0, N+1, 0)
 
30
    line(0, -0.1, 0, 1.1)
27
31
 
28
 
def plot(fun, start, farbe):
 
32
def plot(fun, start, colour):
 
33
    pencolor(colour)
29
34
    x = start
30
 
    pencolor(farbe)
31
 
    penup()
32
 
    goto(0, x)
 
35
    jumpto(0, x)
33
36
    pendown()
34
37
    dot(5)
35
 
    for i in range(n):
 
38
    for i in range(N):
36
39
        x=fun(x)
37
40
        goto(i+1,x)
38
41
        dot(5)
39
42
 
40
43
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
44
    reset()
49
 
    setworldcoordinates(-1.0,-0.1, n+1, 1.1)
 
45
    setworldcoordinates(-1.0,-0.1, N+1, 1.1)
50
46
    speed(0)
51
47
    hideturtle()
52
48
    coosys()
53
49
    plot(f, 0.35, "blue")
54
50
    plot(g, 0.35, "green")
55
51
    plot(h, 0.35, "red")
 
52
    # Now zoom in:
56
53
    for s in range(100):
57
 
        setworldcoordinates(0.5*s,-0.1, n+1, 1.1)
58
 
 
 
54
        setworldcoordinates(0.5*s,-0.1, N+1, 1.1)
59
55
    return "Done!"
60
56
 
61
57
if __name__ == "__main__":