Improve compatibility with CPython 2.7 and 3.x
This commit is contained in:
@@ -95,7 +95,7 @@ class AnimationScene:
|
|||||||
"""
|
"""
|
||||||
Load icon into first available slot
|
Load icon into first available slot
|
||||||
"""
|
"""
|
||||||
cols = bytearray(' ' * 32)
|
cols = bytearray(b' ' * 32)
|
||||||
icon_width = 8
|
icon_width = 8
|
||||||
padding = 1 if self.display.columns == 32 else 0
|
padding = 1 if self.display.columns == 32 else 0
|
||||||
for state in self.on_screen_icons:
|
for state in self.on_screen_icons:
|
||||||
|
|||||||
10
firescene.py
10
firescene.py
@@ -1,4 +1,7 @@
|
|||||||
from uos import urandom
|
try:
|
||||||
|
from uos import urandom
|
||||||
|
except:
|
||||||
|
from os import urandom
|
||||||
from pixelfont import PixelFont
|
from pixelfont import PixelFont
|
||||||
|
|
||||||
class FireScene:
|
class FireScene:
|
||||||
@@ -70,7 +73,10 @@ class FireScene:
|
|||||||
put_pixel(x, y, max(r, 0), max(g, 0), b)
|
put_pixel(x, y, max(r, 0), max(g, 0), b)
|
||||||
# Spread heat from below
|
# Spread heat from below
|
||||||
r, g, b = get_pixel(x, y+1)
|
r, g, b = get_pixel(x, y+1)
|
||||||
spread = (urandom(1)[0]&3) - 1
|
try:
|
||||||
|
spread = (urandom(1)[0]&3) - 1
|
||||||
|
except TypeError:
|
||||||
|
spread = (ord(urandom(1)[0])&3) - 1
|
||||||
r -= spread
|
r -= spread
|
||||||
g -= 1
|
g -= 1
|
||||||
b >>= 2
|
b >>= 2
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ class PixelFont:
|
|||||||
width = 4
|
width = 4
|
||||||
height = 5
|
height = 5
|
||||||
alphabet = " %'-./0123456789:?acdefgiklmnoprstwxy"
|
alphabet = " %'-./0123456789:?acdefgiklmnoprstwxy"
|
||||||
data = bytearray("\x00\x00\x50\x24\x51\x66\x00\x00\x60\x00\x00\x00\x42\x24\x11\x57\x55\x27\x23\x72\x47\x17\x77\x64\x74\x55\x47\x74\x71\x74\x17\x57\x77\x44\x44\x57\x57\x77\x75\x74\x20\x20\x30\x24\x20\x52\x57\x25\x15\x25\x53\x55\x73\x31\x71\x17\x13\x71\x71\x75\x27\x22\x57\x35\x55\x11\x11\x57\x77\x55\x75\x77\x75\x55\x75\x57\x17\x71\x35\x55\x17\x47\x77\x22\x22\x55\x77\x55\x25\x55\x55\x27\x02")
|
data = bytearray(b"\x00\x00\x50\x24\x51\x66\x00\x00\x60\x00\x00\x00\x42\x24\x11\x57\x55\x27\x23\x72\x47\x17\x77\x64\x74\x55\x47\x74\x71\x74\x17\x57\x77\x44\x44\x57\x57\x77\x75\x74\x20\x20\x30\x24\x20\x52\x57\x25\x15\x25\x53\x55\x73\x31\x71\x17\x13\x71\x71\x75\x27\x22\x57\x35\x55\x11\x11\x57\x77\x55\x75\x77\x75\x55\x75\x57\x17\x71\x35\x55\x17\x47\x77\x22\x22\x55\x77\x55\x25\x55\x55\x27\x02")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import time
|
|||||||
import gc
|
import gc
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
if not hasattr(time, 'ticks_ms'):
|
if not hasattr(time, 'sleep_ms') or not hasattr(time, 'ticks_ms'):
|
||||||
# Emulate https://docs.pycom.io/firmwareapi/micropython/utime.html
|
# Emulate https://docs.pycom.io/firmwareapi/micropython/utime.html
|
||||||
time.ticks_ms = lambda: int(time.time() * 1000)
|
time.ticks_ms = lambda: int(time.time() * 1000)
|
||||||
time.sleep_ms = lambda x: time.sleep(x/1000.0)
|
time.sleep_ms = lambda x: time.sleep(x/1000.0)
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ if __name__ == '__main__':
|
|||||||
print('width = {}'.format(font_width))
|
print('width = {}'.format(font_width))
|
||||||
print('height = {}'.format(font_height))
|
print('height = {}'.format(font_height))
|
||||||
print('alphabet = "{}"'.format(font_alphabet))
|
print('alphabet = "{}"'.format(font_alphabet))
|
||||||
print('data = bytearray("{}")'.format("".join("\\x{:02x}".format(x) for x in data)))
|
print('data = bytearray(b"{}")'.format("".join("\\x{:02x}".format(x) for x in data)))
|
||||||
print('')
|
print('')
|
||||||
print('/* Computed with pixelfont.py */')
|
print('/* Computed with pixelfont.py */')
|
||||||
print('static int font_width = {};'.format(font_width))
|
print('static int font_width = {};'.format(font_width))
|
||||||
|
|||||||
Reference in New Issue
Block a user