Skip to content

Instantly share code, notes, and snippets.

@kamera25
Last active Dec 24, 2017
Embed
What would you like to do?
# Add your Python code here. E.g.
from microbit import *
# ひらがなの画像
# KanaFive by pleist. http://wentwayup.tamaliver.jp/e93615.html
HIRAGANA_IMAGES = [
#あ
Image(
"01000:"
"11101:"
"01010:"
"10101:"
"01001"),
Image(
"10010:"
"10001:"
"10001:"
"10101:"
"01001"),
Image(
"01100:"
"11110:"
"00001:"
"00001:"
"01110"),
Image(
"01100:"
"11111:"
"00010:"
"01100:"
"10011"),
Image(
"01000:"
"11101:"
"01000:"
"11110:"
"11001"),
#か
Image(
"01010:"
"11101:"
"01010:"
"01010:"
"10010"),
Image(
"00100:"
"11110:"
"01111:"
"10000:"
"11111"),
Image(
"00110:"
"01000:"
"10000:"
"01000:"
"00110"),
Image(
"10010:"
"10111:"
"10010:"
"10010:"
"10010"),
Image(
"01110:"
"00010:"
"00000:"
"10000:"
"01111"),
#さ
Image(
"01000:"
"11111:"
"00100:"
"10000:"
"01111"),
Image(
"10000:"
"10000:"
"10000:"
"10001:"
"01110"),
Image(
"00010:"
"11111:"
"01010:"
"00110:"
"00010"),
Image(
"01010:"
"11111:"
"01010:"
"01000:"
"00110"),
Image(
"01001:"
"00010:"
"11111:"
"01000:"
"00111"),
#た
Image(
"01000:"
"11100:"
"01011:"
"10000:"
"10111"),
Image(
"01000:"
"11111:"
"01110:"
"00001:"
"01110"),
Image(
"11110:"
"00001:"
"00001:"
"00001:"
"00110"),
Image(
"11111:"
"00010:"
"00100:"
"00100:"
"00010"),
Image(
"10010:"
"10100:"
"01000:"
"10000:"
"01111"),
#な
Image(
"01000:"
"11011:"
"00010:"
"01111:"
"01110"),
Image(
"10111:"
"10000:"
"10000:"
"10000:"
"10111"),
Image(
"10001:"
"01110:"
"10101:"
"11011:"
"00011"),
Image(
"01000:"
"11110:"
"01001:"
"11011:"
"01011"),
Image(
"01110:"
"10101:"
"10101:"
"10101:"
"01100"),
#は
Image(
"10010:"
"10111:"
"10010:"
"10111:"
"10110"),
Image(
"11000:"
"01011:"
"10010:"
"10010:"
"01100"),
Image(
"01100:"
"00000:"
"00100:"
"10101:"
"10101"),
Image(
"00000:"
"01100:"
"10010:"
"00001:"
"00000"),
Image(
"10111:"
"10010:"
"10111:"
"10010:"
"10111"),
#ま
Image(
"11111:"
"01110:"
"00100:"
"11110:"
"11101"),
Image(
"11000:"
"01010:"
"01111:"
"11010:"
"11010"),
Image(
"01000:"
"11101:"
"01000:"
"11001:"
"01110"),
Image(
"10001:"
"01110:"
"11011:"
"10101:"
"11001"),
Image(
"11100:"
"01000:"
"11100:"
"01001:"
"00110"),
#や
Image(
"01001:"
"11110:"
"01001:"
"01000:"
"01000"),
Image(
"10010:"
"10001:"
"10001:"
"10101:"
"01001"),
Image(
"10100:"
"10110:"
"10101:"
"10101:"
"10110"),
Image(
"01100:"
"11111:"
"00010:"
"01100:"
"10011"),
Image(
"00100:"
"00111:"
"00100:"
"11110:"
"11101"),
#ら
Image(
"10011:"
"10000:"
"11110:"
"00001:"
"11110"),
Image(
"10001:"
"10001:"
"01001:"
"00001:"
"00110"),
Image(
"11111:"
"01100:"
"00010:"
"11001:"
"11110"),
Image(
"01000:"
"11110:"
"01010:"
"11010:"
"01011"),
Image(
"11110:"
"01100:"
"00010:"
"00001:"
"11110"),
#わ
Image(
"01000:"
"11110:"
"01001:"
"11001:"
"01001"),
Image(
"00000:"
"00000:"
"00000:"
"00000:"
"00000"),
Image(
"00000:"
"00000:"
"00000:"
"00000:"
"00000"),
Image(
"00000:"
"00000:"
"00000:"
"00000:"
"00000"),
Image(
"11000:"
"01110:"
"11001:"
"11011:"
"11011"),
#ん
Image(
"01000:"
"01000:"
"10000:"
"11001:"
"10110"),
Image(
"00000:"
"00000:"
"00000:"
"00000:"
"00000"),
Image(
"00000:"
"00000:"
"00000:"
"00000:"
"00000"),
Image(
"00000:"
"00000:"
"00000:"
"00000:"
"00000"),
Image(
"00000:"
"00000:"
"00000:"
"00000:"
"00000")
]
def getIndexBoin(b_char):
if b_char == 'a':
return 0
if b_char == 'i':
return 1
if b_char == 'u':
return 2
if b_char == 'e':
return 3
if b_char == 'o':
return 4
if b_char == 'N': #ん
return 50
return -1
def getIndexShin(s_char):
if s_char == 'k':
return 0
if s_char == 's':
return 1
if s_char == 't':
return 2
if s_char == 'n':
return 3
if s_char == 'h':
return 4
if s_char == 'm':
return 5
if s_char == 'y':
return 6
if s_char == 'r':
return 7
if s_char == 'w':
return 8
return -1
def displayShowHira(text, bright = 5):
i = 0
while i < len(text):
sleep(1000)
# 母音の特定
f_char = text[i]
boin = getIndexBoin(f_char)
if boin != -1:
display.show(HIRAGANA_IMAGES[boin] * bright)
i += 1
continue
# 子音の特定
s_char = text[i+1]
index = (getIndexShin(f_char) + 1) * 5 + getIndexBoin(s_char)
display.show(HIRAGANA_IMAGES[index] * bright)
i += 2
while True:
displayShowHira("hirosima", 9)
sleep(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment