Skip to content
Snippets Groups Projects
Commit c99d120e authored by q3k's avatar q3k
Browse files

cap_touch_demo: do not use global ctx

parent 022bfa91
No related branches found
No related tags found
No related merge requests found
Pipeline #5595 passed
......@@ -3,45 +3,54 @@ import math
import time
import hardware
from st3m import utils
from st3m import utils, application
ctx = hardware.get_ctx()
class Dot:
def __init__(self, size, imag, real):
self.size = size
self.imag = imag
self.real = real
def init():
pass
def draw(self, i, ctx):
imag = self.imag
real = self.real
size = self.szie
def run():
ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill()
time.sleep_ms(30)
for i in range(10):
size = (hardware.get_captouch(i) * 4) + 4
size += int(
max(
0,
sum([hardware.captouch_get_petal_pad(i, x) for x in range(0, 3 + 1)])
/ 8000,
)
)
x = 70 + (hardware.captouch_get_petal_rad(i) / 1000)
x += (hardware.captouch_get_petal_phi(i) / 600) * 1j
rot = cmath.exp(2j * math.pi * i / 10)
x = x * rot
col = (1.0, 0.0, 1.0)
if i % 2:
col = (0.0, 1.0, 1.0)
ctx.rgb(*col).rectangle(
-int(x.imag - (size / 2)), -int(x.real - (size / 2)), size, size
-int(imag - (size / 2)), -int(real - (size / 2)), size, size
).fill()
hardware.display_update()
def foreground():
pass
class CapTouchDemo(application.Application):
def on_init(self):
self.dots = []
def main_foreground(self):
self.dots = []
for i in range(10):
size = (hardware.get_captouch(i) * 4) + 4
size += int(
max(
0,
sum([hardware.captouch_get_petal_pad(i, x) for x in range(0, 3 + 1)])
/ 8000,
)
)
x = 70 + (hardware.captouch_get_petal_rad(i) / 1000)
x += (hardware.captouch_get_petal_phi(i) / 600) * 1j
rot = cmath.exp(2j * math.pi * i / 10)
x = x * rot
self.dots.append(Dot(size, x.imag, x.real))
def on_draw(self, ctx):
ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill()
for i, dot in enumerate(self.dots):
dot.draw(i, ctx)
from st3m.application import Application
app = Application("cap touch")
app.main_foreground = run
app = CapTouchDemo("cap touch")
\ No newline at end of file
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