7cc4c4ce2191d09d7f285475727f97991558039b

Author
Pavle Portic <pavle.portic@tilda.center>
Committer
Pavle Portic <pavle.portic@tilda.center>
Date

Message

Print number of total iterations on the current frame

Diff

 1diff --git a/mandelbrot.py b/mandelbrot.py
 2index ab36e78ca80b765f4097065b3f758d247b8e9865..93f1f60846208446b14045672d2540274918aeaa 100644
 3--- a/mandelbrot.py
 4+++ b/mandelbrot.py
 5@@ -13,6 +13,7 @@ import curses
 6 import colors
 7 
 8 MAX_ITERS = 100
 9+ITERATIONS = 0
10 COLOR_COUNT = 101
11 MONOCHROME = False
12 ZOOM_LEVEL = 0
13@@ -33,8 +34,10 @@ def get_points(cols, rows):
14 
15 
16 def calculate_point(x, y):
17+	global ITERATIONS
18 	z = 0
19 	for i in range(MAX_ITERS):
20+		ITERATIONS += 1
21 		z = z ** 2 + complex(x, y)
22 		if abs(z) >= 2:
23 			return i
24@@ -43,6 +46,8 @@ def calculate_point(x, y):
25 
26 
27 def calculate_set(cols, rows):
28+	global ITERATIONS
29+	ITERATIONS = 0
30 	x, y = get_points(cols, rows)
31 	matrix = np.zeros([rows, cols])
32 	for i in range(rows):
33@@ -64,7 +69,7 @@ def print_set(screen, cols, rows, matrix, char):
34 				color_index = 2 if color_index < 2 else color_index
35 				screen.addstr(i, j, ' ', curses.color_pair(color_index))
36 
37-	screen.addstr(rows, 0, f'Iterations: {MAX_ITERS}, Zoom: {ZOOM_LEVEL}, Char: {char}', curses.color_pair(COLOR_COUNT))
38+	screen.addstr(rows, 0, f'Max Iterations: {MAX_ITERS}, Zoom: {ZOOM_LEVEL}, Iterations: {ITERATIONS}, Char: {char}', curses.color_pair(COLOR_COUNT))
39 	screen.refresh()
40 
41