Created
September 22, 2022 19:39
-
-
Save todbot/4f80d456289956bcec26b868f38c7ce2 to your computer and use it in GitHub Desktop.
simple "generative art" using CircuitPython and displayio.Bitmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
video demo:
https://www.youtube.com/watch?v=5TFOlvQUbn8