Skip to content

lcd.drawLine

since 1.1.0

Draw a line.

lcd.drawLine(x1, y1, x2, y2)

Parameters

Name Type Required Description
x1 number yes X coordinate of the start point
y1 number yes Y coordinate of the start point
x2 number yes X coordinate of the end point
y2 number yes Y coordinate of the end point

Returns

Nothing.

Examples

-- a simple graph of the last N samples
local function drawGraph(samples, n, x, y, w, h, min, max)
  local step = w / (n - 1)
  local prevX, prevY
  for i = 1, n do
    local v = samples[i] or min
    local px = x + (i - 1) * step
    local py = y + h - (v - min) / (max - min) * h
    if prevX then lcd.drawLine(prevX, prevY, px, py) end
    prevX, prevY = px, py
  end
end

Use lcd.pen(PEN_DOTTED) before drawing for dotted lines (grid lines, thresholds).

Used in

Real-world usage

Called 133 times across 9 open-source Ethos Lua projects. A few short excerpts:
lcd.drawLine(x1, y1, x2, y2)

src/dashx/app/modules/logs/logs_view.lua:279

lcd.drawLine(x - halfW, y, x + halfW, y)

src/ethos-arcade/games/missilecmd/game.lua:1809

lcd.drawLine(cx, cy, playerTipX, playerTipY)

src/ethos-heli-training/games/piro-rate-lock/game.lua:696