-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathrunner.py
executable file
·65 lines (54 loc) · 1.6 KB
/
runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-2020 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK
import sys
from pathlib import Path
from PIL import Image
from demo_opts import get_device
from luma.core.sprite_system import spritesheet, framerate_regulator
def main(num_iterations=sys.maxsize):
data = {
'image': str(Path(__file__).resolve().parent.joinpath('images', 'runner.png')),
'frames': {
'width': 64,
'height': 67,
'regX': 0,
'regY': 2
},
'animations': {
'run-right': {
'frames': range(19, 9, -1),
'next': "run-right",
},
'run-left': {
'frames': range(0, 10),
'next': "run-left"
}
}
}
regulator = framerate_regulator()
sheet = spritesheet(**data)
runner = sheet.animate('run-right')
x = -sheet.frames.width
dx = 3
while num_iterations > 0:
with regulator:
num_iterations -= 1
background = Image.new(device.mode, device.size, "white")
background.paste(next(runner), (x, 0))
device.display(background)
x += dx
if x >= device.width:
runner = sheet.animate('run-left')
dx = -dx
if x <= -sheet.frames.width:
runner = sheet.animate('run-right')
dx = -dx
if __name__ == "__main__":
try:
device = get_device()
main()
except KeyboardInterrupt:
pass