diff options
| author | Andrés Cuervo <andrescuervor@gmail.com> | 2023-05-11 21:47:48 +0000 |
|---|---|---|
| committer | Andrés Cuervo <andrescuervor@gmail.com> | 2023-05-11 21:47:48 +0000 |
| commit | 09ccccf4496798f54cb49110c3a06256cc7fea00 (patch) | |
| tree | e370cbf56690ed2f09c2f0db3a67794d2e437374 /virtual-programs/archive | |
| parent | Make circles proper circles, add hex- & octagon (diff) | |
| download | folk-09ccccf4496798f54cb49110c3a06256cc7fea00.tar.gz folk-09ccccf4496798f54cb49110c3a06256cc7fea00.zip | |
Remove some nested Whens
Diffstat (limited to 'virtual-programs/archive')
| -rw-r--r-- | virtual-programs/archive/highlight.folk | 12 | ||||
| -rw-r--r-- | virtual-programs/archive/image.folk | 16 | ||||
| -rw-r--r-- | virtual-programs/archive/points-up-test.folk | 6 | ||||
| -rw-r--r-- | virtual-programs/archive/points-up.folk | 30 |
4 files changed, 28 insertions, 36 deletions
diff --git a/virtual-programs/archive/highlight.folk b/virtual-programs/archive/highlight.folk index d4206622..79cdb4db 100644 --- a/virtual-programs/archive/highlight.folk +++ b/virtual-programs/archive/highlight.folk @@ -1,10 +1,8 @@ Wish $this has filename "highlight.folk" -When /someone/ wishes /thing/ is highlighted /color/ { - When $thing has region /region/ { - # it's not really correct to just stick a side-effect in the - # When handler like this. but we did it in Realtalk, and it - # was ok, so whatever for now - Display::fillRect device $x $y [expr {$x+$width}] [expr {$y+$height}] $color - } +When /someone/ wishes /thing/ is highlighted /color/ & /thing/ has region /region/ { + # it's not really correct to just stick a side-effect in the + # When handler like this. but we did it in Realtalk, and it + # was ok, so whatever for now + Display::fillRect device $x $y [expr {$x+$width}] [expr {$y+$height}] $color } diff --git a/virtual-programs/archive/image.folk b/virtual-programs/archive/image.folk index 4d2ca6fd..b3364d14 100644 --- a/virtual-programs/archive/image.folk +++ b/virtual-programs/archive/image.folk @@ -19,14 +19,12 @@ namespace eval ::image { namespace ensemble create } -When the camera frame is /f/ { - When $this has region /r/ { - lassign [projectorToCamera [lindex $r 0 0]] x0 y0 - lassign [projectorToCamera [lindex $r 0 2]] x1 y1 - set thisimage [image subimage $f \ - [expr {min($x0,$x1)}] [expr {min($y0,$y1)}] \ - [expr {int(abs($x1-$x0))}] [expr {int(abs($y1-$y0))}]] - Wish display runs [list Display::image {*}[lindex $r 0 0] $thisimage] - } +When the camera frame is /f/ & $this has region /r/ { + lassign [projectorToCamera [lindex $r 0 0]] x0 y0 + lassign [projectorToCamera [lindex $r 0 2]] x1 y1 + set thisimage [image subimage $f \ + [expr {min($x0,$x1)}] [expr {min($y0,$y1)}] \ + [expr {int(abs($x1-$x0))}] [expr {int(abs($y1-$y0))}]] + Wish display runs [list Display::image {*}[lindex $r 0 0] $thisimage] } Wish $this is outlined red diff --git a/virtual-programs/archive/points-up-test.folk b/virtual-programs/archive/points-up-test.folk index b0b90ae9..c4fcff4d 100644 --- a/virtual-programs/archive/points-up-test.folk +++ b/virtual-programs/archive/points-up-test.folk @@ -1,8 +1,6 @@ Wish $this is highlighted blue Wish $this points up -When $this points up at /target/ { - When $target has program code /code/ { - Wish $target is labelled "being pointed at" - } +When $this points up at /target/ & /target/ has program code /code/ { + Wish $target is labelled "being pointed at" } diff --git a/virtual-programs/archive/points-up.folk b/virtual-programs/archive/points-up.folk index 24a3a4c9..e5c12126 100644 --- a/virtual-programs/archive/points-up.folk +++ b/virtual-programs/archive/points-up.folk @@ -1,20 +1,18 @@ -When /someone/ wishes /rect/ points up { - When $rect is a rectangle with x /x/ y /y/ width /width/ height /height/ { - set wx [expr {$x+$width/2}] - set wy [expr {$y-40}] - set ww 5 - set wh 40 - Claim $rect-whisker is a rectangle with x $wx y $wy width $ww height $wh - Wish $rect-whisker is highlighted green +When /someone/ wishes /rect/ points up & /rect/ is a rectangle with x /x/ y /y/ width /width/ height /height/ { + set wx [expr {$x+$width/2}] + set wy [expr {$y-40}] + set ww 5 + set wh 40 + Claim $rect-whisker is a rectangle with x $wx y $wy width $ww height $wh + Wish $rect-whisker is highlighted green - When /target/ is a rectangle with x /tx/ y /ty/ width /tw/ height /th/ { - if {$target != $rect && \ - [rectanglesOverlap \ - [list $wx $wy] [list [expr {$wx+$ww}] [expr {$wy+$wh}]] \ - [list $tx $ty] [list [expr {$tx+$tw}] [expr {$ty+$th}]] \ - false]} { - Claim $rect points up at $target - } + When /target/ is a rectangle with x /tx/ y /ty/ width /tw/ height /th/ { + if {$target != $rect && \ + [rectanglesOverlap \ + [list $wx $wy] [list [expr {$wx+$ww}] [expr {$wy+$wh}]] \ + [list $tx $ty] [list [expr {$tx+$tw}] [expr {$ty+$th}]] \ + false]} { + Claim $rect points up at $target } } } |
