Toggle Navigation
Hatchery
Eggs
cz19plasma
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import display import buttons import defines import time import system import rgb # exit when 'b' button is pressed def on_b_button(pressed): if pressed: system.reboot() buttons.attach(buttons.BTN_B, on_b_button) # change the brightness when the 'right' or 'left' buttons are pressed BRIGHTNESS_MAX = 30 BRIGHTNESS_MIN = 1 brightness = rgb.getbrightness() # 'right' button increases brightness def on_right_button(pressed): if pressed: global brightness if brightness < BRIGHTNESS_MAX: brightness += 1 rgb.setbrightness(brightness) buttons.attach(buttons.BTN_RIGHT, on_right_button) # 'left' button decreases brightness def on_left_button(pressed): if pressed: global brightness if brightness > BRIGHTNESS_MIN: brightness -= 1 rgb.setbrightness(brightness) buttons.attach(buttons.BTN_LEFT, on_left_button) # Plasma code, adapted from the version for the MCH2022 badge written by zgreg # see https://mch2022.badge.team/projects/plasma and https://github.com/grigorig/mch2022plasma sintab = [ 0 , 3 , 6 , 9 , 12 , 15 , 18 , 21 , 24 , 28 , 31 , 34 , 37 , 40 , 43 , 46 , 48 , 51 , 54 , 57 , 60 , 63 , 65 , 68 , 71 , 73 , 76 , 78 , 81 , 83 , 85 , 88 , 90 , 92 , 94 , 96 , 98 , 100 , 102 , 104 , 106 , 108 , 109 , 111 , 112 , 114 , 115 , 116 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 124 , 125 , 126 , 126 , 127 , 127 , 127 , 127 , 127 , 127 , 127 , 127 , 127 , 127 , 127 , 126 , 126 , 125 , 124 , 124 , 123 , 122 , 121 , 120 , 119 , 118 , 117 , 115 , 114 , 112 , 111 , 109 , 108 , 106 , 104 , 102 , 100 , 99 , 97 , 94 , 92 , 90 , 88 , 86 , 83 , 81 , 78 , 76 , 73 , 71 , 68 , 65 , 63 , 60 , 57 , 54 , 52 , 49 , 46 , 43 , 40 , 37 , 34 , 31 , 28 , 25 , 22 , 18 , 15 , 12 , 9 , 6 , 3 , 0 , -2 , -6 , -9 , -12 , -15 , -18 , -21 , -24 , -27 , -30 , -33 , -36 , -39 , -42 , -45 , -48 , -51 , -54 , -57 , -60 , -62 , -65 , -68 , -70 , -73 , -76 , -78 , -81 , -83 , -85 , -88 , -90 , -92 , -94 , -96 , -98 , -100 , -102 , -104 , -106 , -107 , -109 , -111 , -112 , -114 , -115 , -116 , -118 , -119 , -120 , -121 , -122 , -123 , -124 , -124 , -125 , -126 , -126 , -127 , -127 , -127 , -127 , -127 , -127 , -127 , -127 , -127 , -127 , -127 , -126 , -126 , -125 , -124 , -124 , -123 , -122 , -121 , -120 , -119 , -118 , -117 , -115 , -114 , -113 , -111 , -109 , -108 , -106 , -104 , -103 , -101 , -99 , -97 , -95 , -92 , -90 , -88 , -86 , -83 , -81 , -79 , -76 , -74 , -71 , -68 , -66 , -63 , -60 , -57 , -55 , -52 , -49 , -46 , -43 , -40 , -37 , -34 , -31 , -28 , -25 , -22 , -19 , -16 , -12 , -9 , -6 , -3 , ] DISP_WIDTH = 32 DISP_HEIGHT = 8 def show_plasma(t): for j in range(DISP_HEIGHT): for i in range(0, DISP_WIDTH, 4): # manual unroll color = (128 + sintab[(i+t) % 256] + 128 + sintab[(j+128+sintab[t%256]) % 256]) >> 1 r = 128 + sintab[(color + t) % 256] g = 128 + sintab[(color * 7 + t) % 256] b = 128 + sintab[(color * 2 + t) % 256] v = r << 16 | g << 8 | b; display.drawPixel(i, j, v) i += 1 color = (128 + sintab[(i+t) % 256] + 128 + sintab[(j+128+sintab[t%256]) % 256]) >> 1 r = 128 + sintab[(color + t) % 256] g = 128 + sintab[(color * 7 + t) % 256] b = 128 + sintab[(color * 2 + t) % 256] v = r << 16 | g << 8 | b; display.drawPixel(i, j, v) i += 1 color = (128 + sintab[(i+t) % 256] + 128 + sintab[(j+128+sintab[t%256]) % 256]) >> 1 r = 128 + sintab[(color + t) % 256] g = 128 + sintab[(color * 7 + t) % 256] b = 128 + sintab[(color * 2 + t) % 256] v = r << 16 | g << 8 | b; display.drawPixel(i, j, v) i += 1 color = (128 + sintab[(i+t) % 256] + 128 + sintab[(j+128+sintab[t%256]) % 256]) >> 1 r = 128 + sintab[(color + t) % 256] g = 128 + sintab[(color * 7 + t) % 256] b = 128 + sintab[(color * 2 + t) % 256] v = r << 16 | g << 8 | b; display.drawPixel(i, j, v) time.sleep(0.025) display.flush() t = 0 while True: show_plasma(t) t += 1