这是使用生成的 feigenbaum 图tkinter
。它来自“开书计划”,可视化混乱。
程序源在这里;我将其转换为 python 3 并将其发布在下面。阅读和理解这段代码需要你学习很多东西。
#
# chaos-3.py
#
# Build Feigenbaum Logistic map. Input start and end K
#
# python chaos-3.py 3.4 3.9
#
canWidth=500
canHeight=500
def setupWindow () :
global win, canvas
from tkinter import Tk, Canvas, Frame
win = Tk()
canvas = Canvas(win, height=canHeight, width=canWidth)
f = Frame (win)
canvas.pack()
f.pack()
def startApp () :
global win, canvas
import sys
# k1 = float(sys.argv[1]) # starting value of K
# k2 = float(sys.argv[2]) # ending value of K
x = .2 # is somewhat arbitrary
vrng = range(200) # We'll do 200 horz steps
for t in range(canWidth) :
win.update()
k = k1 + (k2-k1)*t/canWidth
# print("K = %.04f" % k)
for i in vrng :
p = x*canHeight
canvas.create_line(t,p,t,p+1) # just makes a pixel dot
x = x * (1-x) * k # next x value
if x <=0 or x >= 1.0 :
# print("overflow at k", k)
return
def main () :
setupWindow() # Create Canvas with Frame
startApp() # Start up the display
win.mainloop() # Just wait for user to close graph
k1 = 2.9
k2 = 3.8
main()