seamless image transition added

This commit is contained in:
Neythen 2021-04-27 19:59:25 +01:00
parent 799fd16f8f
commit 4be49a66c2
3 changed files with 39 additions and 9 deletions

View File

@ -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

View File

@ -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)