seamless image transition added
This commit is contained in:
parent
799fd16f8f
commit
4be49a66c2
Binary file not shown.
@ -55,7 +55,7 @@ class StockTicker():
|
|||||||
return image
|
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"):
|
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)
|
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)
|
image = self.openImage(image_file)
|
||||||
|
img_width, img_height = image.size
|
||||||
|
|
||||||
i = 0
|
print(offset_x, offset_y)
|
||||||
while True:
|
|
||||||
self.SetImage(image, offset_x = -i, offset_y = 0)
|
while offset_x > -img_width:
|
||||||
|
offset_x -= 1
|
||||||
|
|
||||||
|
self.SetImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||||
time.sleep(delay)
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
7
test.py
7
test.py
@ -13,6 +13,7 @@ from stockTicker import StockTicker
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
stock_ticker = StockTicker()
|
stock_ticker = StockTicker()
|
||||||
|
|
||||||
while(True):
|
|
||||||
stock_ticker.ScrollImage('final.ppm')
|
stock_ticker.ScrollImageTransition(['final.ppm', 'final.ppm'], offset_x = 0, offset_y = 0, delay = 0.005)
|
||||||
time.sleep(100)
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user