% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nr-draw.R
\name{nr_rect}
\alias{nr_rect}
\title{Draw rectangles on a native raster image}
\usage{
nr_rect(
  nr,
  x,
  y,
  w,
  h,
  fill = "black",
  color = NA,
  hjust = 0,
  vjust = 0,
  linewidth = 1,
  use_alpha = TRUE
)
}
\arguments{
\item{nr}{native raster image}

\item{x, y}{coordinates of lower left corner of rectangle.  [vector]}

\item{w, h}{width and height of rectangle. [vector]}

\item{fill}{interior fill color [vector]}

\item{color}{outline color. Default: NA. [vector]}

\item{hjust, vjust}{specify horizontal and vertical justification of the 
handle on the \code{src} image to be placed at \code{(x, y)} within 
the \code{dst} image.
Default (0, 0) is to use the top-left corner of the image as the 
handle.
Use (0.5, 0.5) to centre the \code{src} image at the \code{dst} 
location \code{(x, y)}}

\item{linewidth}{Line linewidth. Default: 1.  If \code{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.}

\item{use_alpha}{Use alpha channel when drawing? Logical. Default: TRUE}
}
\value{
Invisibly return the supplied native raster image which was been
        modified in-place
}
\description{
Draw rectangles on a native raster image
}
\examples{
set.seed(1)
w <- 200
h <- 150
nr <- nr_new(w, h, 'grey80')

N <- 10
coords <- expand.grid(x = seq(2, w, length.out = N), 
                      y = seq(2, h, length.out = N))

cols <- sample(grDevices::heat.colors(nrow(coords)))

nr_rect(
  nr,
  x = coords$x,
  y = coords$y,
  w = w/N - 1,
  h = h/N - 1,
  fill = cols
)
plot(nr)
}
\seealso{
Other drawing functions: 
\code{\link{nr_circle}()},
\code{\link{nr_polygon}()},
\code{\link{nr_polyline}()},
\code{\link{nr_tri_mesh}()}
}
\concept{drawing functions}
