Skip to content

Commit 29225ff

Browse files
committed
app: make drawing faster
1 parent 1b664cd commit 29225ff

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

software/mandelbrot-app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,13 @@ def __init__(self, builder) -> None:
161161
def painter(self):
162162
drawing_start = time.perf_counter()
163163
try:
164+
cr = cairo.Context(self.surface)
165+
pixel_count = 0
164166
while True:
165167
# get() will exit this thread if the
166168
# queue is empty
167169
pixel = pixel_queue.get()
170+
pixel_count += 1
168171

169172
x = pixel[0]
170173
y = pixel[1]
@@ -177,7 +180,6 @@ def painter(self):
177180
maxed = pixel[2] >> 7
178181

179182
def draw_pixel():
180-
cr = cairo.Context(self.surface)
181183
if not maxed:
182184
cr.set_source_rgb(red, green, blue)
183185
else:
@@ -186,7 +188,9 @@ def draw_pixel():
186188
cr.rectangle(x, y, 1.5, 1.5)
187189
cr.fill()
188190
self.surface.mark_dirty_rectangle(x, y, 1, 1)
189-
self.canvas.queue_draw()
191+
if pixel_count % 500 == 0:
192+
self.canvas.queue_draw()
193+
190194
return False
191195

192196
Gdk.threads_enter()

software/mandelbrot-client-gui.glade

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@
177177
<property name="position">1</property>
178178
</packing>
179179
</child>
180+
<child>
181+
<object class="GtkBox" id="status_box">
182+
<property name="can_focus">False</property>
183+
<child>
184+
<placeholder/>
185+
</child>
186+
<child>
187+
<object class="GtkProgressBar">
188+
<property name="visible">True</property>
189+
<property name="can_focus">False</property>
190+
</object>
191+
<packing>
192+
<property name="expand">False</property>
193+
<property name="fill">True</property>
194+
<property name="position">1</property>
195+
</packing>
196+
</child>
197+
</object>
198+
<packing>
199+
<property name="expand">False</property>
200+
<property name="fill">True</property>
201+
<property name="position">2</property>
202+
</packing>
203+
</child>
180204
</object>
181205
</child>
182206
</object>

0 commit comments

Comments
 (0)