Skip to content

Commit d4589be

Browse files
Merge pull request #3 from FoamyGuy/add_jackolantern_example
Adding shifting jack-o-lantern eyes example
2 parents b3e980d + cdd951e commit d4589be

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

docs/examples.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,21 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/monsterm4sk_simpletest.py
77
:caption: examples/monsterm4sk_simpletest.py
88
:linenos:
9+
10+
Rainbow Stars
11+
-------------
12+
13+
Groovy color changing stars eyes.
14+
15+
.. literalinclude:: ../examples/monsterm4sk_rainbow_stars.py
16+
:caption: examples/monsterm4sk_rainbow_stars.py
17+
:linenos:
18+
19+
Pumpkin Shifting Eyes
20+
---------------------
21+
22+
Triangle Jack-O-Lantern eyes that shift back and forth.
23+
24+
.. literalinclude:: ../examples/monsterm4sk_pumpkin_shifting_eyes.py
25+
:caption: examples/monsterm4sk_pumpkin_shifting_eyes.py
26+
:linenos:
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# SPDX-FileCopyrightText: 2020 Foamyguy, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
"""
6+
CircuitPython example for Monster M4sk.
7+
8+
Draws a yellow triangle on each screen as Jack-O-Lantern eyes.
9+
The eyes shift back and forth from left to right.
10+
"""
11+
12+
import time
13+
import board
14+
import displayio
15+
import adafruit_imageload
16+
import adafruit_monsterm4sk
17+
18+
SCREEN_SIZE = 240
19+
IMAGE_SIZE = 173
20+
21+
# Create a bitmap for the background 10x10 pixels
22+
bg_color_pixel = displayio.Bitmap(10, 10, 1)
23+
24+
# Create a two color palette
25+
bg_palette = displayio.Palette(2)
26+
bg_palette[0] = 0xFF7700 # orange
27+
28+
bg_color_pixel.fill(0) # fill orange
29+
30+
# Create a TileGrid for the orange background
31+
bg_left_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette)
32+
bg_right_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette)
33+
34+
# Create background groups scaled 24x to match screen size
35+
bg_left_group = displayio.Group(scale=24)
36+
bg_right_group = displayio.Group(scale=24)
37+
38+
# add the background tilegrids to the scaled groups
39+
bg_left_group.append(bg_left_tile_grid)
40+
bg_right_group.append(bg_right_tile_grid)
41+
42+
# load the eye image
43+
eye_image, eye_palette = adafruit_imageload.load(
44+
"/small_triangle_eye.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
45+
)
46+
47+
# Create a TileGrid to hold the bitmap for each eye
48+
right_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette)
49+
left_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette)
50+
51+
# initialize the monster m4sk hardware
52+
i2c_bus = board.I2C()
53+
mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
54+
55+
# left eye group setup
56+
left_group = displayio.Group(max_size=4)
57+
mask.left_display.show(left_group)
58+
59+
# right eye group setup
60+
right_group = displayio.Group(max_size=4)
61+
mask.right_display.show(right_group)
62+
63+
# Add orange backgrounds to both groups
64+
right_group.append(bg_right_group)
65+
left_group.append(bg_left_group)
66+
67+
# add triangle eyes to both groups
68+
right_group.append(right_pumkin_eye_tilegrid)
69+
left_group.append(left_pumkin_eye_tilegrid)
70+
71+
# centered vertically
72+
right_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
73+
left_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
74+
75+
while True:
76+
# move the eyes to the right
77+
for i in range(0, 240 - 173, 5):
78+
right_pumkin_eye_tilegrid.x = i
79+
left_pumkin_eye_tilegrid.x = i
80+
time.sleep(0.01)
81+
82+
time.sleep(2) # wait 2 seconds
83+
84+
# move the eyes to the left
85+
for i in range(0, 240 - 173, 5):
86+
right_pumkin_eye_tilegrid.x -= 5
87+
left_pumkin_eye_tilegrid.x -= 5
88+
time.sleep(0.01)
89+
90+
time.sleep(2) # wait 2 seconds
91+
92+
if mask.boop:
93+
pass
94+
95+
if mask.buttons["S9"]:
96+
pass
97+
98+
if mask.buttons["S10"]:
99+
pass
100+
101+
if mask.buttons["S11"]:
102+
pass

examples/small_triangle_eye.bmp

30.8 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: 2020 Foamyguy, created for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense

0 commit comments

Comments
 (0)