nr_line: Draw lines on a native raster image

View source: R/nr-draw.R

nr_lineR Documentation

Draw lines on a native raster image

Description

Uses Bresenham's algorithm to draw lines. No antialiasing.

Usage

nr_line(nr, x1, y1, x2, y2, color = "black", linewidth = 1, use_alpha = TRUE)

Arguments

nr

native raster image

x1, y1, x2, y2

Vectors of coordinates of endpoints of line

color

Color as a character string. Either a standard R color (e.g. 'blue', 'white') or a hex color of the form #rrggbbaa, #rrggbb, #rgba or #rgb

linewidth

Line linewidth. Default: 1. If linewidth = 1 then a naive version of Bresenham is used to draw the points. If linewidth is greater than 1, then the line is convert to a triangle strip and rendered as polygons.

use_alpha

Use alpha channel when drawing? Logical. Default: TRUE

Value

Invisibly return the supplied native raster image which was been modified in-place

Examples

w <- 200
h <- 150
nr <- nr_new(w, h, 'grey80')

N <- 40
nr_line(
  nr,
  x1 = seq(0, 2*w, length.out =  N), y1 = 0,
  x2 = 0, y2 = seq(0, 2 * h, length.out = N),
  color = rainbow(N)
)

plot(nr)


nara documentation built on May 28, 2026, 5:07 p.m.