Linting fixes for Galactic

This commit is contained in:
ZodiusInfuser 2022-10-27 13:11:36 +01:00
parent 00d7b99589
commit 6e8f2d8a27
9 changed files with 113 additions and 160 deletions

View File

@ -65,7 +65,7 @@ while True:
draw()
update()
# pause for a moment (important or the USB serial device will fail)
time.sleep(0.001)

View File

@ -47,6 +47,7 @@ bass_notes = (
notes = [melody_notes, rhythm_notes, drum_beats, hi_hat, bass_notes]
channels = [gu.synth_channel(i) for i in range(len(notes))]
def gradient(r, g, b):
for y in range(0, height):
for x in range(0, width):
@ -87,6 +88,7 @@ def outline_text(text):
graphics.set_pen(graphics.create_pen(v, v, v))
graphics.text(text, x, y, -1, 1)
gu.set_brightness(0.5)
# Vars for storing button state
@ -134,41 +136,41 @@ while True:
if not was_a_pressed:
# Configure the synth to play our notes
channels[0].configure(waveforms=Channel.TRIANGLE + Channel.SQUARE,
attack=0.016,
decay=0.168,
sustain=0xafff / 65535,
release=0.168,
volume=10000 / 65535)
attack=0.016,
decay=0.168,
sustain=0xafff / 65535,
release=0.168,
volume=10000 / 65535)
channels[1].configure(waveforms=Channel.SINE + Channel.SQUARE,
attack=0.038,
decay=0.300,
sustain=0,
release=0,
volume=12000 / 65535)
attack=0.038,
decay=0.300,
sustain=0,
release=0,
volume=12000 / 65535)
channels[2].configure(waveforms=Channel.NOISE,
attack=0.005,
decay=0.010,
sustain=16000 / 65535,
release=0.100,
volume=18000 / 65535)
attack=0.005,
decay=0.010,
sustain=16000 / 65535,
release=0.100,
volume=18000 / 65535)
channels[3].configure(waveforms=Channel.NOISE,
attack=0.005,
decay=0.005,
sustain=8000 / 65535,
release=0.040,
volume=8000 / 65535)
attack=0.005,
decay=0.005,
sustain=8000 / 65535,
release=0.040,
volume=8000 / 65535)
channels[4].configure(waveforms=Channel.SQUARE,
attack=0.010,
decay=0.100,
sustain=0,
release=0.500,
volume=12000 / 65535)
attack=0.010,
decay=0.100,
sustain=0,
release=0.500,
volume=12000 / 65535)
# If the synth is not already playing, init the first beat
if not synthing:
beat = 0
next_beat()
gu.play_synth()
synthing = True
timer.init(freq=10, mode=Timer.PERIODIC, callback=tick)
@ -181,44 +183,44 @@ while True:
if not was_b_pressed:
# Configure the synth to play our notes, but with only one channel audable
channels[0].configure(waveforms=Channel.TRIANGLE + Channel.SQUARE,
attack=0.016,
decay=0.168,
sustain=0,
release=0.168,
volume=0)
attack=0.016,
decay=0.168,
sustain=0,
release=0.168,
volume=0)
channels[1].configure(waveforms=Channel.SINE + Channel.SQUARE,
attack=0.038,
decay=0.300,
sustain=0,
release=0,
volume=12000 / 65535)
attack=0.038,
decay=0.300,
sustain=0,
release=0,
volume=12000 / 65535)
channels[2].configure(waveforms=Channel.NOISE,
attack=0.005,
decay=0.010,
sustain=16000 / 65535,
release=0.100,
volume=0)
attack=0.005,
decay=0.010,
sustain=16000 / 65535,
release=0.100,
volume=0)
channels[3].configure(waveforms=Channel.NOISE,
attack=0.005,
decay=0.005,
sustain=8000 / 65535,
release=0.040,
volume=0)
attack=0.005,
decay=0.005,
sustain=8000 / 65535,
release=0.040,
volume=0)
channels[4].configure(waveforms=Channel.SQUARE,
attack=0.010,
decay=0.100,
sustain=0,
release=0.500,
volume=0)
attack=0.010,
decay=0.100,
sustain=0,
release=0.500,
volume=0)
# If the synth is not already playing, init the first beat
if not synthing:
beat = 0
next_beat()
gu.play_synth()
synthing = True
timer.init(freq=10, mode=Timer.PERIODIC, callback=tick)
timer.init(freq=10, mode=Timer.PERIODIC, callback=tick)
was_b_pressed = True
else:
@ -226,14 +228,14 @@ while True:
if gu.is_pressed(GalacticUnicorn.SWITCH_C):
if not was_c_pressed:
# Stop synth (if running) and play Tone A
# Stop synth (if running) and play Tone A
timer.deinit()
tone_a = 400
channels[0].play_tone(tone_a, 0.06)
gu.play_synth()
synthing = False
was_c_pressed = True
else:
was_c_pressed = False
@ -247,8 +249,8 @@ while True:
channels[1].play_tone(tone_b, 0.06, attack=0.5)
gu.play_synth()
synthing = False
synthing = False
was_d_pressed = True
else:
was_d_pressed = False
@ -285,7 +287,7 @@ while True:
gu.stop_playing()
timer.deinit()
synthing = False
was_z_pressed = True
else:
was_z_pressed = False
@ -341,6 +343,6 @@ while True:
outline_text(text)
gu.update(graphics)
# pause for a moment (important or the USB serial device will fail
time.sleep(0.001)

