Created
November 24, 2021 21:44
-
-
Save FoamyGuy/69a8b1225c4c25e2972a785b309957a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import board | |
import displayio | |
import adafruit_imageload | |
from adafruit_displayio_layout.widgets.easing import back_easeinout as easein | |
from adafruit_displayio_layout.widgets.easing import back_easeinout as easeout | |
def _animate_value( | |
start_val, | |
end_val, | |
animation_time, | |
function_to_call | |
): | |
start_time = time.monotonic() | |
if start_val > end_val: # direction is decreasing: "out" | |
easing_function = easeout # use the "out" easing function | |
else: # direction is increasing: "in" | |
easing_function = easein # use the "in" easing function | |
while True: | |
this_time = time.monotonic() | |
target_position = ( | |
start_val | |
+ (end_val - start_val) | |
* (this_time - start_time) | |
/ animation_time | |
) | |
# print(target_position) | |
if (this_time - start_time) < animation_time: | |
if function_to_call: | |
function_to_call(easing_function(target_position)) | |
else: | |
break | |
def set_x_position(x_pos): | |
print(int(x_pos)) | |
tile_grid.x = int(x_pos) | |
image, palette = adafruit_imageload.load("images/4bit.bmp") | |
tile_grid = displayio.TileGrid(image, pixel_shader=palette) | |
group = displayio.Group() | |
group.append(tile_grid) | |
board.DISPLAY.show(group) | |
_start_time = time.monotonic() | |
_animate_value(0, 100, 0.5, set_x_position) | |
time.sleep(1) | |
#_animate_value(100, 0, 1.0, set_x_position) | |
print(time.monotonic() - _start_time) | |
while True: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment