summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2023-09-22 16:15:39 +0000
committerOmar Rizwan <omar@omar.website>2023-09-22 16:15:39 +0000
commitb7ee450f1d3f7cc6addcf03e3d1b77348c4aafae (patch)
treede74b77bbc6824236f459f390985b15b11c2c60f /virtual-programs
parentGpu: WIP: Pi fixes. (diff)
parentMerge pull request #84 from FolkComputer/osnr/operation-log (diff)
downloadfolk-b7ee450f1d3f7cc6addcf03e3d1b77348c4aafae.tar.gz
folk-b7ee450f1d3f7cc6addcf03e3d1b77348c4aafae.zip
Merge branch 'main' into osnr/vulkan-display
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/archive/log.folk13
-rw-r--r--virtual-programs/shapes.folk56
-rw-r--r--virtual-programs/sprites.folk32
3 files changed, 81 insertions, 20 deletions
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 "<ol>"]
+ foreach entry $log {
+ if {$entry eq "Evaluate"} {
+ lappend body {<li style="background-color: yellow;">Evaluate</li>}
+ } else {
+ lappend body "<li>[htmlEscape $entry]</li>"
+ }
+ }
+ lappend body "</ol>"
+ html [join $body ""]
+} \ No newline at end of file
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
diff --git a/virtual-programs/sprites.folk b/virtual-programs/sprites.folk
new file mode 100644
index 00000000..0e4fc87e
--- /dev/null
+++ b/virtual-programs/sprites.folk
@@ -0,0 +1,32 @@
+########
+# 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]
+ set angle [region angle $r]
+ Wish display runs [list Display::image {*}$center $subimage $angle 1]
+ }
+}
+
+Claim $this has demo {
+ Wish $this draws sprite $path with 8 frames and 4 columns
+}