| Title: | Creative Coding Pipeline for R |
|---|---|
| Description: | A toy R wrapper for 'rust-skia' <https://github.com/rust-skia/rust-skia> (the Rust crate 'skia_safe' <https://rust-skia.github.io/doc/skia_safe/>, a binding for 'Skia' <https://skia.org/>). |
| Authors: | Akiru Kato [aut, cre], Jeroen Ooms [cph] |
| Maintainer: | Akiru Kato <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.8.1 |
| Built: | 2026-05-15 10:23:35 UTC |
| Source: | https://github.com/paithiov909/skiagd |
Adds one or more elliptical arcs to an existing picture.
add_arc( img, ltrb, rsx_trans = matrix(c(1, 0, 0, 0, 0, 0), nrow(ltrb), 6, byrow = TRUE), angle = matrix(c(0, 360), nrow(ltrb), 2, byrow = TRUE), use_center = TRUE, ..., props = paint() )add_arc( img, ltrb, rsx_trans = matrix(c(1, 0, 0, 0, 0, 0), nrow(ltrb), 6, byrow = TRUE), angle = matrix(c(0, 360), nrow(ltrb), 2, byrow = TRUE), use_center = TRUE, ..., props = paint() )
img |
A raw vector of a serialized picture. |
ltrb |
A numeric matrix (or a data-frame-like object) with 4 numeric columns (left, top, right, bottom), where each row defines the bounding box of the oval that contains the arc. |
rsx_trans |
A numeric matrix (or a data-frame-like object) with 6 columns where each row represents an RSX transform. Each column of the matrix corresponds to:
|
angle |
A numeric matrix (or a data-frame-like object) with 2 numeric columns giving the sweep angles (in degrees) for each arc. |
use_center |
A logical value indicating whether to draw the wedge edges, i.e., lines from the oval center to the arc end points (like a "Pac-Man" wedge). |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The number of arcs is determined by nrow(ltrb). The number of rows of
rsx_trans and angle, and the lengths of sigma and width (and the number
of columns of color) must match this number.
The drawing attributes sigma, width, and color can be supplied via ....
If they are not supplied, they are taken from props and recycled to all arcs.
When use_center = TRUE and the sweep in angle describes a full circle
(e.g., c(0, 360)), the geometry includes the wedge edges from the oval's
rightmost point toward the center. Depending on style, this may be filled
and thus not visually apparent.
A raw vector containing a serialized picture.
Arcs are drawn from an oval specified by a rounded rectangle internally,
and this geometry does not support rotation.
If the rotation angle in rsx_trans is not zero, this function will error.
To draw rotated arcs or more general shapes, use add_path() instead.
## Not run: # Arrange arcs by shifting coordinates in `ltrb` arcs <- dplyr::tibble( l = c(60, 260, 60), t = c(60, 60, 240), r = c(220, 420, 220), b = c(200, 200, 380), angle_start = c(0, 45, 0), angle_end = c(270, 270, 360) ) canvas("white") |> add_arc( ltrb = dplyr::select(arcs, l, t, r, b), angle = dplyr::select(arcs, angle_start, angle_end), use_center = TRUE ) |> draw_img() # Arrange arcs by translating the same `ltrb` via `rsx_trans` arcs <- dplyr::tibble( l = 60, t = 60, r = 220, b = 200, angle_start = c(0, 0, 0), angle_end = c(270, 180, 360) ) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, tx = c(0, 200, 0), ty = c(0, 0, 180), ax = 0, ay = 0 ) canvas("white") |> add_arc( ltrb = dplyr::select(arcs, l, t, r, b), rsx_trans = rsx_trans, angle = dplyr::select(arcs, angle_start, angle_end), use_center = TRUE ) |> draw_img() ## End(Not run)## Not run: # Arrange arcs by shifting coordinates in `ltrb` arcs <- dplyr::tibble( l = c(60, 260, 60), t = c(60, 60, 240), r = c(220, 420, 220), b = c(200, 200, 380), angle_start = c(0, 45, 0), angle_end = c(270, 270, 360) ) canvas("white") |> add_arc( ltrb = dplyr::select(arcs, l, t, r, b), angle = dplyr::select(arcs, angle_start, angle_end), use_center = TRUE ) |> draw_img() # Arrange arcs by translating the same `ltrb` via `rsx_trans` arcs <- dplyr::tibble( l = 60, t = 60, r = 220, b = 200, angle_start = c(0, 0, 0), angle_end = c(270, 180, 360) ) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, tx = c(0, 200, 0), ty = c(0, 0, 180), ax = 0, ay = 0 ) canvas("white") |> add_arc( ltrb = dplyr::select(arcs, l, t, r, b), rsx_trans = rsx_trans, angle = dplyr::select(arcs, angle_start, angle_end), use_center = TRUE ) |> draw_img() ## End(Not run)
Draws a PNG sprite multiple times (as an atlas) onto an existing picture.
add_atlas(img, png, rsx_trans, ..., props = paint())add_atlas(img, png, rsx_trans, ..., props = paint())
img |
A raw vector of a serialized picture. |
png |
A raw vector of a PNG image to be used as a sprite. This can be
created by |
rsx_trans |
A numeric matrix (or a data-frame-like object) with 6 columns where each row represents an RSX transform. Each column of the matrix corresponds to:
|
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The number of sprites drawn is determined by nrow(rsx_trans). Each row of
rsx_trans specifies an RSX transform applied to the sprite (scale, rotation,
translation, and anchor offsets).
A raw vector containing a serialized picture.
To create sprites (or canvases) of a specific size,
you may need to fix the size of the current graphics device (e.g., using a dummy device)
or supply canvas_size via props = paint(canvas_size = ...),
because drawing functions use props[["canvas_size"]] at each call.
## Not run: # To fix the canvas size to 48x16, open a dummy device png(nullfile(), width = 48, height = 16) # Create a simple arrow sprite (48x16) as a PNG arrow_png <- canvas("transparent") |> add_line( from = matrix(c(4, 8), ncol = 2), to = matrix(c(44, 8), ncol = 2) ) |> add_line( from = matrix(c( 36, 4, 44, 8, 36, 12 ), ncol = 2, byrow = TRUE), to = matrix(c( 44, 8, 36, 12, 44, 8 ), ncol = 2, byrow = TRUE) ) |> as_png() # Close the dummy device dev.off() # Place the sprite with different rotations and positions # (anchor offsets set to the sprite center: 24, 8) rsx_trans <- dplyr::tibble( sc = 1, rot = c(0, pi / 6, pi / 3, pi / 2, pi * 3 / 4), tx = c(100, 200, 300, 200, 100), ty = c(100, 100, 100, 200, 200), ax = 24, ay = 8 ) # Open a dummy device again png(nullfile(), width = 400, height = 300) img <- canvas("white") |> add_atlas(arrow_png, rsx_trans = rsx_trans) # Close the dummy device dev.off() # Draw the picture draw_img(img) ## End(Not run)## Not run: # To fix the canvas size to 48x16, open a dummy device png(nullfile(), width = 48, height = 16) # Create a simple arrow sprite (48x16) as a PNG arrow_png <- canvas("transparent") |> add_line( from = matrix(c(4, 8), ncol = 2), to = matrix(c(44, 8), ncol = 2) ) |> add_line( from = matrix(c( 36, 4, 44, 8, 36, 12 ), ncol = 2, byrow = TRUE), to = matrix(c( 44, 8, 36, 12, 44, 8 ), ncol = 2, byrow = TRUE) ) |> as_png() # Close the dummy device dev.off() # Place the sprite with different rotations and positions # (anchor offsets set to the sprite center: 24, 8) rsx_trans <- dplyr::tibble( sc = 1, rot = c(0, pi / 6, pi / 3, pi / 2, pi * 3 / 4), tx = c(100, 200, 300, 200, 100), ty = c(100, 100, 100, 200, 200), ax = 24, ay = 8 ) # Open a dummy device again png(nullfile(), width = 400, height = 300) img <- canvas("white") |> add_atlas(arrow_png, rsx_trans = rsx_trans) # Close the dummy device dev.off() # Draw the picture draw_img(img) ## End(Not run)
Adds one or more circles to an existing picture.
add_circle(img, center, radius, ..., props = paint())add_circle(img, center, radius, ..., props = paint())
img |
A raw vector of a serialized picture. |
center |
A numeric matrix (or a data-frame-like object) with 2 columns (x and y), where each row represents the center of a circle. |
radius |
A numeric vector of radii, one for each circle. |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The number of circles is determined by nrow(center). The length of radius
must match this number.
The drawing attributes sigma, width, and color can be supplied via ....
If they are not supplied, they are taken from props and recycled to all circles.
A raw vector containing a serialized picture.
## Not run: circles <- dplyr::tibble( x = c(100, 300), y = c(100, 200), radius = c(40, 60) ) canvas("white") |> add_circle( center = dplyr::select(circles, x, y), radius = dplyr::pull(circles, radius) ) |> draw_img() ## End(Not run)## Not run: circles <- dplyr::tibble( x = c(100, 300), y = c(100, 200), radius = c(40, 60) ) canvas("white") |> add_circle( center = dplyr::select(circles, x, y), radius = dplyr::pull(circles, radius) ) |> draw_img() ## End(Not run)
Adds one or more difference rectangles (outer minus inner), optionally with rounded corners.
add_diff_rect( img, outer, inner, rsx_trans = matrix(c(1, 0, 0, 0, 0, 0), nrow(outer), 6, byrow = TRUE), outer_radii = matrix(0, nrow(outer), 2), inner_radii = matrix(0, nrow(inner), 2), ..., props = paint() )add_diff_rect( img, outer, inner, rsx_trans = matrix(c(1, 0, 0, 0, 0, 0), nrow(outer), 6, byrow = TRUE), outer_radii = matrix(0, nrow(outer), 2), inner_radii = matrix(0, nrow(inner), 2), ..., props = paint() )
img |
A raw vector of a serialized picture. |
outer, inner
|
A numeric matrix (or a data-frame-like object) with 4 numeric columns (left, top, right, bottom), where each row represents a rectangle. |
rsx_trans |
A numeric matrix (or a data-frame-like object) with 6 columns where each row represents an RSX transform. Each column of the matrix corresponds to:
|
outer_radii, inner_radii
|
A numeric matrix (or data-frame-like object) with 2 numeric columns (x and y), where each row represents the corner radii of a rounded rectangle. |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The number of shapes is determined by nrow(outer). The numbers of rows of
inner, rsx_trans, outer_radii, and inner_radii,
and the lengths of sigma and width (and the number of columns of color) must match this number.
The drawing attributes sigma, width, and color can be supplied via ....
If they are not supplied, they are taken from props and recycled to all shapes.
A raw vector containing a serialized picture.
As with add_rect(), Skia's rounded rectangle does not support rotation.
If the rotation angle in rsx_trans is not zero, this function will error.
To draw rotated rectangles or more general shapes, use add_path().
## Not run: # Shift rectangles by modifying coordinates directly ltrb <- dplyr::tibble( lo = c(60, 280), to = c(60, 60), ro = c(240, 460), bo = c(200, 200), li = c(100, 320), ti = c(100, 100), ri = c(200, 420), bi = c(160, 160) ) canvas("white") |> add_diff_rect( outer = dplyr::select(ltrb, lo, to, ro, bo), inner = dplyr::select(ltrb, li, ti, ri, bi), outer_radii = matrix(c(16, 16), nrow(ltrb), 2, byrow = TRUE), inner_radii = matrix(c(8, 8), nrow(ltrb), 2, byrow = TRUE) ) |> draw_img() # Use the same geometry and translate via `rsx_trans` ltrb <- dplyr::tibble( lo = rep_len(60, 2), to = rep_len(60, 2), ro = rep_len(240, 2), bo = rep_len(200, 2), li = rep_len(100, 2), ti = rep_len(100, 2), ri = rep_len(200, 2), bi = rep_len(160, 2) ) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, tx = c(0, 220), ty = c(0, 0), ax = 0, ay = 0 ) canvas("white") |> add_diff_rect( outer = dplyr::select(ltrb, lo, to, ro, bo), inner = dplyr::select(ltrb, li, ti, ri, bi), rsx_trans = rsx_trans ) |> draw_img() ## End(Not run)## Not run: # Shift rectangles by modifying coordinates directly ltrb <- dplyr::tibble( lo = c(60, 280), to = c(60, 60), ro = c(240, 460), bo = c(200, 200), li = c(100, 320), ti = c(100, 100), ri = c(200, 420), bi = c(160, 160) ) canvas("white") |> add_diff_rect( outer = dplyr::select(ltrb, lo, to, ro, bo), inner = dplyr::select(ltrb, li, ti, ri, bi), outer_radii = matrix(c(16, 16), nrow(ltrb), 2, byrow = TRUE), inner_radii = matrix(c(8, 8), nrow(ltrb), 2, byrow = TRUE) ) |> draw_img() # Use the same geometry and translate via `rsx_trans` ltrb <- dplyr::tibble( lo = rep_len(60, 2), to = rep_len(60, 2), ro = rep_len(240, 2), bo = rep_len(200, 2), li = rep_len(100, 2), ti = rep_len(100, 2), ri = rep_len(200, 2), bi = rep_len(160, 2) ) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, tx = c(0, 220), ty = c(0, 0), ax = 0, ay = 0 ) canvas("white") |> add_diff_rect( outer = dplyr::select(ltrb, lo, to, ro, bo), inner = dplyr::select(ltrb, li, ti, ri, bi), rsx_trans = rsx_trans ) |> draw_img() ## End(Not run)
Adds one or more line segments to an existing picture.
add_line(img, from, to, ..., props = paint())add_line(img, from, to, ..., props = paint())
img |
A raw vector of a serialized picture. |
from |
A numeric matrix (or a data-frame-like object) with 2 columns (x and y) where each row represents the start point of a line segment. |
to |
A numeric matrix (or a data-frame-like object) with 2 columns (x and y), where each row represents the end point of a line segment. |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The number of line segments is determined by nrow(from). The number of rows
of to, and the lengths of sigma and width (and the number of columns of
color) must match this number.
The drawing attributes sigma, width, and color can be supplied via ....
If they are not supplied, they are taken from props and recycled to all line
segments.
A raw vector containing a serialized picture.
## Not run: lines <- dplyr::tibble( x0 = c(50, 50), y0 = c(50, 250), x1 = c(350, 350), y1 = c(50, 250) ) canvas("white") |> add_line( from = dplyr::select(lines, x0, y0), to = dplyr::select(lines, x1, y1) ) |> draw_img() ## End(Not run)## Not run: lines <- dplyr::tibble( x0 = c(50, 50), y0 = c(50, 250), x1 = c(350, 350), y1 = c(50, 250) ) canvas("white") |> add_line( from = dplyr::select(lines, x0, y0), to = dplyr::select(lines, x1, y1) ) |> draw_img() ## End(Not run)
Adds one or more SVG paths to an existing picture.
Each path is given as a string in the SVG d attribute syntax, and can be
positioned by providing an RSX transform per path via rsx_trans.
add_path( img, path, rsx_trans = matrix(c(1, 0, 0, 0, 0, 0), length(path), 6, byrow = TRUE), ..., props = paint() )add_path( img, path, rsx_trans = matrix(c(1, 0, 0, 0, 0, 0), length(path), 6, byrow = TRUE), ..., props = paint() )
img |
A raw vector of a serialized picture. |
path |
A character vector of SVG path notations (the |
rsx_trans |
A numeric matrix (or a data-frame-like object) with 6 columns where each row represents an RSX transform. Each column of the matrix corresponds to:
|
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The number of paths is determined by length(path). The number of rows of
rsx_trans, and the lengths of sigma and width (and the number of columns
of color) must match this number.
The drawing attributes sigma, width, and color can be supplied via ....
If they are not supplied, they are taken from props and recycled to all paths.
The FillType for closed paths is taken from props[["fill_type"]]
and applied to all paths.
A raw vector containing a serialized picture.
## Not run: # Single path canvas("white") |> add_path("M45 10 H55 V45 H90 V55 H55 V90 H45 V55 H10 V45 H45 Z") |> draw_img() # Place the same path multiple times using `rsx_trans` path <- rep("M45 10 H55 V45 H90 V55 H55 V90 H45 V55 H10 V45 H45 Z", 3) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, tx = c(0, 120, 0), ty = c(0, 0, 120), ax = 1, ay = 1 ) canvas("white") |> add_path(path, rsx_trans = rsx_trans) |> draw_img() ## End(Not run)## Not run: # Single path canvas("white") |> add_path("M45 10 H55 V45 H90 V55 H55 V90 H45 V55 H10 V45 H45 Z") |> draw_img() # Place the same path multiple times using `rsx_trans` path <- rep("M45 10 H55 V45 H90 V55 H55 V90 H45 V55 H10 V45 H45 Z", 3) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, tx = c(0, 120, 0), ty = c(0, 0, 120), ax = 1, ay = 1 ) canvas("white") |> add_path(path, rsx_trans = rsx_trans) |> draw_img() ## End(Not run)
Draws a PNG image onto an existing picture.
add_png(img, png, left = 0, top = 0, ..., props = paint())add_png(img, png, left = 0, top = 0, ..., props = paint())
img |
A raw vector of a serialized picture. |
png |
A raw vector of a PNG image. |
left |
A numeric scalar giving the horizontal offset (in pixels) of the PNG's top-left corner from the canvas origin. Negative values are allowed. |
top |
A numeric scalar giving the vertical offset (in pixels) of the PNG's top-left corner from the canvas origin. Negative values are allowed. |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
A raw vector containing a serialized picture.
Draws grouped point sequences using Skia's batched point API.
add_point(img, point, group = rep_len(1, nrow(point)), ..., props = paint())add_point(img, point, group = rep_len(1, nrow(point)), ..., props = paint())
img |
A raw vector of a serialized picture. |
point |
A numeric matrix (or a data-frame-like object) with two numeric columns (x and y), where each row is a point. |
group |
A vector of grouping indices for |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
This function draws one shape per group, where each group is a consecutive run
in group (because grouping is implemented via rle()). If the same group id
appears in multiple non-consecutive runs, they are treated as separate groups.
The drawing behavior for each group is controlled by props[["point_mode"]]:
PointMode$Points: draws the group's points.
PointMode$Lines: draws line segments through the group's points.
PointMode$Polygon: draws a polygon from the group's points.
The attributes sigma, width, and color can be supplied via ....
They are applied per group, so their lengths must match the number of groups
(i.e., length(rle(group)$values)). If not supplied, they are taken from props
and recycled to all groups.
A raw vector containing a serialized picture.
## Not run: rad <- \(deg) deg * (pi / 180) cv_size <- dev_size() # Generate coordinates for a rose curve rose <- dplyr::tibble( i = seq_len(360), r = 120 * abs(sin(rad(4 * i))) ) |> dplyr::reframe( id = i, x = r * cos(rad(360 * i / 360)) + cv_size[1] / 2, y = r * sin(rad(360 * i / 360)) + cv_size[2] / 2, .by = i ) # Points (color per group; here, one point per group => color per point) canvas("white") |> add_point( dplyr::select(rose, x, y), group = dplyr::pull(rose, id), color = seq(0, 1, length.out = nrow(rose)) |> grDevices::hsv(1, 1, 1) |> col2rgba(), props = paint(width = 3) ) |> draw_img() # Lines (one polyline per group) rose2 <- dplyr::reframe( rose, x = c(cv_size[1] / 2, x), y = c(cv_size[2] / 2, y), .by = id ) canvas("white") |> add_point( dplyr::select(rose2, x, y), group = dplyr::pull(rose2, id), color = unique(dplyr::pull(rose2, id) / nrow(rose)) |> grDevices::hsv(1, 1, 1) |> col2rgba(), props = paint(point_mode = PointMode$Lines, width = 1) ) |> draw_img() # Polygon (a single polygon from all points) canvas("white") |> add_point( dplyr::select(rose, x, y), group = rep_len(1, nrow(rose)), props = paint(point_mode = PointMode$Polygon, width = 3, color = "hotpink") ) |> draw_img() ## End(Not run)## Not run: rad <- \(deg) deg * (pi / 180) cv_size <- dev_size() # Generate coordinates for a rose curve rose <- dplyr::tibble( i = seq_len(360), r = 120 * abs(sin(rad(4 * i))) ) |> dplyr::reframe( id = i, x = r * cos(rad(360 * i / 360)) + cv_size[1] / 2, y = r * sin(rad(360 * i / 360)) + cv_size[2] / 2, .by = i ) # Points (color per group; here, one point per group => color per point) canvas("white") |> add_point( dplyr::select(rose, x, y), group = dplyr::pull(rose, id), color = seq(0, 1, length.out = nrow(rose)) |> grDevices::hsv(1, 1, 1) |> col2rgba(), props = paint(width = 3) ) |> draw_img() # Lines (one polyline per group) rose2 <- dplyr::reframe( rose, x = c(cv_size[1] / 2, x), y = c(cv_size[2] / 2, y), .by = id ) canvas("white") |> add_point( dplyr::select(rose2, x, y), group = dplyr::pull(rose2, id), color = unique(dplyr::pull(rose2, id) / nrow(rose)) |> grDevices::hsv(1, 1, 1) |> col2rgba(), props = paint(point_mode = PointMode$Lines, width = 1) ) |> draw_img() # Polygon (a single polygon from all points) canvas("white") |> add_point( dplyr::select(rose, x, y), group = rep_len(1, nrow(rose)), props = paint(point_mode = PointMode$Polygon, width = 3, color = "hotpink") ) |> draw_img() ## End(Not run)
Adds one or more rounded rectangles to an existing picture.
add_rect( img, ltrb, rsx_trans = matrix(c(1, 0, 0, 0, 0, 0), nrow(ltrb), 6, byrow = TRUE), radii = matrix(0, nrow(ltrb), 2), ..., props = paint() )add_rect( img, ltrb, rsx_trans = matrix(c(1, 0, 0, 0, 0, 0), nrow(ltrb), 6, byrow = TRUE), radii = matrix(0, nrow(ltrb), 2), ..., props = paint() )
img |
A raw vector of a serialized picture. |
ltrb |
A numeric matrix (or a data-frame-like object) with 4 columns (left, top, right, bottom), where each row represents a rectangle. |
rsx_trans |
A numeric matrix (or a data-frame-like object) with 6 columns where each row represents an RSX transform. Each column of the matrix corresponds to:
|
radii |
A numeric matrix (or data-frame-like object) with 2 columns (x and y), where each row represents the corner radii of a rounded rectangle. |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The number of rectangles is determined by nrow(ltrb). The number of rows of
rsx_trans and radii, and the lengths of sigma and width
(and the number of columns of color) must match this number.
The drawing attributes sigma, width, and color can be supplied via ....
If they are not supplied, they are taken from props and recycled to all rectangles.
A raw vector containing a serialized picture.
Skia's rounded rectangle does not support rotation. If the rotation
angle in rsx_trans is not zero, this function will error. To draw rotated
rectangles or more general shapes, use add_path() instead.
## Not run: # Arrange rectangles by shifting coordinates in `ltrb` ltrb <- dplyr::tibble( l = c(60, 220, 60), t = c(60, 60, 180), r = c(180, 340, 180), b = c(140, 140, 260) ) canvas("white") |> add_rect( ltrb = ltrb, radii = matrix(c(12, 12), nrow(ltrb), 2, byrow = TRUE) ) |> draw_img() # Arrange rectangles by translating the same `ltrb` via `rsx_trans` ltrb <- dplyr::tibble( l = rep_len(60, 3), t = rep_len(60, 3), r = rep_len(180, 3), b = rep_len(140, 3) ) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, tx = c(0, 160, 0), ty = c(0, 0, 120), ax = 0, ay = 0 ) canvas("white") |> add_rect( ltrb = ltrb, rsx_trans = rsx_trans, radii = matrix(c(12, 12), nrow(ltrb), 2, byrow = TRUE) ) |> draw_img() ## End(Not run)## Not run: # Arrange rectangles by shifting coordinates in `ltrb` ltrb <- dplyr::tibble( l = c(60, 220, 60), t = c(60, 60, 180), r = c(180, 340, 180), b = c(140, 140, 260) ) canvas("white") |> add_rect( ltrb = ltrb, radii = matrix(c(12, 12), nrow(ltrb), 2, byrow = TRUE) ) |> draw_img() # Arrange rectangles by translating the same `ltrb` via `rsx_trans` ltrb <- dplyr::tibble( l = rep_len(60, 3), t = rep_len(60, 3), r = rep_len(180, 3), b = rep_len(140, 3) ) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, tx = c(0, 160, 0), ty = c(0, 0, 120), ax = 0, ay = 0 ) canvas("white") |> add_rect( ltrb = ltrb, rsx_trans = rsx_trans, radii = matrix(c(12, 12), nrow(ltrb), 2, byrow = TRUE) ) |> draw_img() ## End(Not run)
Draws text strings as text blobs.
add_text(img, text, rsx_trans, freeze = TRUE, ..., props = paint())add_text(img, text, rsx_trans, freeze = TRUE, ..., props = paint())
img |
A raw vector of a serialized picture. |
text |
A character vector of text strings to be drawn. |
rsx_trans |
A numeric matrix (or a data-frame-like object) with 6 columns where each row represents an RSX transform. Each column of the matrix corresponds to:
|
freeze |
A logical value indicating whether to freeze the picture after drawing text.
If |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The placement of glyphs is controlled by rsx_trans. For add_text(),
rsx_trans must have the same number of rows as the total number of characters
to be drawn, i.e. sum(nchar(text)), not length(text).
In contrast, sigma and color provided via ... (or from props) are matched
to length(text) (one value per text element). If you need per-character values
for sigma or color, split your string into single characters and pass them
as a character vector.
A raw vector containing a serialized picture.
Text blobs do not have a font fallback mechanism. Characters not supported by the specified font may not render correctly.
If freeze = FALSE, the returned picture can become large because font data may
be embedded. In most cases, it is recommended to keep freeze = TRUE.
## Not run: if ("Noto Sans Mono" %in% list_font_families()[["family"]]) { info <- text_info( "Hello, skiagd!", props = paint(family = "Noto Sans Mono", fontsize = 36) ) offset <- seq( 0, info$n_chars * (info$width / info$n_chars), length.out = info$n_chars ) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, x = (dev_size()[1] - info$width) / 2 + offset, y = dev_size()[2] / 2, ax = 0, ay = 0 ) canvas("white") |> add_text( "Hello, skiagd!", rsx_trans = rsx_trans, props = paint(family = "Noto Sans Mono", fontsize = 36) ) |> draw_img() } ## End(Not run)## Not run: if ("Noto Sans Mono" %in% list_font_families()[["family"]]) { info <- text_info( "Hello, skiagd!", props = paint(family = "Noto Sans Mono", fontsize = 36) ) offset <- seq( 0, info$n_chars * (info$width / info$n_chars), length.out = info$n_chars ) rsx_trans <- dplyr::tibble( sc = 1, rot = 0, x = (dev_size()[1] - info$width) / 2 + offset, y = dev_size()[2] / 2, ax = 0, ay = 0 ) canvas("white") |> add_text( "Hello, skiagd!", rsx_trans = rsx_trans, props = paint(family = "Noto Sans Mono", fontsize = 36) ) |> draw_img() } ## End(Not run)
Adds a vertex mesh to an existing picture.
add_vertices(img, vertices, ..., props = paint())add_vertices(img, vertices, ..., props = paint())
img |
A raw vector of a serialized picture. |
vertices |
A numeric matrix (or a data-frame-like object)
with 2 numeric columns (x and y),
where each row is a vertex position.
Vertices are consumed in groups of three (three rows per triangle).
If |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
The vertex mode is taken from props[["vertex_mode"]]. The blur sigma is taken
from props[["sigma"]].
Vertex colors are per-vertex attributes. If color is supplied via ..., it
must be an RGBA integer matrix with 4 rows and nrow(vertices) columns (one
color per vertex). If color is not supplied, props[["color"]] is recycled
to all vertices.
A raw vector containing a serialized picture.
When vertex colors are present, the paint's blend source is determined by:
props[["shader"]] if a shader is set, otherwise
an opaque version of props[["color"]].
This source is then combined with the interpolated vertex colors. As a result, to paint each vertex with a different visible color, you typically need to set a Shader (see the examples below).
## Not run: # A single triangle with per-vertex colors. # To make the vertex colors visible as-is, set a shader. canvas("white") |> add_vertices( dplyr::tibble( x = c(128, 0, 128), y = c(256, 256, 0) ), color = col2rgba(c("#61dafb", "#fb61da", "#dafb61")), props = paint( shader = Shader$from_picture( canvas("#ffffff00"), TileMode$Repeat, dev_size(), diag(3) ) ) ) |> draw_img() ## End(Not run)## Not run: # A single triangle with per-vertex colors. # To make the vertex colors visible as-is, set a shader. canvas("white") |> add_vertices( dplyr::tibble( x = c(128, 0, 128), y = c(256, 256, 0) ), color = col2rgba(c("#61dafb", "#fb61da", "#dafb61")), props = paint( shader = Shader$from_picture( canvas("#ffffff00"), TileMode$Repeat, dev_size(), diag(3) ) ) ) |> draw_img() ## End(Not run)
Converts img to an integer matrix with class nativeRaster.
as_nativeraster(img, ..., props = paint())as_nativeraster(img, ..., props = paint())
img |
A raw vector of a serialized picture. |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
In base R, a nativeRaster object conventionally stores
colors with non-premultiplied alpha
(RGB channels are independent of the alpha channel).
In contrast, skiagd renders internally with premultiplied alpha, and the resulting pixel values are returned as-is.
When such a raster is drawn onto an R graphics device
(e.g., via grid::grid.raster()),
the device composites the image with its background color.
If the alpha channel is not fully opaque (< 255),
this extra alpha blending can change the apparent colors compared
with what you would expect from the output of as_png().
A nativeRaster object.
## Not run: img <- canvas("navy") |> as_nativeraster() grid::grid.newpage() grid::grid.raster(img, interpolate = FALSE) ## End(Not run)## Not run: img <- canvas("navy") |> as_nativeraster() grid::grid.newpage() grid::grid.raster(img, interpolate = FALSE) ## End(Not run)
Renders a serialized picture to a PNG image.
as_png(img, ..., props = paint())as_png(img, ..., props = paint())
img |
A raw vector of a serialized picture. |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
A raw vector of a PNG image.
## Not run: png <- canvas("navy") |> as_png() # Write the PNG image to a file writeBin(png, "navy.png") ## End(Not run)## Not run: png <- canvas("navy") |> as_png() # Write the PNG image to a file writeBin(png, "navy.png") ## End(Not run)
BlendMode determines how source and destination colors are combined.
BlendModeBlendMode
The following blend modes are available in Skia:
Clear
Src
Dst
SrcOver
DstOver
SrcIn
DstIn
SrcOut
DstOut
SrcATop
DstATop
Xor
Plus
Modulate
Screen
Overlay
Darken
Lighten
ColorDodge
ColorBurn
HardLight
SoftLight
Difference
Exclusion
Multiply
Hue
Saturation
Color
Luminosity
Other paint-attributes:
BlurStyle,
Cap,
FillType,
FontStyle,
ImageFilter,
Join,
PathEffect,
PointMode,
Shader,
Style,
VertexMode
BlurStyle controls how a blur mask filter is applied to the shape.
BlurStyleBlurStyle
The following BlurStyle are available:
Normal: Normal blur.
Solid: Solid blur.
Outer: Outer blur.
Inner: Inner blur.
Other paint-attributes:
BlendMode,
Cap,
FillType,
FontStyle,
ImageFilter,
Join,
PathEffect,
PointMode,
Shader,
Style,
VertexMode
Creates a new serialized picture (a single frame) with a canvas filled with the specified color.
The coordinate system follows the usual image convention: the origin is at the top-left, the X axis increases to the right, and the Y axis increases downward. Units are pixels.
canvas(fill = "transparent", canvas_size = paint()[["canvas_size"]])canvas(fill = "transparent", canvas_size = paint()[["canvas_size"]])
fill |
An RGBA color specification for the background fill.
You can also provide a named color or a hexadecimal color code, which is
converted internally using |
canvas_size |
An integer vector of length 2 specifying canvas width and height, in pixels. |
A raw vector containing a serialized Skia picture.
## Not run: canvas("navy") |> draw_img() canvas(c(255, 0, 0, 255)) |> draw_img() # filled with red ## End(Not run)## Not run: canvas("navy") |> draw_img() canvas(c(255, 0, 0, 255)) |> draw_img() # filled with red ## End(Not run)
Cap determines the stroke cap (the geometry drawn at the beginning and end of strokes).
CapCap
The following caps are available:
Butt: Butt cap.
Round: Round cap.
Square: Square cap.
Cap in skia_safe::paint - Rust
Other paint-attributes:
BlendMode,
BlurStyle,
FillType,
FontStyle,
ImageFilter,
Join,
PathEffect,
PointMode,
Shader,
Style,
VertexMode
A wrapper of colorfast::col_to_rgb().
col2rgba(color)col2rgba(color)
color |
|
An integer matrix with 4 rows (RGBA) and N columns (the same length as color).
Creates a transformation matrix from sets of points src and dst.
If mapping is not possible, throws an error.
create_mapping(src, dst)create_mapping(src, dst)
src |
A numeric matrix (or a data-frame-like object) with 2 columns (x and y) and 4 rows, where each row is a point. |
dst |
A numeric matrix (or a data-frame-like object) with 2 columns (x and y) and 4 rows, where each row is a point. |
A numeric matrix of size 3x3.
## Not run: cv_size <- dev_size() # Create an affine matrix that fits a 768x576 picture to current device size create_mapping( src = matrix( c(0, 0, 768, 0, 768, 576, 0, 576), ), dst = matrix( c(0, 0, cv_size[1], 0, cv_size[1], cv_size[2], 0, cv_size[2]), ncol = 2, byrow = TRUE ) ) ## End(Not run)## Not run: cv_size <- dev_size() # Create an affine matrix that fits a 768x576 picture to current device size create_mapping( src = matrix( c(0, 0, 768, 0, 768, 576, 0, 576), ), dst = matrix( c(0, 0, cv_size[1], 0, cv_size[1], cv_size[2], 0, cv_size[2]), ncol = 2, byrow = TRUE ) ) ## End(Not run)
Just returns the size of the current graphics device as integers.
dev_size(units = "px")dev_size(units = "px")
units |
|
An integer vector of length 2 (width, height).
Converts img to a nativeRaster and draws it using
grid::grid.raster() with interpolate = TRUE.
Linear interpolation is therefore applied by default. This produces
smoother edges (e.g., for circles and diagonal shapes), at the cost of
slightly slower rendering. If you prefer a faster but more blocky result,
you can manually call grid::grid.raster() with interpolate = FALSE
on the output of as_nativeraster().
See the examples in as_nativeraster() for a comparison.
draw_img(img, ..., props = paint())draw_img(img, ..., props = paint())
img |
A raw vector of a serialized picture. |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
img is returned invisibly.
Embeds an image file as a base64-encoded HTML <img> tag.
For string input, the image file is read from disk, encoded as a data URI, and wrapped in an HTML object. For raw input, the image data is directly embedded in an HTML object, assuming it is a valid PNG image data.
embed_img(x, max_size = 4 * 1024^2, browsable = TRUE, ...) data_uri(x, max_size = 4 * 1024^2, ...)embed_img(x, max_size = 4 * 1024^2, browsable = TRUE, ...) data_uri(x, max_size = 4 * 1024^2, ...)
x |
File path or raw image data. |
max_size |
Maximum allowed file size in bytes.
If |
browsable |
Logical.
Whether to wrap the result in |
... |
Additional attributes passed to |
This function is designed as a lightweight helper for visualization and
documentation purposes. It does not perform any image decoding itself and
relies on the input being readable by base64enc::dataURI().
embed_img() returns an HTML object.
data_uri() returns a data URI string.
Enables autocomplete for painting attributes. To do this, this function simply assigns them to the current environment.
enable_autocomplete(env = parent.frame())enable_autocomplete(env = parent.frame())
env |
Environment to assign objects to. |
Called for its side-effect.
FillType determines how paths are drawn.
This is for add_path() only. Not used in other functions.
FillTypeFillType
The following FillType are available:
Winding
EvenOdd
InverseWinding
InverseEvenOdd
FillType in skia_safe::path - Rust
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FontStyle,
ImageFilter,
Join,
PathEffect,
PointMode,
Shader,
Style,
VertexMode
FontStyle determines the font style.
FontStyleFontStyle
The following styles are available:
Normal: Normal (plain).
Bold: Bold (bold).
Italic: Italic (italic).
BoldItalic: BoldItalic (bold.italic).
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FillType,
ImageFilter,
Join,
PathEffect,
PointMode,
Shader,
Style,
VertexMode
Rasterizes a picture into a PNG and adds it to a new canvas.
This is equivalent to as_png(img, props = props) and then drawing the
resulting PNG onto a fresh canvas using add_png() with the default blend mode
(BlendMode$SrcOver). It can be used to flatten a picture before continuing
to draw.
freeze(img, left = 0, top = 0, fill = "transparent", ..., props = paint())freeze(img, left = 0, top = 0, fill = "transparent", ..., props = paint())
img |
A raw vector of a serialized picture. |
left |
A numeric scalar giving the horizontal offset (in pixels) where the rasterized image is drawn on the new canvas. Negative values are allowed. |
top |
A numeric scalar giving the vertical offset (in pixels) where the rasterized image is drawn on the new canvas. Negative values are allowed. |
fill |
An RGBA color specification for the background fill of the new canvas.
You can provide a named color or a hexadecimal color code, which is converted
using |
... |
For some drawing functions, you can specify
If they are not provided as named arguments, they will be taken from |
props |
A list of painting attributes created by |
A raw vector containing a serialized picture.
ImageFilter is a struct that offers a reference to skia_safe::ImageFilter.
You can apply an image filter to canvas via paint().
Concatenating image filters with c() is equivalent to sequentially compose them
into a single filter using ImageFilter$compose().
For blending image filters, use ImageFilter$blend() explicitly.
img |
A raw vector of picture. |
crop_rect |
Numerics of length 4 for cropping the filtered image. |
dst, src
|
|
coef |
Numerics that represents the coefficients |
mode |
|
sigma |
Numerics of length 2 for blur sigma. |
tile_mode |
|
color_mat |
A 4x5 row-major numeric matrix that represents a color matrix. Every pixel's color value is multiplied by this matrix in the same way as the feColorMatrix SVG filter. A playground to build color matrices is available here. |
outer, inner
|
|
radius |
Numerics of length 2; radius of elipse for dilation and erosion. |
channels |
Numerics of length 2 in range of |
scale |
A numeric scalar; displacement scale factor to be used. |
displacement |
An |
offset |
Numerics of length 2 for X and Y offsets. |
source |
A RuntimeEffect object. |
uniforms |
A named list of numerics to be assigned to uniforms in |
The following filters are available:
no_filter(): does not apply any image filter. This is the default image filter for paint().
from_picture(img, crop_rect): creates an image filter from a picture.
arithmetic(dst, src, coef, crop_rect): applies an arithmetic operation to two image filters.
blend(dst, src, mode, crop_rect): blends two image filters with a given blend mode.
blur(sigma, tile_mode, crop_rect): creates a blur image filter.
color_matrix(color_mat): creates an image filter from a color matrix.
compose(outer, inner): composes two image filters.
crop(crop_rect, tile_mode): crops the source image.
dilate(radius, crop_rect): dilates the source image.
displacement_map(channels, scale, displacement, crop_rect): creates a displacement map.
drop_shadow(offset, sigma, color, crop_rect): creates a drop shadow image filter.
erode(raidus, crop_rect): erodes the source image.
offset(offset, crop_rect): creates an offset image filter.
runtime_shader(source, uniforms): creates an image filter from a RuntimeEffect.
An ImageFilter object.
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FillType,
FontStyle,
Join,
PathEffect,
PointMode,
Shader,
Style,
VertexMode
Join determines the stroke join (the geometry drawn at the corners of strokes) for shapes.
JoinJoin
The following joins are available:
Miter: Miter join.
Round: Round join.
Bevel: Bevel join.
Join in skia_safe::paint - Rust
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FillType,
FontStyle,
ImageFilter,
PathEffect,
PointMode,
Shader,
Style,
VertexMode
Returns font families available on the system.
Since skiagd can only access fonts installed on the system,
font families in the font registry or local fonts
registered by the systemfonts package
cannot be specified as the family in paint().
list_font_families()list_font_families()
A tibble containing family.
The paint() function allows users to specify
various painting attributes for drawing shapes on the canvas,
such as color and stroke width.
paint(...)paint(...)
... |
< |
The following painting attributes can be specified:
canvas_size: Integers of length 2 (width, height).
color: An RGBA color specification (integers of length 4). This can be also specified using named colors or hexadecimal color codes, which are converted using col2rgba().
style: Paint style. See Style.
join: Stroke join. See Join.
cap: Stroke cap. See Cap.
width: A numeric scalar (stroke width).
miter: A numeric scalar (stroke miter).
fontsize: A numeric scalar (font size).
family: Font family name. You can list available font families using list_font_families().
fontface: Font face. See FontStyle.
sigma: A numeric scalar. Default value for blur sigma.
blur_style: BlurStyle for a blur mask filter applied to the shape.
blend_mode: See BlendMode.
path_effect: See PathEffect.
shader: See Shader.
image_filter: See ImageFilter.
point_mode: PointMode for add_point().
vertex_mode: VertexMode for add_vertices().
fill_type: FillType for add_path().
A list containing the specified painting attributes, merged with default values.
PathEffect is a struct that offers a reference to skia_safe::PathEffect.
You can apply a path effect to shapes via paint().
Concatenating path effects with c() is equivalent to sum them sequentially
into a single effect using PathEffect$sum().
first |
A |
second |
A |
start |
A numeric scalar in the range |
end |
A numeric scalar in the range |
length |
A numeric scalar; length of the subsegments. |
deviation |
A numeric scalar; limit of the movement of the endpoints. |
seed |
An integer scalar; random seed. |
intervals |
A numeric vector; even number of entries with even indices specifying the length of the "on" intervals, and the odd index specifying the length of "off". |
phase |
A numeric scalar; offset into the intervals array (for |
radius |
A numeric scalar; radius of the rounded corners. |
path |
A string scalar of SVG notation to replicate. |
advance |
A numeric scalar; space between instances of path. |
style |
A string scalar; how to transform path at each point.
Can be |
transform |
Numerics of length 9; see transform-matrix. |
width |
A numeric scalar; width of the path to be stamped. |
The following effects are available:
no_effect(): does not apply any path effect. This is the default effect for paint().
sum(first, second): applies two effects in sequence.
trim(start, end): trims the start and end of the path. Note that you can't trim nothing at all, i.e., setting start = 0 and end = 1 does nothing.
discrete(lentgh, deviation, seed): applies discrete path effect.
dash(intervals, phase): applies dash path effect.
corner(radius): applies corner path effect.
path_1d(path, advance, phase, style): applies 1D path effect.
path_2d(path, transform): applies 2D path effect.
line_2d(width, transform): applies 2D line path effect.
A PathEffect object.
Path Effects | React Native Skia
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FillType,
FontStyle,
ImageFilter,
Join,
PointMode,
Shader,
Style,
VertexMode
In Skia, a picture is a prerecorded list of drawing operations on a canvas. The drawing functions of skiagd take it as their first argument, add new shapes onto it, and return a serialized picture as a raw vector again.
A serialized picture is a binary format containing a single frame,
which can be saved to a .skp file using writeBin(),
and reused by any drawing functions
as long as it is compatible with the version of Skia
used to create it.
You can review contents of .skp files
with the Skia debugger
if they are compatible with the version.
PointMode determines how points are drawn.
This is for add_point() only. Not used in other functions.
PointModePointMode
The following PointMode are available:
Points: Draws each point as a point. The shape of point drawn depends on props.
Lines: Each pair of point draws a line segment. One line is drawn for every two points; each point is used once. If count is odd, the final point is ignored.
Polygon: Each adjacent pair of point draws a line segment. count minus one lines are drawn; the first and last point are used once.
PointMode in skia_safe::canvas - Rust
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FillType,
FontStyle,
ImageFilter,
Join,
PathEffect,
Shader,
Style,
VertexMode
RuntimeEffect is a struct that wraps skia_safe::RuntimeEffect.
Skia provides a shading language called SkSL. The syntax is similar to GLSL, but differs in minor details. A quick overview of their differences can be found here.
You can compile an SkSL source into a RuntimeEffect
using RuntimeEffect$make(),
and apply it as an ImageFilter or a Shader.
sksl |
A string scalar of an SkSL source.
For ImageFilter, the fragment shader must receive
the currently filtered image as |
RuntimeEffect as an R environment exposes the following method:
make(sksl): Takes an SkSL source and compiles it into a RuntimeEffect.
A RuntimeEffect object has the following method:
source(): Returns the original SkSL source as a string scalar.
For make(), a RuntimeEffect object is returned
if the SkSL source is successfully compiled.
Otherwise, an error is thrown with the compilation error message.
## Not run: effect <- RuntimeEffect$make(R"{ uniform shader image; uniform vec2 resolution; vec4 main(vec2 fragCoord) { vec2 uv = fragCoord / resolution; return vec4(uv.x, uv.y, .6, 1.0); } }") cv_size <- dev_size() imgf <- ImageFilter$runtime_shader( effect, list(resolution = as.double(cv_size)) ) canvas() |> add_rect( matrix(c(0, 0, cv_size), ncol = 4), props = paint(image_filter = imgf) ) |> draw_img() ## End(Not run)## Not run: effect <- RuntimeEffect$make(R"{ uniform shader image; uniform vec2 resolution; vec4 main(vec2 fragCoord) { vec2 uv = fragCoord / resolution; return vec4(uv.x, uv.y, .6, 1.0); } }") cv_size <- dev_size() imgf <- ImageFilter$runtime_shader( effect, list(resolution = as.double(cv_size)) ) canvas() |> add_rect( matrix(c(0, 0, cv_size), ncol = 4), props = paint(image_filter = imgf) ) |> draw_img() ## End(Not run)
Shader is a struct that offers a reference to skia_safe::Shader.
You can apply a shader to shapes via paint().
Concatenating shaders with c() is equivalent to blend them all
into a single shader using Shader$blend() with the default BlendMode.
You can pass mode explicitly for c() to change the blend mode.
img |
A raw vector of picture. |
mode |
|
tile_size |
Numerics of length 2; tile size (width, height). |
transform |
Numerics of length 9; see transform-matrix. |
png |
A raw vector of PNG image. |
source |
A RuntimeEffect object. |
uniforms |
A named list of numerics to be assigned to uniforms in |
color |
An integer matrix in range |
dst |
A |
src |
A |
freq |
Numerics of length 2; frequencies. |
octaves |
A numeric scalar; number of octaves. |
seed |
Integer scalar; random seed. |
start |
Numerics of length 2; starting point (x, y). |
end |
Numerics of length 2; ending point (x, y). |
flags |
A logical scalar; typically, you can leave this as |
radii |
Numerics of length 2; radii of start and end circles. |
center |
Numerics of length 2; center of the gradient. |
start_angle |
A numeric scalar in range |
end_angle |
A numeric scalar in range |
The following shaders are available:
no_shader(): does not apply any shader. This is the default shader for paint().
from_picture(img, mode, tile_size, transform): takes a picture and returns an image shader.
from_png(png, mode, transform): takes a PNG image and returns an image shader.
from_runtime_effect(source, uniforms): takes a RuntimeEffect and returns a shader.
color(color): takes a color and returns a color shader.
blend(mode, dst, src): returns a shader where the given shaders are combined with BlendMode.
fractal_noise(freq, octaves, seed, tile_size): fractal perlin noise shader.
turbulence(freq, octaves, seed, tile_size): turbulence noise shader.
linear_gradient(start, end, color, mode, flags, transform): linear gradient shader.
radial_gradient(center, radius, color, mode, flags, transform): radial gradient shader.
conical_gradient(start, end, radii, color, mode, flags, transform): conical gradient shader.
sweep_gradient(center, start_angle, end_angle, color, mode, flags, transform): sweep gradient shader.
A Shader object.
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FillType,
FontStyle,
ImageFilter,
Join,
PathEffect,
PointMode,
Style,
VertexMode
Style determines the stroke style of shapes.
StyleStyle
The following styles are available:
StrokeAndFill: Stroke and fill.
Stroke: Stroke only.
Fill: Fill only.
Style in skia_safe::paint - Rust
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FillType,
FontStyle,
ImageFilter,
Join,
PathEffect,
PointMode,
Shader,
VertexMode
Computes axis-aligned bounding boxes for one or more SVG paths.
svg_bounds(path)svg_bounds(path)
path |
A character vector of SVG path notations (the |
A tibble containing columns id, left, top, right and bottom for each path.
id is a 1-based index corresponding to the input order of path.
Other path-utils:
svg_interpolate(),
svg_transform()
svg_bounds("M45 10 H55 V45 H90 V55 H55 V90 H45 V55 H10 V45 H45 Z")svg_bounds("M45 10 H55 V45 H90 V55 H55 V90 H45 V55 H10 V45 H45 Z")
Interpolates between two SVG paths that are compatible for morphing.
svg_interpolate(t, first, second)svg_interpolate(t, first, second)
t |
A numeric vector of interpolation weights. Values between 0 and 1 produce intermediate paths; values outside this range are wrapped. |
first |
A string scalar of an SVG path notation (the |
second |
A string scalar of an SVG path notation (the |
This function returns intermediate paths between first and second using
weights t. Paths must be interpolatable (e.g., compatible command sequences);
otherwise an error is thrown.
A character vector of SVG path notations interpolated.
Other path-utils:
svg_bounds(),
svg_transform()
trans <- matrix(c(1, 0, -50, 0, 1, -50, 0, 0, 1), 3, 3) first <- svg_transform(R"( M10 18 H40 M18 10 V40 M90 18 H60 M82 10 V40 M10 82 H40 M18 90 V60 M90 82 H60 M82 90 V60 )", trans) second <- svg_transform(R"( M12 22 H44 M22 12 V44 M88 22 H56 M78 12 V44 M12 78 H44 M22 88 V56 M88 78 H56 M78 88 V56 )", trans) svg_interpolate(seq(-2, 2, length.out = 10), first, second)trans <- matrix(c(1, 0, -50, 0, 1, -50, 0, 0, 1), 3, 3) first <- svg_transform(R"( M10 18 H40 M18 10 V40 M90 18 H60 M82 10 V40 M10 82 H40 M18 90 V60 M90 82 H60 M82 90 V60 )", trans) second <- svg_transform(R"( M12 22 H44 M22 12 V44 M88 22 H56 M78 12 V44 M12 78 H44 M22 88 V56 M88 78 H56 M78 88 V56 )", trans) svg_interpolate(seq(-2, 2, length.out = 10), first, second)
Applies an affine transformation to SVG path notations.
This is useful for translating, scaling, or skewing paths written in the
SVG d attribute syntax before placing them with add_path().
svg_transform(path, transform)svg_transform(path, transform)
path |
A character vector of SVG path notations (the |
transform |
Numerics of length 9; see transform-matrix. |
A character vector of transformed SVG path notations.
Other path-utils:
svg_bounds(),
svg_interpolate()
trans <- matrix(c(1, 0, -50, 0, 1, -50, 0, 0, 1), 3, 3) svg_transform("M45 10 H55 V45 H90 V55 H55 V90 H45 V55 H10 V45 H45 Z", trans)trans <- matrix(c(1, 0, -50, 0, 1, -50, 0, 0, 1), 3, 3) svg_transform("M45 10 H55 V45 H90 V55 H55 V90 H45 V55 H10 V45 H45 Z", trans)
Returns metrics for text strings when they are shaped and drawn as a text blob
with the given props.
text_info(text, props = paint())text_info(text, props = paint())
text |
A character vector of text strings. |
props |
A list of painting attributes created by |
A tibble containing one row per element of text, with columns:
id (1-based index), n_chars, width (advance width),
and left, top, right, bottom for the bounding box.
TileMode determines how the source is tiled for shaders.
This is not a painting attribute. To specify TileMode, directly pass these pointers to shader functions.
TileModeTileMode
The following TileMode are available:
Clamp
Repeat
Mirror
Decal
Several skiagd APIs accept transform as numerics of length 9.
This value is interpreted as a 3x3 affine transformation matrix.
Typical uses include transforming:
shader coordinate systems such as gradients and image shaders,
path effect patterns such as PathEffect$path_2d() and PathEffect$line_2d(),
SVG path data via svg_transform().
The matrix is read in the following layout:
For ordinary affine transforms, the last column is typically c(0, 0, 1),
while the other entries control scaling, skewing, and translation.
skiagd passes this matrix through to the corresponding Skia API, so the exact
effect depends on where transform is used.
Matrix in skia_safe::matrix - Rust
VertexMode determines how vertices are drawn.
This is for add_vertices() only. Not used in other functions.
VertexModeVertexMode
The following VertexMode are available:
Triangles
TriangleStrip
TriangleFan
VertexMode in skia_safe::vertices - Rust
Other paint-attributes:
BlendMode,
BlurStyle,
Cap,
FillType,
FontStyle,
ImageFilter,
Join,
PathEffect,
PointMode,
Shader,
Style