skiagd is a toy R wrapper for rust-skia (the rust crate skia_safe, a binding for Skia).
Despite its name, this package is intended as a graphics library, not a graphics device for R 😓
- This is not a graphics device. skiagd does not allow R’s session to hold a reference to a Canvas object on Rust side.
- Drawing functions return a
picture
as a
raw
object every time it’s called.add_*
puts those data onto canvas, actually adds some paintings to there, and then returns araw
object again.
I’m planning to re-implement features like React Native Skia.
- Shapes
- Path
- SVG notation (path)
- Polygons
- Rect
- RoundedRect (round_rect)
- DiffRect (drrect)
- Line
- Points (points; not point)
- Ellipses
- Circle
- Oval (oval)
- Arc (arc)
- Atlas
- Vertices
- Patch
- Path
- Images
- PNG
- Text
- Paragraph
- Text
- Glyphs
- Text Path
- Text Blob
- Painting Attributes (Paint)
- Fitting Images (needs to re-implement this)
- Group / Backdrop Filters
- Mask
It’s still in early alpha stage. The API is subject to (maybe drastic) change.
pkgload::load_all(export_all = FALSE)
#> ℹ Loading skiagd
img_data <-
unigd::ugd_render_inline({
set.seed(1234)
size <- dev_size("px")
n_circles <- 250
canvas("snow") |>
add_line(
matrix(c(runif(300, 0, size[1]), runif(300, 0, size[2])), ncol = 2),
matrix(c(runif(300, 0, size[1]), runif(300, 0, size[2])), ncol = 2),
props = paint(color = "#fff28166", width = 6)
) |>
add_circle(
matrix(c(runif(n_circles, 0, size[1]), runif(n_circles, 0, size[2])), ncol = 2),
runif(n_circles, 6, 50),
props = paint(color = "#87ceeb66", blend_mode = BlendMode$ColorBurn)
) |>
add_circle(
matrix(c(runif(n_circles, 0, size[1]), runif(n_circles, 0, size[2])), ncol = 2),
runif(n_circles, 20, 60),
props = paint(color = "#ff1493aa", blend_mode = BlendMode$Overlay)
) |>
add_path(
"M 128 0 L 168 80 L 256 93 L 192 155 L 207 244 L 128 202 L 49 244 L 64 155 L 0 93 L 88 80 L 128 0 Z",
transform = c(1, 0, (size[1] / 2 - 128), 0, 1, (size[2] / 2 - 128), 0, 0, 1),
props = paint(color = "#fff281ee")
) |>
draw_img()
}, as = "png", width = 1280, height = 720)
img_data |>
magick::image_read() |>
as.raster() |>
plot()