Skip to content

Instantly share code, notes, and snippets.

@FoamyGuy
Last active August 9, 2021 19:24
Show Gist options
  • Save FoamyGuy/06ab9ff20a3e264eb159e93b24c7df57 to your computer and use it in GitHub Desktop.
Save FoamyGuy/06ab9ff20a3e264eb159e93b24c7df57 to your computer and use it in GitHub Desktop.
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
"""
Adapted from this answer: https://stackoverflow.com/a/27756701/507810
"""
import displayio
import terminalio
from adafruit_display_text import label
from blinka_displayio_pygamedisplay import PyGameDisplay
# Make the display context. Change size if you want
display = PyGameDisplay(width=320, height=240)
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
# Create a two color palette
palette = displayio.Palette(2)
palette[0] = 0xFFFFFF
palette[1] = 0x000000
# Create a bitmap with two colors
bitmap = displayio.Bitmap(display.width, display.height, 2)
# Create a TileGrid using the Bitmap and Palette
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
main_group.append(tile_grid)
def set_pixel(_bitmap, x, y, color_index):
_bitmap[x, y] = color_index
def x_line(_bitmap, x1, x2, y, color_index):
while x1 <= x2:
set_pixel(bitmap, x1, y, color_index)
x1 += 1
def y_line(_bitmap, x, y1, y2, color_index):
while y1 <= y2:
set_pixel(_bitmap, x, y1, color_index)
y1 += 1
def circle2(_bitmap, color_index, xc, yc, inner, outer):
xo = outer
xi = inner
y = 0
erro = 1 - xo
erri = 1 - xi
while(xo >= y):
x_line(_bitmap, xc + xi, xc + xo, yc + y, color_index)
y_line(_bitmap, xc + y, yc + xi, yc + xo, color_index)
x_line(_bitmap, xc - xo, xc - xi, yc + y, color_index)
y_line(_bitmap, xc - y, yc + xi, yc + xo, color_index)
x_line(_bitmap, xc - xo, xc - xi, yc - y, color_index)
y_line(_bitmap, xc - y, yc - xo, yc - xi, color_index)
x_line(_bitmap, xc + xi, xc + xo, yc - y, color_index)
y_line(_bitmap, xc + y, yc - xo, yc - xi, color_index)
y += 1
if (erro < 0):
erro += 2 * y + 1
else:
xo -= 1
erro += 2 * (y - xo + 1)
if (y > inner):
xi = y
else:
if (erri < 0):
erri += 2 * y + 1
else:
xi -= 1
erri += 2 * (y - xi + 1)
circle2(bitmap, 1, 50, 50, 35, 39)
while display.running:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment