summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2023-10-13 22:24:29 +0000
committerOmar Rizwan <omar@omar.website>2023-10-13 22:24:29 +0000
commit3e1ed38511ed5bbfc58f86c95eb62ba9761b3099 (patch)
tree7f75320b00417dfbfe95781acbe1a87987e9fb27 /virtual-programs
parentMerge branch 'main' into osnr/multiple-on-process-blocks (diff)
downloadfolk-3e1ed38511ed5bbfc58f86c95eb62ba9761b3099.tar.gz
folk-3e1ed38511ed5bbfc58f86c95eb62ba9761b3099.zip
arc: Re-add arc support
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/display/arc.folk39
1 files changed, 39 insertions, 0 deletions
diff --git a/virtual-programs/display/arc.folk b/virtual-programs/display/arc.folk
new file mode 100644
index 00000000..e2412bf0
--- /dev/null
+++ b/virtual-programs/display/arc.folk
@@ -0,0 +1,39 @@
+# Example:
+# When $this has region /r/ {
+# lassign [region centroid $r] x y
+# Wish to draw an arc with x $x y $y start 0 arclen 1 thickness 3 radius 100 color green
+# }
+
+Wish the GPU compiles pipeline "arc" {{vec2 center float start float arclen float radius float thickness vec4 color} {
+ float r = radius + thickness;
+ vec2 vertices[4] = vec2[4](
+ center - r,
+ vec2(center.x + r, center.y - r),
+ vec2(center.x - r, center.y + r),
+ center + r
+ );
+ return vertices[gl_VertexIndex];
+} {
+ #define M_TWO_PI 6.283185307179586
+ start = clamp(start, 0, M_TWO_PI);
+ arclen = clamp(arclen, 0, M_TWO_PI);
+
+ float dist = length(gl_FragCoord.xy - center) - radius;
+ float angle = atan(-(gl_FragCoord.y - center.y), gl_FragCoord.x - center.x);
+
+ // Shift angle from [-pi, pi) to [0, 2*pi]
+ angle = (angle < 0) ? (angle + M_TWO_PI) : angle;
+ float end = start + arclen;
+
+ return ((dist < thickness && dist > 0.0) &&
+ ((end < M_TWO_PI && angle > start && angle < end) ||
+ (end >= M_TWO_PI && (angle > start || angle < end-M_TWO_PI)))) ? color : vec4(0, 0, 0, 0);
+
+}}
+
+When /someone/ wishes to draw an arc with /...options/ {
+ dict with options {
+ Wish the GPU draws pipeline "arc" with arguments \
+ [list [list $x $y] $start $arclen $radius $thickness [getColor $color]]
+ }
+}