add dreidel code
This commit is contained in:
parent
0aae1a43af
commit
24539d4681
3 changed files with 68 additions and 0 deletions
68
TFT_Gizmo_Dreidel/dreidel.py
Normal file
68
TFT_Gizmo_Dreidel/dreidel.py
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import board
|
||||||
|
import displayio
|
||||||
|
import adafruit_imageload
|
||||||
|
from adafruit_circuitplayground.bluefruit import cpb
|
||||||
|
from adafruit_gizmo import tft_gizmo
|
||||||
|
|
||||||
|
# define melody to play while spinning (freq, duration)
|
||||||
|
melody = (
|
||||||
|
# oh drei del drei del
|
||||||
|
(330, 8), (392, 8), (330, 8), (392, 8), (330, 8),
|
||||||
|
# drei del I made it
|
||||||
|
(392, 8), (330, 16), (330, 8), (392, 8), (392, 8),
|
||||||
|
# out of clay
|
||||||
|
(349, 8), (330, 8), (294, 16), (0, 8),
|
||||||
|
# oh drei del drei del
|
||||||
|
(294, 8), (349, 8), (294, 8), (349, 8), (294, 8),
|
||||||
|
# drei del then drei del
|
||||||
|
(349, 8), (294, 16), (294, 8), (392, 8), (349, 8),
|
||||||
|
# I shall play
|
||||||
|
(330, 8), (294, 8), (262, 16),
|
||||||
|
)
|
||||||
|
melody_tempo = 0.02
|
||||||
|
|
||||||
|
# setup TFT Gizmo and main display group (splash)
|
||||||
|
display = tft_gizmo.TFT_Gizmo()
|
||||||
|
splash = displayio.Group()
|
||||||
|
display.show(splash)
|
||||||
|
|
||||||
|
# load dreidel background image
|
||||||
|
dreidel_bmp, dreidel_pal = adafruit_imageload.load("/dreidel_background.bmp",
|
||||||
|
bitmap=displayio.Bitmap,
|
||||||
|
palette=displayio.Palette)
|
||||||
|
dreidel_tg = displayio.TileGrid(dreidel_bmp, pixel_shader=dreidel_pal)
|
||||||
|
splash.append(dreidel_tg)
|
||||||
|
|
||||||
|
# load dreidel symbols (sprite sheet)
|
||||||
|
symbols_bmp, symbols_pal = adafruit_imageload.load("/dreidel_sheet.bmp",
|
||||||
|
bitmap=displayio.Bitmap,
|
||||||
|
palette=displayio.Palette)
|
||||||
|
for index, color in enumerate(symbols_pal):
|
||||||
|
if color == 0xFFFF01:
|
||||||
|
symbols_pal.make_transparent(index)
|
||||||
|
symbols_tg = displayio.TileGrid(symbols_bmp, pixel_shader=symbols_pal,
|
||||||
|
width = 1,
|
||||||
|
height = 1,
|
||||||
|
tile_width = 60,
|
||||||
|
tile_height = 60)
|
||||||
|
symbols_group = displayio.Group(scale=2, x=60, y=70)
|
||||||
|
symbols_group.append(symbols_tg)
|
||||||
|
splash.append(symbols_group)
|
||||||
|
|
||||||
|
# dreidel time!
|
||||||
|
tile = 0
|
||||||
|
while True:
|
||||||
|
# wait for shake
|
||||||
|
while not cpb.shake():
|
||||||
|
pass
|
||||||
|
# play melody while "spinning" the symbols
|
||||||
|
for note, duration in melody:
|
||||||
|
symbols_tg[0] = tile % 4
|
||||||
|
tile += 1
|
||||||
|
cpb.play_tone(note, duration * melody_tempo)
|
||||||
|
# land on a random symbol
|
||||||
|
symbols_tg[0] = random.randint(0, 3)
|
||||||
|
# prevent immediate re-shake
|
||||||
|
time.sleep(2)
|
||||||
BIN
TFT_Gizmo_Dreidel/dreidel_background.bmp
Normal file
BIN
TFT_Gizmo_Dreidel/dreidel_background.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
BIN
TFT_Gizmo_Dreidel/dreidel_sheet.bmp
Normal file
BIN
TFT_Gizmo_Dreidel/dreidel_sheet.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
Loading…
Reference in a new issue