From 434d722c5fa6f9f1433a4d6ae015cee94ff45474 Mon Sep 17 00:00:00 2001 From: David Todd Date: Mon, 27 Jan 2020 18:57:31 -0600 Subject: [PATCH] Fix infinite loop with unchanged dots --- pixo/pixels.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pixo/pixels.py b/pixo/pixels.py index c9c4d87..2a37204 100644 --- a/pixo/pixels.py +++ b/pixo/pixels.py @@ -124,18 +124,23 @@ class Pixo: selected multiple times """ already_changed = [] + + if image == (0, 0, 0): + image = [(0, 0, 0) for _ in range(TOTAL_DOTS)] + while len(already_changed) < TOTAL_DOTS: dot = random.randrange(0, TOTAL_DOTS) - if dot not in already_changed and not BOARD[dot] == image[dot]: + if dot not in already_changed: already_changed.append(dot) - BOARD[dot] = image[dot] - time.sleep(delay) - BOARD.show() + if not BOARD[dot] == image[dot]: + BOARD[dot] = image[dot] + time.sleep(delay) + BOARD.show() return self - def transition_image_dissolve(self, delay=0.2): + def transition_image_dissolve(self, delay=0.09): """ Randomly sets pixels to black, giving the appearance of it dissolving away into the ether