-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogistic_map_tkinter.py
More file actions
40 lines (36 loc) · 1.41 KB
/
logistic_map_tkinter.py
File metadata and controls
40 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# bifurcation diagram of logistic map
# https://en.wikipedia.org/wiki/Logistic_map
# https://en.wikipedia.org/wiki/Bifurcation_diagram
# the diagram is plotted using tkinter which comes with CPython
#
import tkinter as tk
# parameters
screen_width = 1600; screen_height = 1000 # image size in pixels
a_start = 3.5; a_end = 4.0 # interval parameter a
log_map_scale_factor = 15 # makes map appear brighter
number_iterations = 2000 # number of iterations on logistic formula
# make tkinter and canvas objects
root = tk.Tk()
root.title("Logistic map using Python and Tkinter")
canvas1 = tk.Canvas(root, background = "black",
height = screen_height, width = screen_width)
canvas1.pack()
# calculating and plotting logistic map
a_span = a_end - a_start
for x in range(screen_width):
a = a_start + a_span * x / (screen_width - 1)
z = 0.5
log_map_lst = [0] * screen_height
for _ in range(number_iterations):
z = a * z *(1 - z)
log_map_lst[ int(z * (screen_height - 1)) ] += 1
for y in range(screen_height):
col = min(255, log_map_lst[y] * log_map_scale_factor)
col_str = f"#{col:02X}{col:02X}{col:02X}"
canvas1.create_line(x, screen_height - y - 1, x + 1, screen_height - y - 1,
fill = col_str)
if x % 50 == 0:
canvas1.update() # each 50 cycles show updated canvas
# plotting finished, window shows
canvas1.update()
tk.mainloop()