summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2023-10-30 06:04:13 +0000
committerGitHub <noreply@github.com>2023-10-30 06:04:13 +0000
commite21bb5eac49dfa9ad1ee5646a76fa6638253bf11 (patch)
tree4efa28ad3450f76363de472e494606e921521048 /virtual-programs
parentoutline: Slight optimization (diff)
parentscale sampling (diff)
downloadfolk-e21bb5eac49dfa9ad1ee5646a76fa6638253bf11.tar.gz
folk-e21bb5eac49dfa9ad1ee5646a76fa6638253bf11.zip
Merge pull request #108 from FolkComputer/cs/tweaks
scaled images, uncollected outlines, auto-neighbors
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/display/image.folk16
-rw-r--r--virtual-programs/images.folk8
-rw-r--r--virtual-programs/intersect.folk6
-rw-r--r--virtual-programs/outline.folk18
4 files changed, 22 insertions, 26 deletions
diff --git a/virtual-programs/display/image.folk b/virtual-programs/display/image.folk
index 23246d45..7415b260 100644
--- a/virtual-programs/display/image.folk
+++ b/virtual-programs/display/image.folk
@@ -5,17 +5,17 @@ On process "display" {
dict set ::pipelines "image" [Gpu::pipeline {sampler2D image vec2 imageSize
vec2 pos float radians float scale
fn rotate} {
- vec2 a = pos + rotate(-imageSize/2, -radians);
- vec2 b = pos + rotate(vec2(imageSize.x, -imageSize.y)/2, -radians);
- vec2 c = pos + rotate(imageSize/2, -radians);
- vec2 d = pos + rotate(vec2(-imageSize.x, imageSize.y)/2, -radians);
+ vec2 a = pos + scale * (rotate(-imageSize/2, -radians));
+ vec2 b = pos + scale * (rotate(vec2(imageSize.x, -imageSize.y)/2, -radians));
+ vec2 c = pos + scale * (rotate(imageSize/2, -radians));
+ vec2 d = pos + scale * (rotate(vec2(-imageSize.x, imageSize.y)/2, -radians));
vec2 vertices[4] = vec2[4](a, b, d, c);
return vertices[gl_VertexIndex];
} {fn invBilinear fn rotate} {
- vec2 a = pos + rotate(-imageSize/2, -radians);
- vec2 b = pos + rotate(vec2(imageSize.x, -imageSize.y)/2, -radians);
- vec2 c = pos + rotate(imageSize/2, -radians);
- vec2 d = pos + rotate(vec2(-imageSize.x, imageSize.y)/2, -radians);
+ vec2 a = pos + scale * (rotate(-imageSize/2, -radians));
+ vec2 b = pos + scale * (rotate(vec2(imageSize.x, -imageSize.y)/2, -radians));
+ vec2 c = pos + scale * (rotate(imageSize/2, -radians));
+ vec2 d = pos + scale * (rotate(vec2(-imageSize.x, imageSize.y)/2, -radians));
vec2 p = gl_FragCoord.xy;
vec2 uv = invBilinear(p, a, b, c, d);
if( max( abs(uv.x-0.5), abs(uv.y-0.5))<0.5 ) {
diff --git a/virtual-programs/images.folk b/virtual-programs/images.folk
index d8bcaf55..1be51424 100644
--- a/virtual-programs/images.folk
+++ b/virtual-programs/images.folk
@@ -343,7 +343,7 @@ When /someone/ wishes /p/ displays camera slice /slice/ & /p/ has region /r/ {
Wish to draw an image with center $center image $slice radians 0 scale 1
}
-When /someone/ wishes /p/ displays image /im/ {
+When /someone/ wishes /p/ displays image /im/ with scale /s/ {
set im [image load $im]
When $p has region /r/ {
# Compute a scale for im that will fit in the region width/height
@@ -354,10 +354,14 @@ When /someone/ wishes /p/ displays image /im/ {
# set scale [expr {min($width / [image width $im],
# $height / [image height $im])}]
# Wish $p is labelled $im
- Wish to draw an image with center $center image $im radians [region angle $r]
+ Wish to draw an image with center $center image $im radians [region angle $r] scale $s
}
# On unmatch {
# # HACK: Leaves time for the display to finish trying to display this.
# after 5000 [list image freeJpeg $im]
# }
}
+
+When /someone/ wishes /p/ displays image /im/ {
+ Wish $p displays image $im with scale 1
+}
diff --git a/virtual-programs/intersect.folk b/virtual-programs/intersect.folk
index 7755acbd..1aea9695 100644
--- a/virtual-programs/intersect.folk
+++ b/virtual-programs/intersect.folk
@@ -25,4 +25,8 @@ When /someone/ wishes /p/ has neighbors & /p/ has region /r/ & /p2/ has region /
#Display::stroke [list [list $b2MaxX $b2MaxY] {500 500}] 3 white
#Display::stroke [list [list $b2MinX $b2MinY] [list $b2MaxX $b2MaxY]] 10 blue
}
-} \ No newline at end of file
+}
+
+When when /p/ has neighbor /n/ /lambda/ with environment /e/ {
+ Wish $p has neighbors
+}
diff --git a/virtual-programs/outline.folk b/virtual-programs/outline.folk
index 1d6411cb..13f060b1 100644
--- a/virtual-programs/outline.folk
+++ b/virtual-programs/outline.folk
@@ -9,21 +9,9 @@ proc loopRegion {edges vertices width color} {
Wish the GPU draws pipeline "line" with instances $instances
}
-When the collected matches for [list /someone/ wishes /thing/ is outlined /color/] are /matches/ {
- set thingColors [dict create]
- foreach match $matches {
- dict lappend thingColors [dict get $match thing] [dict get $match color]
- }
- foreach thing [dict keys $thingColors] {
- When $thing has region /region/ {
- set thickness 0
- foreach color [dict get $thingColors $thing] {
- # FIXME: assumes path
- lassign $region vertices edges
- loopRegion $edges $vertices [incr thickness 3] $color
- }
- }
- }
+When /someone/ wishes /thing/ is outlined /color/ & /thing/ has region /region/ {
+ lassign $region vertices edges
+ loopRegion $edges $vertices 3 $color
}
When /someone/ wishes /thing/ is outlined thick /color/ & /thing/ has region /region/ {