Skip to content

Commit

Permalink
Merge pull request #108 from FolkComputer/cs/tweaks
Browse files Browse the repository at this point in the history
scaled images, uncollected outlines, auto-neighbors
  • Loading branch information
osnr authored Oct 30, 2023
2 parents ed868c6 + 37ccfee commit e21bb5e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
16 changes: 8 additions & 8 deletions virtual-programs/display/image.folk
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
8 changes: 6 additions & 2 deletions virtual-programs/images.folk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
6 changes: 5 additions & 1 deletion virtual-programs/intersect.folk
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

When when /p/ has neighbor /n/ /lambda/ with environment /e/ {
Wish $p has neighbors
}
18 changes: 3 additions & 15 deletions virtual-programs/outline.folk
Original file line number Diff line number Diff line change
Expand Up @@ -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/ {
Expand Down

0 comments on commit e21bb5e

Please sign in to comment.