Skip to content

Instantly share code, notes, and snippets.

@FoamyGuy
Created December 24, 2021 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FoamyGuy/6a7b658cb4d23e035ccd65d9b3d4dd73 to your computer and use it in GitHub Desktop.
Save FoamyGuy/6a7b658cb4d23e035ccd65d9b3d4dd73 to your computer and use it in GitHub Desktop.
import time
import board
import vectorio
import displayio
from rainbowio import colorwheel
scarf_palette = displayio.Palette(1)
scarf_palette[0] = colorwheel(128)
def draw_circle(x, y, r, color):
palette = displayio.Palette(1)
palette[0] = color
_circle = vectorio.Circle(pixel_shader=palette,
radius=r,
x=x,
y=y, )
main_group.append(_circle)
return _circle
def draw_polygon(x, y, points, color, palette=None):
if not palette:
_palette = displayio.Palette(1)
_palette[0] = color
else:
_palette = palette
_polygon = vectorio.Polygon(
pixel_shader=_palette,
points=points, x=x, y=y)
main_group.append(_polygon)
return _polygon
def draw_rectangle(x, y, w, h, color, palette = None):
if not palette:
_palette = displayio.Palette(1)
_palette[0] = color
else:
_palette = palette
rectangle = vectorio.Rectangle(
pixel_shader=_palette,
width=w, height=h,
x=x, y=y)
main_group.append(rectangle)
return rectangle
display = board.DISPLAY
display.rotation = 90
main_group = displayio.Group()
HEAD_R = 60
head = draw_circle(display.width // 2,
HEAD_R + 10, HEAD_R, 0xffffff)
MIDDLE_R = 75
middle = draw_circle(display.width // 2,
HEAD_R + MIDDLE_R + 10, MIDDLE_R, 0xffffff)
BOTTOM_R = 110
bottom = draw_circle(display.width // 2,
HEAD_R + MIDDLE_R + BOTTOM_R + 10,
BOTTOM_R, 0xffffff)
EYE_R = 8
left_eye = draw_circle(display.width // 2 - 20,
head.y - 30,
EYE_R, 0x00000)
right_eye = draw_circle(display.width // 2 + 20,
head.y - 30,
EYE_R, 0x00000)
nose = draw_polygon(
display.width // 2,
head.y - 14,
[(0, 0), (0, 20), (70, 10)],
0xff6600
)
nose_circle = draw_circle(
display.width // 2,
head.y - 4,
10,
0xff6600
)
buttons = []
BUTTON_R = 11
for i in range(4):
buttons.append(draw_circle(display.width // 2,
head.y + 46 + (i * 48),
BUTTON_R, 0x00000))
SCARF_EXTRA = 8
SCARF_WIDTH = HEAD_R * 2 + SCARF_EXTRA
scarf_neck = draw_rectangle(
display.width // 2 - SCARF_WIDTH // 2,
head.y + 15,
SCARF_WIDTH,
20,
0xff0000,
palette=scarf_palette
)
scarf_tail = draw_polygon(
display.width // 2 - SCARF_WIDTH + 26,
head.y + 25,
[(40, 0), (50, 8), (25, 50), (0, 56), (4, 42)],
0xff0000,
palette=scarf_palette
)
display.show(main_group)
while True:
for i in range(255):
scarf_palette[0] = colorwheel(i)
time.sleep(0.005)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment