Martin v. Löwis | 97cf99f | 2008-06-10 04:44:07 +0000 | [diff] [blame] | 1 | # Datei: chaosplotter.py |
| 2 | # Autor: Gregor Lingl |
| 3 | # Datum: 31. 5. 2008 |
| 4 | |
| 5 | # Ein einfaches Programm zur Demonstration von "chaotischem Verhalten". |
| 6 | |
Martin v. Löwis | 60ebb8b | 2008-09-21 07:32:10 +0000 | [diff] [blame] | 7 | from turtle import * |
Martin v. Löwis | 97cf99f | 2008-06-10 04:44:07 +0000 | [diff] [blame] | 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() |