View File

@ -131,7 +131,7 @@ while True:
draw_landscape()
else:
draw_portrait()
# pause for a moment (important or the USB serial device will fail)
time.sleep(0.001)

View File

@ -1,4 +1,4 @@
import time, random
import random
from galactic import GalacticUnicorn
graphics = None
@ -11,14 +11,15 @@ heat = [[0.0 for y in range(height)] for x in range(width)]
fire_spawns = 5
damping_factor = 0.97
def init():
# a palette of five firey colours (white, yellow, orange, red, smoke)
global palette
palette = [
graphics.create_pen( 0, 0, 0),
graphics.create_pen( 20, 20, 20),
graphics.create_pen(180, 30, 0),
graphics.create_pen(220, 160, 0),
graphics.create_pen(0, 0, 0),
graphics.create_pen(20, 20, 20),
graphics.create_pen(180, 30, 0),
graphics.create_pen(220, 160, 0),
graphics.create_pen(255, 255, 180)
]
@ -35,13 +36,14 @@ def pen_from_value(value):
return palette[3]
return palette[4]
@micropython.native # noqa: F821
def draw():
def draw():
# clear the the rows off the bottom of the display
for x in range(width):
heat[x][height - 1] = 0.0
heat[x][height - 2] = 0.0
# add new fire spawns
for c in range(fire_spawns):
x = random.randint(0, width - 4) + 2
@ -65,12 +67,13 @@ def draw():
# update the heat map with our newly averaged value
heat[x][y] = average
# render the heat values to the graphics buffer
for y in range(GalacticUnicorn.HEIGHT):
for x in range(GalacticUnicorn.WIDTH):
graphics.set_pen(pen_from_value(heat[x + 1][y]))
graphics.pixel(x, y)
def test():
print("A")
print("A")

View File

@ -1,4 +1,5 @@
import machine, time
import time
import machine
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
@ -9,6 +10,7 @@ machine.freq(200000000)
galactic = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)
# returns the id of the button that is currently pressed or
# None if none are
def pressed():
@ -22,6 +24,7 @@ def pressed():
return GalacticUnicorn.SWITCH_D
return None
graphics.set_font("bitmap6")
graphics.set_pen(graphics.create_pen(0, 0, 0))
graphics.clear()
@ -36,44 +39,43 @@ while True:
import fire as effect
break
if pressed() == GalacticUnicorn.SWITCH_B:
import supercomputer as effect
import supercomputer as effect # noqa: F811
break
if pressed() == GalacticUnicorn.SWITCH_C:
import rainbow as effect
import rainbow as effect # noqa: F811
break
if pressed() == GalacticUnicorn.SWITCH_D:
import retroprompt as effect
import retroprompt as effect # noqa: F811
break
# wait until all buttons are released
while pressed() != None:
while pressed() is not None:
time.sleep(0.1)
effect.graphics = graphics
effect.init()
brightness = 0.5
sleep = False
was_sleep_pressed = False
# wait
while True:
# if A, B, C, or D are pressed then reset
if pressed() != None:
if pressed() is not None:
machine.reset()
sleep_pressed = galactic.is_pressed(GalacticUnicorn.SWITCH_SLEEP)
if sleep_pressed and not was_sleep_pressed:
sleep = not sleep
was_sleep_pressed = sleep_pressed
if sleep:
# fade out if screen not off
galactic.set_brightness(galactic.get_brightness() - 0.05)
if galactic.get_brightness() > 0.0:
effect.draw()
@ -81,18 +83,17 @@ while True:
galactic.update(graphics)
else:
effect.draw()
# update the display
galactic.update(graphics)
# brightness up/down
if galactic.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_UP):
brightness += 0.05
if galactic.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_DOWN):
brightness -= 0.05
galactic.set_brightness(brightness)
# pause for a moment (important or the USB serial device will fail
time.sleep(0.001)

View File

