Skip to content
Snippets Groups Projects
Commit eb578558 authored by dx's avatar dx Committed by q3k
Browse files

python_payload: menu/worms cleanup

parent d764e4a5
No related branches found
No related tags found
No related merge requests found
......@@ -5,16 +5,16 @@ import math
def xy_from_polar(r,deg):
#rad = deg/180*math.pi
return( (
return (
r * math.sin(deg), #x
r * math.cos(deg) #y
) )
)
def randrgb():
return ((random.random(),random.random(),random.random()))
WIDTH = 240
HEIGHT = 240
......@@ -26,23 +26,11 @@ BLUE = (0,0,1)
WHITE = (1,1,1)
GREY = (0.5,0.5,0.5)
# Get the global context (representing the whole screen)
global ctx
# The global context (representing the whole screen)
ctx = None
'''
#center the text horizontally and vertically
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
worms = None
#ctx.rgb() expects individual values for the channels, so unpack a list/tuple with *
#operations on ctx can be chained
#create a blue background
ctx.rgb(*BLUE).rectangle(-WIDTH/2,-HEIGHT/2,WIDTH,HEIGHT).fill()
#Write some text
ctx.move_to(0,0).rgb(*WHITE).text("Hi :)")
hardware.display_update()
'''
class Worm():
def __init__(self):
......@@ -57,7 +45,6 @@ class Worm():
self._lastdist = 0.0
def draw(self):
global ctx
ctx.rgb(*self.color)
ctx.round_rectangle(
self.x-self.size/2,
......@@ -90,8 +77,6 @@ class Worm():
self._lastdist = dist
global worms
def init():
global worms
global ctx
......@@ -110,7 +95,17 @@ def run():
def foreground():
pass
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
#ctx.rgb() expects individual values for the channels, so unpack a list/tuple with *
#operations on ctx can be chained
#create a blue background
ctx.rgb(*BLUE).rectangle(-WIDTH/2,-HEIGHT/2,WIDTH,HEIGHT).fill()
#Write some text
ctx.move_to(0,0).rgb(*WHITE).text("Hi :)")
hardware.display_update()
#Known problems:
#ctx.rotate(math.pi) turns the display black until powercycled
......
......@@ -3,13 +3,11 @@ import utils
import time
import harmonic_demo
import melodic_demo
import cap_touch_demo
import demo_worms
MODULES = [
harmonic_demo,
melodic_demo,
cap_touch_demo,
demo_worms,
]
......@@ -20,30 +18,12 @@ ctx = None
BACKGROUND_COLOR = 0
def draw_volume_slider(volume):
global ctx
length = 96 + ((volume - 20) * 1.6)
if length > 96:
length = 96
if length < 0:
length = 0
length = int(length)
ctx.rgb(0,0,0)#dummy
ctx.round_rectangle(-49,41,98,8,3).fill()#dummy idk
ctx.rgb(0,255,0)
ctx.round_rectangle(-51,49,102,12,3).fill()
ctx.rgb(0,0,0)
ctx.round_rectangle(-50,50,100,10,3).fill()
ctx.rgb(0,255,0)
ctx.round_rectangle(-48,52, length ,6,3).fill()
def run_menu():
global CURRENT_APP_RUN
global ctx
display_fill(BACKGROUND_COLOR)
draw_volume_slider(VOLUME)
utils.draw_volume_slider(ctx, VOLUME)
ctx.move_to(0,0).rgb(255,0,255).text("select :3")
display_update()
......@@ -70,7 +50,6 @@ def foreground_menu():
utils.highlight_bottom_petal(0,0,55,55);
utils.highlight_bottom_petal(1,55,0,55);
utils.highlight_bottom_petal(2,55,55,0);
utils.highlight_bottom_petal(3,0,110,0);
display_fill(BACKGROUND_COLOR)
display_update()
......@@ -88,37 +67,18 @@ def set_rel_volume(vol):
set_global_volume_dB(VOLUME)
time.sleep_ms(100)
def captouch_cal():
global ctx
display_fill(0b0000000111100111)
ctx.move_to(0,0).rgb(0,255,0).text("cal")
display_update()
time.sleep_ms(500)
display_fill(0b0011100000000111)
ctx.move_to(0,0).rgb(0,255,0).text("cal")
display_update()
captouch_autocalib()
while(captouch_calibration_active()):
pass
display_fill(0)
display_update()
def main():
global CURRENT_APP_RUN
global ctx
while not init_done():
pass
captouch_autocalib() #dry run
while(captouch_calibration_active()):
pass
captouch_autocalib()
ctx = get_ctx()
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
captouch_cal()
for module in MODULES:
module.init()
......@@ -128,7 +88,7 @@ def main():
while True:
if((get_button(1) == 2) and (CURRENT_APP_RUN == run_menu)):
captouch_cal()
captouch_autocalib()
foreground_menu()
else:
if(get_button(0) == 2):
......
......@@ -39,13 +39,20 @@ def draw_rect(x,y,w,h,col):
for k in range(h):
display_draw_pixel(x+j,y+k,col)
def draw_volume_slider(volume):
def draw_volume_slider(ctx, volume):
length = 96 + ((volume - 20) * 1.6)
if length > 96:
length = 96
if length < 0:
length = 0
length = int(length)
draw_rect(70,20,100,10,GREEN)
draw_rect(71,21,98,8, 0)
draw_rect(72+96-length,22,length,6,GREEN)
ctx.rgb(0,0,0)#dummy
ctx.round_rectangle(-49,41,98,8,3).fill()#dummy idk
ctx.rgb(0,255,0)
ctx.round_rectangle(-51,49,102,12,3).fill()
ctx.rgb(0,0,0)
ctx.round_rectangle(-50,50,100,10,3).fill()
ctx.rgb(0,255,0)
ctx.round_rectangle(-48,52, length ,6,3).fill()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment