folkarc:touch
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| folkarc:touch [2023/11/03 19:49] – created discord | folkarc:touch [2024/09/15 19:11] (current) – discord | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Tablet-based touch input ====== | ||
| + | |||
| + | |||
| Use this and navigate your tablet to ''/ | Use this and navigate your tablet to ''/ | ||
| <file tcl> | <file tcl> | ||
| - | # Tablet Touch Handler | + | # Tablet Touch Handler |
| Wish the web server handles route "/ | Wish the web server handles route "/ | ||
| html { | html { | ||
| < | < | ||
| + | |||
| <body > | <body > | ||
| <span id=" | <span id=" | ||
| + | <img src=" | ||
| + | <button onClick=" | ||
| <canvas id=" | <canvas id=" | ||
| + | |||
| </ | </ | ||
| < | < | ||
| Line 16: | Line 21: | ||
| let width = el.getBoundingClientRect().width; | let width = el.getBoundingClientRect().width; | ||
| let height = el.getBoundingClientRect().height; | let height = el.getBoundingClientRect().height; | ||
| + | |||
| const program = " | const program = " | ||
| + | |||
| function touch(event) { | function touch(event) { | ||
| event.preventDefault(); | event.preventDefault(); | ||
| Line 25: | Line 30: | ||
| } | } | ||
| } | } | ||
| + | |||
| + | /* Get the documentElement (< | ||
| + | let elem = document.documentElement; | ||
| + | |||
| + | /* View in fullscreen */ | ||
| + | function openFullscreen() { | ||
| + | if (elem.requestFullscreen) { | ||
| + | elem.requestFullscreen(); | ||
| + | } else if (elem.webkitRequestFullscreen) { /* Safari */ | ||
| + | elem.webkitRequestFullscreen(); | ||
| + | } else if (elem.msRequestFullscreen) { /* IE11 */ | ||
| + | elem.msRequestFullscreen(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| el.addEventListener(" | el.addEventListener(" | ||
| el.addEventListener(" | el.addEventListener(" | ||
| + | |||
| function stop_touch(event) { send(`Commit { Claim ${program} has no touch }`); } | function stop_touch(event) { send(`Commit { Claim ${program} has no touch }`); } | ||
| el.addEventListener(" | el.addEventListener(" | ||
| + | |||
| let ws; | let ws; | ||
| let send; | let send; | ||
| Line 36: | Line 57: | ||
| ws = new WebSocket(window.location.origin.replace(" | ws = new WebSocket(window.location.origin.replace(" | ||
| send = function(s) { ws.send(s); } | send = function(s) { ws.send(s); } | ||
| + | |||
| ws.onopen = () => { document.getElementById(' | ws.onopen = () => { document.getElementById(' | ||
| ws.onclose = window.onbeforeunload = () => { | ws.onclose = window.onbeforeunload = () => { | ||
| document.getElementById(' | document.getElementById(' | ||
| + | |||
| send(`Commit { Claim ${program} has no touch }`); | send(`Commit { Claim ${program} has no touch }`); | ||
| setTimeout(() => { wsConnect(); | setTimeout(() => { wsConnect(); | ||
| Line 63: | Line 84: | ||
| }; | }; | ||
| wsConnect(); | wsConnect(); | ||
| + | |||
| </ | </ | ||
| </ | </ | ||
| + | |||
| } | } | ||
| + | } | ||
| + | |||
| + | |||
| + | When tag 48712 has corners /corners/ { | ||
| + | # Setting aside this tag space (48600 to 48713) for calibration. | ||
| + | |||
| + | set tagCorners [lmap p $corners {:: | ||
| + | |||
| + | 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 | ||
| + | | ||
| } | } | ||
| </ | </ | ||
| Line 80: | Line 129: | ||
| Wish to draw a circle with x $posX y $posY radius 20 thickness 6 color white | Wish to draw a circle with x $posX y $posY radius 20 thickness 6 color white | ||
| | | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Tablet pointer! | ||
| + | |||
| + | <file tcl> | ||
| + | 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 [[: | ||
| + | |||
| + | <file tcl> | ||
| + | # Supercollider touch demo | ||
| + | |||
| + | When /thing/ claims /thing2/ has touch number /i/ with x /x/ and y /y/ { | ||
| + | set freq [expr {int($Display:: | ||
| + | |||
| + | 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: | ||
| + | Pan2.ar(SinOsc.ar(freq) * 0.5 * envgen, 1.0); | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
folkarc/touch.1699040996.txt.gz · Last modified: by discord
