From b8bffe3cf3596239a569284043174164d2785475 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Sat, 7 Oct 2023 01:10:18 +0000 Subject: Implement arc primitive The arc is specified as start angle (from positive x axis) plus arc length (both in the range [0, 2*pi)) --- virtual-programs/display.folk | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'virtual-programs') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index f92afb67..546e1861 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -190,6 +190,38 @@ On process { } } + variable arc [Gpu::pipeline {vec2 center float start float arclen float radius float thickness vec4 color int filled} { + 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); + + }] + + proc arc {x y start arclen radius thickness color {filled false}} { + variable arc + Gpu::draw $arc [list $x $y] $start $arclen $radius $thickness [getColor $color] [ne $filled "false"] + } + # TODO: Fix bool support. variable circle [Gpu::pipeline {vec2 center float radius float thickness vec4 color int filled} { float r = radius + thickness; -- cgit v1.2.3 From b2b4768a73458ca214198c9d9e751aceb036ef80 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Sat, 7 Oct 2023 21:49:11 +0000 Subject: Add claim for display size --- virtual-programs/display.folk | 2 ++ 1 file changed, 2 insertions(+) (limited to 'virtual-programs') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index f92afb67..36a370e7 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -23,6 +23,8 @@ namespace eval ::Display { uplevel [list Wish display runs [list $func {*}$args] on layer $::Display::LAYER] } } + + Claim the display Display has width $::Display::WIDTH height $::Display::HEIGHT } On process { -- cgit v1.2.3 From f77cbd902cf1d352661261cd0fbf53d2b6bc1dba Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Mon, 9 Oct 2023 13:36:11 -0400 Subject: display: Remove filled arg from arc --- virtual-programs/display.folk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index 546e1861..bae5951f 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -190,7 +190,7 @@ On process { } } - variable arc [Gpu::pipeline {vec2 center float start float arclen float radius float thickness vec4 color int filled} { + variable arc [Gpu::pipeline {vec2 center float start float arclen float radius float thickness vec4 color} { float r = radius + thickness; vec2 vertices[4] = vec2[4]( center - r, @@ -217,9 +217,9 @@ On process { }] - proc arc {x y start arclen radius thickness color {filled false}} { + proc arc {x y start arclen radius thickness color} { variable arc - Gpu::draw $arc [list $x $y] $start $arclen $radius $thickness [getColor $color] [ne $filled "false"] + Gpu::draw $arc [list $x $y] $start $arclen $radius $thickness [getColor $color] } # TODO: Fix bool support. -- cgit v1.2.3