Skip to content

Instantly share code, notes, and snippets.

@todbot
Created September 22, 2022 19:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todbot/4f80d456289956bcec26b868f38c7ce2 to your computer and use it in GitHub Desktop.
Save todbot/4f80d456289956bcec26b868f38c7ce2 to your computer and use it in GitHub Desktop.
simple "generative art" using CircuitPython and displayio.Bitmap
# bitmaplines.py -- simple "generative art" using CircuitPython and displayio.Bitmap
# 22 Sep 2022 - @todbot / Tod Kurt, from @jedgarpark's 22 Sep 2022 CircuitPython Parsec
# Video: https://youtu.be/5TFOlvQUbn8
import board, displayio, time
import random
display = board.DISPLAY
num_colors = 5
bitmap = displayio.Bitmap( display.width, display.height, num_colors )
palette = displayio.Palette(num_colors)
tilegrid = displayio.TileGrid(bitmap,pixel_shader=palette)
maingroup = displayio.Group()
maingroup.append(tilegrid)
display.show(maingroup)
palette[0] = 0x000000 # black
palette[1] = 0xFF0000 # red
palette[2] = 0x0000FF # blue
palette[3] = 0xFF00FF # purple
palette[4] = 0x00FF00 # green
def draw_hline(x,y,length, color):
for i in range(length):
bitmap[x+i, y] = c
def draw_vline(x,y,length, color):
for i in range(length):
bitmap[x, y+i] = c
llen = 20
while True:
x, y = random.randint(0,display.width-llen), random.randint(0,display.height-llen)
c = random.randint(0,len(palette)-1)
draw_hline(x,y, llen, c)
draw_vline(x,y, llen, c)
@todbot
Copy link
Author

todbot commented Sep 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment