Skip to content

Adding shifting jack-o-lantern eyes example #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@ Ensure your device works with this simple test.
.. literalinclude:: ../examples/monsterm4sk_simpletest.py
:caption: examples/monsterm4sk_simpletest.py
:linenos:

Rainbow Stars
-------------

Groovy color changing stars eyes.

.. literalinclude:: ../examples/monsterm4sk_rainbow_stars.py
:caption: examples/monsterm4sk_rainbow_stars.py
:linenos:

Pumpkin Shifting Eyes
---------------------

Triangle Jack-O-Lantern eyes that shift back and forth.

.. literalinclude:: ../examples/monsterm4sk_pumpkin_shifting_eyes.py
:caption: examples/monsterm4sk_pumpkin_shifting_eyes.py
:linenos:
102 changes: 102 additions & 0 deletions examples/monsterm4sk_pumpkin_shifting_eyes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# SPDX-FileCopyrightText: 2020 Foamyguy, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

"""
CircuitPython example for Monster M4sk.

Draws a yellow triangle on each screen as Jack-O-Lantern eyes.
The eyes shift back and forth from left to right.
"""

import time
import board
import displayio
import adafruit_imageload
import adafruit_monsterm4sk

SCREEN_SIZE = 240
IMAGE_SIZE = 173

# Create a bitmap for the background 10x10 pixels
bg_color_pixel = displayio.Bitmap(10, 10, 1)

# Create a two color palette
bg_palette = displayio.Palette(2)
bg_palette[0] = 0xFF7700 # orange

bg_color_pixel.fill(0) # fill orange

# Create a TileGrid for the orange background
bg_left_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette)
bg_right_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette)

# Create background groups scaled 24x to match screen size
bg_left_group = displayio.Group(scale=24)
bg_right_group = displayio.Group(scale=24)

# add the background tilegrids to the scaled groups
bg_left_group.append(bg_left_tile_grid)
bg_right_group.append(bg_right_tile_grid)

# load the eye image
eye_image, eye_palette = adafruit_imageload.load(
"/small_triangle_eye.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
)

# Create a TileGrid to hold the bitmap for each eye
right_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette)
left_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette)

# initialize the monster m4sk hardware
i2c_bus = board.I2C()
mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)

# left eye group setup
left_group = displayio.Group(max_size=4)
mask.left_display.show(left_group)

# right eye group setup
right_group = displayio.Group(max_size=4)
mask.right_display.show(right_group)

# Add orange backgrounds to both groups
right_group.append(bg_right_group)
left_group.append(bg_left_group)

# add triangle eyes to both groups
right_group.append(right_pumkin_eye_tilegrid)
left_group.append(left_pumkin_eye_tilegrid)

# centered vertically
right_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
left_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2

while True:
# move the eyes to the right
for i in range(0, 240 - 173, 5):
right_pumkin_eye_tilegrid.x = i
left_pumkin_eye_tilegrid.x = i
time.sleep(0.01)

time.sleep(2) # wait 2 seconds

# move the eyes to the left
for i in range(0, 240 - 173, 5):
right_pumkin_eye_tilegrid.x -= 5
left_pumkin_eye_tilegrid.x -= 5
time.sleep(0.01)

time.sleep(2) # wait 2 seconds

if mask.boop:
pass

if mask.buttons["S9"]:
pass

if mask.buttons["S10"]:
pass

if mask.buttons["S11"]:
pass
Binary file added examples/small_triangle_eye.bmp
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/small_triangle_eye.bmp.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2020 Foamyguy, created for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense