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

py: add captouch scroll demo

parent fd955230
No related branches found
No related tags found
No related merge requests found
Pipeline #6061 passed
# python imports
import random
import time
import math
# flow3r imports
from st3m import Ctx, InputState
from st3m.application import Application
from st3m.property import BLUE, WHITE
from st3m.goose import Optional
from st3m.utils import xy_from_polar, tau
from st3m.ui.interactions import CapScrollController
class ScrollDemo(Application):
PETAL_NO = 8
def __init__(self, name: str) -> None:
super().__init__(name)
self.scroll = CapScrollController()
def draw(self, ctx: Ctx) -> None:
ctx.save()
ctx.move_to(0, 0)
ctx.gray(0)
ctx.rectangle(-120, -120, 240, 240)
ctx.fill()
ctx.font = "Material Icons"
ctx.font_size = 20
ctx.text_baseline = ctx.MIDDLE
ctx.text_align = ctx.CENTER
ctx.rotate((self.PETAL_NO * -tau / 10))
ctx.translate(0, -90)
ctx.gray(1)
ctx.text("\ue5c4\ue5c8")
ctx.restore()
ctx.save()
ctx.move_to(0, 0)
_, y = self.scroll.position
y = -y
ctx.gray(0.1)
ctx.rectangle(-30, -120, 60, 240)
ctx.fill()
nrects = 10
for i in range(nrects):
ypos = y + i * 240 / nrects
ypos += 120
ypos %= 240
ypos -= 120
if i == 0:
ctx.gray(1)
elif i == nrects / 2:
ctx.gray(0.2)
elif i < nrects / 2:
ctx.gray(1 - (i / nrects * 2))
else:
ctx.gray(i / nrects * 2)
ctx.rectangle(-20, -5 + ypos, 40, 10)
ctx.fill()
ctx.restore()
def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms)
self.scroll.update(self.input.captouch.petals[self.PETAL_NO].gesture, delta_ms)
app = ScrollDemo("scroll")
...@@ -52,6 +52,7 @@ from apps.harmonic_demo import app as harmonic ...@@ -52,6 +52,7 @@ from apps.harmonic_demo import app as harmonic
from apps.melodic_demo import app as melodic from apps.melodic_demo import app as melodic
from apps.nick import app as nick from apps.nick import app as nick
from apps.cap_touch_demo import app as captouch_demo from apps.cap_touch_demo import app as captouch_demo
from apps.scroll_demo import app as scroll_demo
# Set the view_managers for the apps, otherwise leaving the app (back) will not work # Set the view_managers for the apps, otherwise leaving the app (back) will not work
...@@ -60,6 +61,7 @@ harmonic._view_manager = vm ...@@ -60,6 +61,7 @@ harmonic._view_manager = vm
melodic._view_manager = vm melodic._view_manager = vm
nick._view_manager = vm nick._view_manager = vm
captouch_demo._view_manager = vm captouch_demo._view_manager = vm
scroll_demo._view_manager = vm
# Build menu structure # Build menu structure
...@@ -82,6 +84,7 @@ menu_apps = SimpleMenu( ...@@ -82,6 +84,7 @@ menu_apps = SimpleMenu(
MenuItemBack(), MenuItemBack(),
MenuItemForeground("captouch", captouch_demo), MenuItemForeground("captouch", captouch_demo),
MenuItemForeground("worms", worms), MenuItemForeground("worms", worms),
MenuItemForeground("cap scroll", scroll_demo),
], ],
vm, vm,
) )
......
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