====== Tablet-based touch input ====== Use this and navigate your tablet to ''/tablet'' # Tablet Touch Handler 9000 - Revamped live at folk0 on Jun 11 2024 Wish the web server handles route "/tablet" with handler { html { Status } } When tag 48712 has corners /corners/ { # Setting aside this tag space (48600 to 48713) for calibration. set tagCorners [lmap p $corners {::cameraToProjector $p}] set vecBottom [sub [lindex $tagCorners 1] [lindex $tagCorners 0]] set vecRight [sub [lindex $tagCorners 2] [lindex $tagCorners 1]] set offsets {{-4.7 -2.6} {1 -2.6} {1 0.8} {-4.7 0.8}} set scales [matmul $offsets [list $vecBottom $vecRight]] set corners [add $tagCorners $scales] set edges [list] for {set i 0} {$i < [llength $corners]} {incr i} { if {$i > 0} { lappend edges [list [expr {$i - 1}] $i] } } lappend edges [list [expr {[llength $corners] - 1}] 0] set angle [expr {atan2(-[lindex $vecBottom 1], [lindex $vecBottom 0])}] set region [region create $corners $edges $angle] Claim 48712 has region $region Claim tag 48712 is a tag Claim 48712 is a tablet } Draw a little circle using touch! When /thing/ claims /thing2/ has touch number /i/ with x /x/ and y /y/ { set posX [expr {int($Display::WIDTH * $x) % $Display::WIDTH}] set posY [expr {int($Display::HEIGHT * $y) % $Display::HEIGHT}] Wish to draw a circle with x $posX y $posY radius 20 thickness 6 color white } Tablet pointer! set MARGIN 0.2 set LENGTH 0.5 When /thing/ claims /thing2/ has touch number /i/ with x /x/ and y /y/ & 48712 has region /r/ { if {$x < $MARGIN && $y > $MARGIN && $y < [expr {1 - $MARGIN}] } { # left Wish 48712 points left with length $LENGTH } elseif {$x > [expr {1 - $MARGIN}] && $y > $MARGIN && $y < [expr {1 - $MARGIN}] } { # right Wish 48712 points right with length $LENGTH } elseif {$y > [expr {1 - $MARGIN}] } { # down Wish 48712 points down with length $LENGTH } elseif {$y < $MARGIN } { # up Wish 48712 points up with length $LENGTH } } If you have [[:supercollider|Supercollider]] set up, play this little theremin! # Supercollider touch demo When /thing/ claims /thing2/ has touch number /i/ with x /x/ and y /y/ { set freq [expr {int($Display::WIDTH * $x) % $Display::WIDTH} / 2.] Wish Supercollider sound $thing2-touch-noise attr freq is $freq Wish $this is labelled "$freq Hz" Wish Supercollider plays sound $thing2-touch-noise { arg freq = 0; var envgen; envgen = EnvGen.kr(Env.adsr(sustainLevel: 0.2)); Pan2.ar(SinOsc.ar(freq) * 0.5 * envgen, 1.0); } }