From 0f0bf7133437277dd80205682d2cff21009eb19f Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 14 Sep 2023 00:11:59 -0400 Subject: Make metrics non-reactive + put recollect before unmatch We'll take the interim states for now to avoid having to recreate all tags. --- virtual-programs/apriltags.folk | 3 ++- virtual-programs/archive/metrics.folk | 8 ++++---- virtual-programs/camera.folk | 4 ++++ virtual-programs/display.folk | 7 +++---- 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/apriltags.folk b/virtual-programs/apriltags.folk index ac2c4f8b..c7ae25b7 100644 --- a/virtual-programs/apriltags.folk +++ b/virtual-programs/apriltags.folk @@ -114,6 +114,7 @@ On process { set ::tagsCache [dict create] # TODO: Garbage-collect this cache. +set ::aprilTime none When the collected matches for [list /someone/ detects tags /tags/ at /timestamp/ in time /aprilTime/] are /matches/ { set tagsSeen [dict create] foreach match $matches { @@ -136,5 +137,5 @@ When the collected matches for [list /someone/ detects tags /tags/ at /timestamp Claim tag $id has center [dict get $tag center] size [dict get $tag size] Claim tag $id has corners [dict get $tag corners] } - Claim the AprilTag time is [lmap m $matches {dict get $m aprilTime}] + set ::aprilTime [lmap m $matches {dict get $m aprilTime}] } diff --git a/virtual-programs/archive/metrics.folk b/virtual-programs/archive/metrics.folk index fe6baebd..e5389512 100644 --- a/virtual-programs/archive/metrics.folk +++ b/virtual-programs/archive/metrics.folk @@ -1,13 +1,13 @@ -When $::thisNode has step count /c/ & the camera time is /cameraTime/ & the AprilTag time is /aprilTime/ { +When $::thisNode has step count /c/ { Wish $this is labelled [string trim " Metrics ---- step count: $c step time: $::stepTime -camera time: $cameraTime -AprilTag time: $aprilTime -display time: $::Display::displayTime +camera time: $::cameraTime +AprilTag time: $::aprilTime +display time: $::displayTime "] } diff --git a/virtual-programs/camera.folk b/virtual-programs/camera.folk index 0a95c8f0..428c4195 100644 --- a/virtual-programs/camera.folk +++ b/virtual-programs/camera.folk @@ -29,6 +29,10 @@ On process { } } +set ::cameraTime none +When the camera time is /cameraTime/ { + set ::cameraTime $cameraTime +} # For backward compatibility. When the camera frame is /grayFrame/ at /timestamp/ { Claim the camera frame is $grayFrame diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index d3f6b610..75ad5cf1 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -35,8 +35,6 @@ namespace eval ::Display { proc fillPolygon args { uplevel [list Wish display runs [list Display::fillPolygon {*}$args] on layer $::Display::LAYER] } - - variable displayTime none } On process { @@ -87,7 +85,8 @@ On process { Step } } -# TODO: remove this compatibility hack + +set ::displayTime none When the display time is /displayTime/ { - set ::Display::displayTime $displayTime + set ::displayTime $displayTime } -- cgit v1.2.3 From 6ab1125e5ab87359d35202ddcdd148883baad05b Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 14 Sep 2023 00:19:39 -0400 Subject: Add log.folk example. --- virtual-programs/archive/log.folk | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 virtual-programs/archive/log.folk (limited to 'virtual-programs') diff --git a/virtual-programs/archive/log.folk b/virtual-programs/archive/log.folk new file mode 100644 index 00000000..872f3fe2 --- /dev/null +++ b/virtual-programs/archive/log.folk @@ -0,0 +1,13 @@ +Wish the web server handles route "/log$" with handler { + set log [Evaluator::getOperationLog] + set body [list "
    "] + foreach entry $log { + if {$entry eq "Evaluate"} { + lappend body {
  1. Evaluate
  2. } + } else { + lappend body "
  3. [htmlEscape $entry]
  4. " + } + } + lappend body "
" + html [join $body ""] +} \ No newline at end of file -- cgit v1.2.3 From a0646f87875cdc16d2785580792d04e6c1b1ac62 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Tue, 19 Sep 2023 21:46:37 -0400 Subject: Draw shape around center point and support rotation --- virtual-programs/shapes.folk | 56 ++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/shapes.folk b/virtual-programs/shapes.folk index 2864b13c..08106475 100644 --- a/virtual-programs/shapes.folk +++ b/virtual-programs/shapes.folk @@ -1,24 +1,37 @@ # numPoints 2 => line # numPoints 3 => triangle # numPoints 4 => square -proc shape {numPoints x y r {color white} {filled false} args} { - set start [list $x $y] - set points [list $start] - set i 0 - while {$i < $numPoints} { - incr i - set angle [expr {2 * 3.14159 * $i / $numPoints}] - set x [expr {$x + $r * cos($angle)}] - set y [expr {$y + $r * sin($angle)}] - lappend points [list $x $y] +proc shape {numPoints c r {angle 0} {color white} {filled false} args} { + set p [list 0 0] + set center $p + set points [list $p] + + set incr [expr {2 * 3.14159 / $numPoints}] + set a [expr {$incr + 3.14159}] + for {set i 0} {$i < $numPoints} {incr i} { + set p [vec2 add $p [vec2 scale [list [expr {cos($a)}] [expr {sin($a)}]] $r]] + lappend points $p + # Accumulate center + set center [vec2 add $center $p] + set a [expr {$a + $incr}] } + set center [vec2 scale $center [expr {1.0/$numPoints}]] + + set points [lmap v $points { + set v [vec2 sub $v $center] + set v [vec2 rotate $v $angle] + set v [vec2 add $v $c] + set v + }] + if {$filled} { Display::fillPolygon $points $color } else { - Display::stroke $points 5 $color + Display::stroke $points 1 $color } } + When /someone/ wishes /p/ draws a /color/ /shape/ offset /offsetVector/ & /p/ has region /r/ { lassign [region centroid $r] x y set width [region width $r] @@ -32,35 +45,38 @@ When /someone/ wishes /p/ draws a /color/ /shape/ offset /offsetVector/ & /p/ ha set y [expr {$y + $offsetY}] } + set angle [region angle $r] + set p [list $x $y] + # puts "drawing a $shape at $x $y with width $width and height $height" set radius 50 switch -nocase $shape { triangle { - shape 3 $x $y $radius $color + shape 3 $p $radius $angle $color } square { - shape 4 $x $y $radius $color + shape 4 $p $radius $angle $color } pentagon { - shape 5 $x $y $radius $color + shape 5 $p $radius $angle $color } hexagon { - shape 6 $x $y $radius $color + shape 6 $p $radius $angle $color } septagon { - shape 7 $x $y $radius $color + shape 7 $p $radius $angle $color } octagon { - shape 8 $x $y $radius $color + shape 8 $p $radius $angle $color } nonagon { - shape 9 $x $y $radius $color + shape 9 $p $radius $angle $color } circle { Display::circle $x $y $radius 5 $color } default { - shape 2 $x $y $radius $color + shape 2 $p $radius $angle $color } } } @@ -99,7 +115,7 @@ Claim $this has demo { lassign [region centroid $r] x y set fill [expr {round(sin($t) * 2) % 2 == 0 ? true : false}] set y [- $y 150] - shape 4 [- $x 100] $y 60 white $fill + shape 4 [list [- $x 100] $y] 0 60 white $fill } Wish $this is outlined white -- cgit v1.2.3 From 05d2ae708c271ad9444626f3bd62b11c129760a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Cuervo?= Date: Wed, 20 Sep 2023 17:19:53 -0400 Subject: Add sprite wish --- virtual-programs/sprites.folk | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 virtual-programs/sprites.folk (limited to 'virtual-programs') diff --git a/virtual-programs/sprites.folk b/virtual-programs/sprites.folk new file mode 100644 index 00000000..3e736500 --- /dev/null +++ b/virtual-programs/sprites.folk @@ -0,0 +1,31 @@ +######## +# Could extend this to draw from camera with: +# Wish $this has thumbnail grid with 8 frames and 4 columns +# When $this has thumbnail grid /thumbnails/ { +# Wish $this draws $thumbnails; # Would need to query $thumnails for its frameCount and columns +# } +####### + +# - path get prepended with ~/folk-images/ +When /anyone/ wishes /p/ draws sprite /path/ with /frameCount/ frames and /columns/ columns { + set im [image load $path] + set sheetwidth [image width $im] + set sheetHeight [image height $im] + set spriteWidth [/ $sheetwidth $columns] + set rows [/ $frameCount $columns] + set spriteHeight [/ $sheetHeight $rows] + + When the clock time is /t/ & $p has region /r/ { + set frameNumber [expr {round ($t * 60 / $columns) % $frameCount}] + set x [* [% $frameNumber $columns] $spriteWidth] + set y [* [% $frameNumber $rows] $spriteHeight] + + set subimage [image subimage $im $x $y $spriteWidth $spriteHeight] + set center [region centroid $r] + Wish display runs [list Display::image {*}$center $subimage 0 1] + } +} + +Claim $this has demo { + Wish $this draws sprite $path with 8 frames and 4 columns +} -- cgit v1.2.3 From a720983725ce6b47703c71e9aa17214a7df17298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Cuervo?= Date: Wed, 20 Sep 2023 17:23:00 -0400 Subject: Orient images to their pages --- virtual-programs/sprites.folk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/sprites.folk b/virtual-programs/sprites.folk index 3e736500..0e4fc87e 100644 --- a/virtual-programs/sprites.folk +++ b/virtual-programs/sprites.folk @@ -22,7 +22,8 @@ When /anyone/ wishes /p/ draws sprite /path/ with /frameCount/ frames and /colum set subimage [image subimage $im $x $y $spriteWidth $spriteHeight] set center [region centroid $r] - Wish display runs [list Display::image {*}$center $subimage 0 1] + set angle [region angle $r] + Wish display runs [list Display::image {*}$center $subimage $angle 1] } } -- cgit v1.2.3