lcd.drawAnnulusSector¶
since 1.1.0
Draw a circular sector.
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
x |
number | yes | X coordinate |
y |
number | yes | Y coordinate |
intR |
number | yes | the inner circle radius, if it is equal to 0, a fan-shaped can be drawn |
extR |
number | yes | the external circle radius |
startAngle |
number | yes | starting angle of the circular sector |
endAngle |
number | yes | ending angle of the circular sector |
Returns¶
Nothing.
Examples¶
Angles are degrees, 0–360, with 0 at the top, increasing clockwise. Open-source dashboards split arcs wider than 180° into two calls:
local function drawArc(cx, cy, inner, outer, a1, a2)
local sweep = (a2 - a1) % 360
if sweep <= 180 then
lcd.drawAnnulusSector(cx, cy, inner, outer, a1, a2)
else
local mid = (a1 + sweep / 2) % 360
lcd.drawAnnulusSector(cx, cy, inner, outer, a1, mid)
lcd.drawAnnulusSector(cx, cy, inner, outer, mid, a2)
end
end
-- a 270° gauge from bottom-left (225) to bottom-right (135)
drawArc(cx, cy, r * 0.75, r, 225, (225 + 270 * percent / 100) % 360)
Full example in Drawing on screen.
Real-world usage¶
Called 16 times across 4 open-source Ethos Lua projects. A few short excerpts:
function utils.drawArc(cx, cy, radius, thickness, startAngle, endAngle, color)
lcd.color(color)
local outer = radius
local inner = math.max(1, radius - (thickness or 6))
startAngle = startAngle % 360
endAngle = endAngle % 360
if endAngle <= startAngle then endAngle = endAngle + 360 end
local sweep = endAngle - startAngle
if sweep <= 180 then
lcd.drawAnnulusSector(cx, cy, inner, outer, startAngle, endAngle)
else
local mid = startAngle + sweep / 2
lcd.drawAnnulusSector(cx, cy, inner, outer, startAngle, mid)
lcd.drawAnnulusSector(cx, cy, inner, outer, mid, endAngle)
end
end