From 4be49a66c204b4444cbc97ed01dc91909e59a915 Mon Sep 17 00:00:00 2001 From: Neythen Date: Tue, 27 Apr 2021 19:59:25 +0100 Subject: [PATCH] seamless image transition added --- __pycache__/stockTicker.cpython-37.pyc | Bin 8310 -> 8783 bytes stockTicker.py | 41 +++++++++++++++++++++---- test.py | 7 +++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/__pycache__/stockTicker.cpython-37.pyc b/__pycache__/stockTicker.cpython-37.pyc index f086f3c435e89e6cd5db69bbef8f183f0fb27187..e0cb3945dc5b5be8789a97983d7906121167cd84 100644 GIT binary patch delta 1636 zcmZ`(U2GIp6u#%q&g|^$?6QSI|5)1M58WnILMuT5rItjCw9p@E*;LBX*=@Jo?v}d) zEM&$SS_2Xh+iNsYVz$BX_1GdyZnGXAVu|+3GW@QDR0@P&M82s$G9M5J9GK=~+*Mu8Vbe-E;BZHA zR7Z1QMFo~GZ`y~ly29LG=?z=6gO=j(Fk9fZj^223I^^(r)ED?M_VSdgm(H(xDXU(7 z{At5c*1ewTazjqg(Vb9+H?T3qHQcak`e}sG%IlaDauh_vHfxy^_R*|Z+6Z(;L>pEi zo58Xa%okIcv=_?GPL5yBTK1GD{|sK6*YN;x(1WWujNq^`!&<>r z9d#Oz3C#`KoLE@kz)Jg2(!y*eAo?9{!9nJ7N)T&C4~ySYfZ2hv>I7B**oBr6W-%mN z=@(Iqo#5gy{)i(aYhoW`txR;H;;C~Yo43XDBnRy5Y}!+cxpaCiq07JZmY{f+jvbZX zo7?8YLldHq%k|EtCexH~ks>oNz~BZqLFX~JS~p}DCT51S6EkVivB`g8t=%C!vR-x> z6$=Y4z2m4B%y6-*N`i%5Kq9pK4zw$1??U@LvSTUL4M+1C3cC733} z#L)2(wtDFeOL5h_xq8*xl#s<;enDI1P_1$}F96g1nIrs{&MKRt7dL$_#c`5eB;Sxf zAjxo+cpJ}TbLrwnGsFpWNropb3X#s+<2WP!B(2g;F%oMae>F90`zB6@MJiv++Sx+> z9QqV@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*yP~=XfPkl>R0B^UNLGijN0Vd@CD= z41YI!%v8evB?SK}n}!7cJNwl7p1q5r&7Q~0A`LfZOGM$9!a?2>>H7kEhZIKQq!>jc zaJ8}s3N%f1BV}0BpeF61ebk}~?WcKUjOG~SpXG+sH&Dvn;os*5)X>IT{BCacKVp&! AApigX 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) + +