Skip to content

Commit 1cc215f

Browse files
committed
mandelbrot-app: fix PNG mode
1 parent 7a81d93 commit 1cc215f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

software/mandelbrot-app.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,19 @@ def update(self, *, center_x, center_y, radius, width, height, max_iterations=25
6767
radius_pixels = min(width, height) / 2
6868
step = radius / radius_pixels
6969

70+
self.radius = radius
71+
self.center_x = center_x
72+
self.center_y = center_y
7073
self.step = float2fix(step)
7174
self.corner_x = float2fix(center_x - (width/2) * step)
7275
self.corner_y = float2fix(center_y - (height/2) * step)
7376
self.width = width
7477
self.height = height
7578
self.max_iterations = max_iterations
7679

80+
def update_size(self, width, height, iterations):
81+
self.update(center_x=self.center_x, center_y=self.center_y, radius=self.radius, width=width, height=height, max_iterations=iterations)
82+
7783
def get_center(self):
7884
center_x = fix2float(self.corner_x) + fix2float(self.step) * (self.width / 2)
7985
center_y = fix2float(self.corner_y) + fix2float(self.step) * (self.height / 2)
@@ -304,9 +310,14 @@ def onDraw(self, canvas: DrawingArea, cr: cairo.Context):
304310
elif argv[1] == "png":
305311
tstart = time.perf_counter()
306312

307-
if len(argv) == 4:
308-
view.width = int(argv[2])
309-
view.height = int(argv[3])
313+
if len(argv) >= 4:
314+
width = int(argv[2])
315+
height = int(argv[3])
316+
if (len(argv) == 5):
317+
iterations = int(argv[4])
318+
view.update_size(width, height, iterations)
319+
else:
320+
view.update_size(width, height, 170)
310321

311322
print("Rendering view to PNG:")
312323
lower_left = view.get_lower_left_corner()

0 commit comments

Comments
 (0)