@ -1,4 +1,4 @@
import time, random, math
import math
from galactic import GalacticUnicorn
graphics = None
@ -7,6 +7,7 @@ palette = None
width = GalacticUnicorn.WIDTH
height = GalacticUnicorn.HEIGHT
@micropython.native # noqa: F821
def from_hsv(h, s, v):
i = math.floor(h * 6.0)
@ -30,6 +31,7 @@ def from_hsv(h, s, v):
if i == 5:
return int(v), int(p), int(q)
phase = 0
hue_map = [from_hsv(x / width, 1.0, 1.0) for x in range(width)]
hue_offset = 0.0
@ -40,12 +42,13 @@ speed = 5.0
def init():
pass
@micropython.native # noqa: F821
def draw():
global hue_offset, phase
phase += speed
phase_percent = phase / 15
for x in range(width):
colour = hue_map[int((x + (hue_offset * width)) % width)]
@ -54,59 +57,3 @@ def draw():
graphics.set_pen(graphics.create_pen(int(colour[0] * v), int(colour[1] * v), int(colour[2] * v)))
graphics.pixel(x, y)
# hue_map = [from_hsv(x / width, 1.0, 1.0) for x in range(width)]
# hue_offset = 0.0
#
# animate = True
# stripe_width = 3.0
# speed = 1.0
#
# gu.set_brightness(0.5)
#
# phase = 0
# while True:
#
# if animate:
# phase += speed
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_VOLUME_UP):
# hue_offset += 0.01
# hue_offset = 1.0 if hue_offset > 1.0 else hue_offset
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_VOLUME_DOWN):
# hue_offset -= 0.01
# hue_offset = 0.0 if hue_offset < 0.0 else hue_offset
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_UP):
# gu.adjust_brightness(+0.01)
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_DOWN):
# gu.adjust_brightness(-0.01)
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_SLEEP):
# animate = False
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_A):
# speed += 0.05
# speed = 10.0 if speed > 10.0 else speed
# animate = True
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_B):
# speed -= 0.05
# speed = 0.0 if speed < 0.0 else speed
# animate = True
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_C):
# stripe_width += 0.05
# stripe_width = 10.0 if stripe_width > 10.0 else stripe_width
#
# if gu.is_pressed(GalacticUnicorn.SWITCH_D):
# stripe_width -= 0.05
# stripe_width = 1.0 if stripe_width < 1.0 else stripe_width
#
# start = time.ticks_ms()
#
# draw()
#
# print("total took: {} ms".format(time.ticks_ms() - start))

View File

@ -1,5 +1,4 @@
import time, random, math
from galactic import GalacticUnicorn
import time
graphics = None
palette = None
@ -58,13 +57,13 @@ PROMPT_SPECTRUM = 1
PROMPT_BBC_MICRO = 2
prompt = 0
def init():
pass
@micropython.native # noqa: F821
def draw():
time_ms = time.ticks_ms()
prompt = (time_ms // 3000) % 3
@ -80,8 +79,7 @@ def draw():
image = bbc_micro
fg = FOREGROUND_BBC_MICRO
bg = BACKGROUND_BBC_MICRO
fg_pen = graphics.create_pen(fg[0], fg[1], fg[2])
bg_pen = graphics.create_pen(bg[0], bg[1], bg[2])
for y in range(len(image)):
@ -99,4 +97,4 @@ def draw():
else:
graphics.set_pen(bg_pen)
graphics.pixel(x, y)
graphics.pixel(x, y)

View File

@ -1,10 +1,11 @@
import time, random
import random
from galactic import GalacticUnicorn
graphics = None
colour = (230, 150, 0)
def init():
global width, height, lifetime, age
width = GalacticUnicorn.WIDTH
@ -16,6 +17,7 @@ def init():
lifetime[x][y] = 1.0 + random.uniform(0.0, 0.1)
age[x][y] = random.uniform(0.0, 1.0) * lifetime[x][y]
@micropython.native # noqa: F821
def draw():
for y in range(height):
@ -25,7 +27,7 @@ def draw():
lifetime[x][y] = 1.0 + random.uniform(0.0, 0.1)
age[x][y] += 0.025
for y in range(height):
for x in range(width):
if age[x][y] < lifetime[x][y] * 0.3:
@ -35,4 +37,4 @@ def draw():
graphics.set_pen(graphics.create_pen(int(decay * colour[0]), int(decay * colour[1]), int(decay * colour[2])))
else:
graphics.set_pen(0)
graphics.pixel(x, y)
graphics.pixel(x, y)

View File

@ -110,5 +110,5 @@ while True:
# pause for a moment (important or the USB serial device will fail)
time.sleep(0.001)
print("total took: {} ms".format(time.ticks_ms() - start))