# 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]] } }