diff --git a/__pycache__/stockTicker.cpython-37.pyc b/__pycache__/stockTicker.cpython-37.pyc index f086f3c..e0cb394 100644 Binary files a/__pycache__/stockTicker.cpython-37.pyc and b/__pycache__/stockTicker.cpython-37.pyc differ diff --git a/stockTicker.py b/stockTicker.py index a43c06a..30b52b6 100644 --- a/stockTicker.py +++ b/stockTicker.py @@ -55,7 +55,7 @@ class StockTicker(): return image - def SetImage(self, image, pos_x = 0, pos_y = 0, offset_x = 0, offset_y = 0, unsafe=True): + def SetImage(self, image, offset_x = 0, offset_y = 0, unsafe=True): if (image.mode != "RGB"): @@ -81,14 +81,43 @@ class StockTicker(): self.matrix.SetPixel(x + offset_x, y + offset_y, r*brightness, g*brightness, b*brightness) - def ScrollImage(self, image_file, pos_x = 0, pos_y = 0, delay = 0.05): + def ScrollImage(self, image_file, offset_x = 0, offset_y = 0, delay = 0.05): image = self.openImage(image_file) + img_width, img_height = image.size - i = 0 - while True: - self.SetImage(image, offset_x = -i, offset_y = 0) + print(offset_x, offset_y) + + while offset_x > -img_width: + offset_x -= 1 + + self.SetImage(image, offset_x = offset_x, offset_y = offset_y) time.sleep(delay) - i += 1 + + def ScrollImageTransition(self, image_files, offset_x = 0, offset_y = 0, delay = 0.05): + # use two image files and switch between them with a seemless transition + current_img = 1 + while True: + if current_img == 1: + image = self.openImage(image_files[0]) + elif current_img == 2: + image = self.openImage(image_files[2]) + + img_width, img_height = image.size + + print(offset_x, offset_y) + + while offset_x > -img_width: + offset_x -= 1 + + self.SetImage(image, offset_x = offset_x, offset_y = offset_y) + time.sleep(delay) + if current_img == 1: + current_img = 2 + elif current_img == 2: + current_img = 1 + offset_x = 0 + + diff --git a/test.py b/test.py index 748c75f..cb8c79b 100644 --- a/test.py +++ b/test.py @@ -13,6 +13,7 @@ from stockTicker import StockTicker if __name__ == '__main__': stock_ticker = StockTicker() - while(True): - stock_ticker.ScrollImage('final.ppm') - time.sleep(100) + + stock_ticker.ScrollImageTransition(['final.ppm', 'final.ppm'], offset_x = 0, offset_y = 0, delay = 0.005) + +