mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue 6340: update by Gregor Lingl of his tdemo_chaos demo program.
Functionally equivalent, clearer code, English comments.
This commit is contained in:
parent
5c3d40e0f3
commit
1666f19317
1 changed files with 24 additions and 28 deletions
|
@ -1,11 +1,13 @@
|
||||||
# Datei: chaosplotter.py
|
# File: tdemo_chaos.py
|
||||||
# Autor: Gregor Lingl
|
# Author: Gregor Lingl
|
||||||
# Datum: 31. 5. 2008
|
# Date: 2009-06-24
|
||||||
|
|
||||||
# Ein einfaches Programm zur Demonstration von "chaotischem Verhalten".
|
# A demonstration of chaos
|
||||||
|
|
||||||
from turtle import *
|
from turtle import *
|
||||||
|
|
||||||
|
N = 80
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
return 3.9*x*(1-x)
|
return 3.9*x*(1-x)
|
||||||
|
|
||||||
|
@ -15,47 +17,41 @@ def g(x):
|
||||||
def h(x):
|
def h(x):
|
||||||
return 3.9*x-3.9*x*x
|
return 3.9*x-3.9*x*x
|
||||||
|
|
||||||
def coosys():
|
def jumpto(x, y):
|
||||||
penup()
|
penup(); goto(x,y)
|
||||||
goto(-1,0)
|
|
||||||
pendown()
|
|
||||||
goto(n+1,0)
|
|
||||||
penup()
|
|
||||||
goto(0, -0.1)
|
|
||||||
pendown()
|
|
||||||
goto(-0.1, 1.1)
|
|
||||||
|
|
||||||
def plot(fun, start, farbe):
|
def line(x1, y1, x2, y2):
|
||||||
|
jumpto(x1, y1)
|
||||||
|
pendown()
|
||||||
|
goto(x2, y2)
|
||||||
|
|
||||||
|
def coosys():
|
||||||
|
line(-1, 0, N+1, 0)
|
||||||
|
line(0, -0.1, 0, 1.1)
|
||||||
|
|
||||||
|
def plot(fun, start, colour):
|
||||||
|
pencolor(colour)
|
||||||
x = start
|
x = start
|
||||||
pencolor(farbe)
|
jumpto(0, x)
|
||||||
penup()
|
|
||||||
goto(0, x)
|
|
||||||
pendown()
|
pendown()
|
||||||
dot(5)
|
dot(5)
|
||||||
for i in range(n):
|
for i in range(N):
|
||||||
x=fun(x)
|
x=fun(x)
|
||||||
goto(i+1,x)
|
goto(i+1,x)
|
||||||
dot(5)
|
dot(5)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global n
|
|
||||||
n = 80
|
|
||||||
ox=-250.0
|
|
||||||
oy=-150.0
|
|
||||||
ex= -2.0*ox / n
|
|
||||||
ey=300.0
|
|
||||||
|
|
||||||
reset()
|
reset()
|
||||||
setworldcoordinates(-1.0,-0.1, n+1, 1.1)
|
setworldcoordinates(-1.0,-0.1, N+1, 1.1)
|
||||||
speed(0)
|
speed(0)
|
||||||
hideturtle()
|
hideturtle()
|
||||||
coosys()
|
coosys()
|
||||||
plot(f, 0.35, "blue")
|
plot(f, 0.35, "blue")
|
||||||
plot(g, 0.35, "green")
|
plot(g, 0.35, "green")
|
||||||
plot(h, 0.35, "red")
|
plot(h, 0.35, "red")
|
||||||
|
# Now zoom in:
|
||||||
for s in range(100):
|
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!"
|
return "Done!"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue