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
...@@ -3,18 +3,34 @@ import math ...@@ -3,18 +3,34 @@ import math
import time import time
import hardware 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(): def draw(self, i, ctx):
pass imag = self.imag
real = self.real
size = self.szie
col = (1.0, 0.0, 1.0)
if i % 2:
col = (0.0, 1.0, 1.0)
ctx.rgb(*col).rectangle(
-int(imag - (size / 2)), -int(real - (size / 2)), size, size
).fill()
def run():
ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill() class CapTouchDemo(application.Application):
time.sleep_ms(30) def on_init(self):
self.dots = []
def main_foreground(self):
self.dots = []
for i in range(10): for i in range(10):
size = (hardware.get_captouch(i) * 4) + 4 size = (hardware.get_captouch(i) * 4) + 4
size += int( size += int(
...@@ -28,20 +44,13 @@ def run(): ...@@ -28,20 +44,13 @@ def run():
x += (hardware.captouch_get_petal_phi(i) / 600) * 1j x += (hardware.captouch_get_petal_phi(i) / 600) * 1j
rot = cmath.exp(2j * math.pi * i / 10) rot = cmath.exp(2j * math.pi * i / 10)
x = x * rot 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
).fill()
hardware.display_update()
def foreground(): self.dots.append(Dot(size, x.imag, x.real))
pass
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 = CapTouchDemo("cap touch")
app.main_foreground = run \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment