README.md

cairocore

R build
status

cairocore provides a canvas and tools for fast 2d drawing operations.

It provides a low-level wrapper around the cariographics 2D graphics library (written in C) which provides drawing operations and related functions, with consistent output on multiple platforms and output media (e.g. SVG, PDF, PNG etc).

This package is not a graphics device - you can’t plot to it. Instead it provides a canvas for directly drawing shapes and text.

View the online documentation here

#### Key Features - Very fast line and shape drawing - Convert canvas surface to/from R arrays - this means you can draw on an array from within R - Alpha-blending and anti-aliasing - Direct control of what pixels get put on a canvas i.e. not having to pass through an intermediate plotting step (e.g. ggplot) or graphics device (e.g. png()) ## Package Philosophy `cairocore` is a one-to-one mapping from R functions to C functions in the [cariographics](https://www.cairographics.org/) C library. This package will remain very “C-like”, but other packages are welcome to wrap this `cairocore` to enable more idiomatic R programming styles. One such wrapper is [cairobasic](https://github.com/coolbutuseless/cairobasic) which offers a subset of the possible drawing operations with a friendlier interface. ## Installation Pre-requisite: Cairographics C library + headers - `CairoGraphics` library installed - See [CairoGraphics downloads page](https://www.cairographics.org/download/) for more information on how this might work on your platform. Install CairoGraphics on Mac OSX - Using [homebrew](https://brew.sh/) - `brew install cairo` (this works on my Mac) - Using [MacPorts]() - `sudo port install cairo` - Using [fink](sudo%20apt-get%20install%20cairo) Install CairoGraphics on Linux - Debian/Ubuntu - `sudo apt-get install libcairo2-dev` - Fedora - `sudo yum install cairo-devel` - openSUSE - `zypper install cairo-devel` Install CairoGraphics on Windows I haven’t been able to test any of the windows techniques - if you are a windows user, please let me know what worked for you\! - [CairoGraphics downloads page](https://www.cairographics.org/download/) for more information - Try the following: - [Rtools/pacman](https://github.com/r-windows/docs/blob/master/rtools40.md#system-libraries-and-pacman) - [rwinlib](https://github.com/rwinlib/cairo) - [winget](https://github.com/microsoft/winget-cli) ## Installation You can install from [GitHub](https://github.com/coolbutuseless/cairocore) with: wzxhzdk:0 ## Documentation + Tutorials `cairocore` behaves almost identically to the `CairoGraphics` C library and in many cases examples from the internet (which are all in C code) may be lightly modified and used as R code. The documentation for `cairocore` is mostly a direct translation of the [`CairoGraphics` documentation](https://www.cairographics.org/manual/) and has been extracted from the C source files. **View the online documentation [here](https://coolbutuseless.github.io/package/cairocore/index.html)** A great tutorial on using CairoGraphics in C is from [zetcode](http://zetcode.com/gfx/cairo/). ## Vignettes I’ve tried to highlight a few interesting features of CairoGrapihcs in the vignettes, but the library is huge and I can’t cover all of it here. Hopefully there are enough code examples to get you started\! - [Creating patterns](https://coolbutuseless.github.io/package/cairocore/articles/demo-creating-and-using-patterns.html) - [Drawing on R arrays](https://coolbutuseless.github.io/package/cairocore/articles/demo-drawing-on-arrays.html) create a drawing canvas from an R array and draw on it - [Drawing simple shapes](https://coolbutuseless.github.io/package/cairocore/articles/demo-drawing-simple-shapes.html) - [Image output formats](https://coolbutuseless.github.io/package/cairocore/articles/demo-image-output-formats.html) - [Using Transforms](https://coolbutuseless.github.io/package/cairocore/articles/demo-transforms.html) by default CairoGraphics considers the origin to be the top left of the page. This vignette sets the transformation matrix on a surface such that the bottom left corner is considered the origin. - [Vectorised functions](https://coolbutuseless.github.io/package/cairocore/articles/demo-vectorised-functions.html) there are some custom functions for drawing multitudes of the same type of element. There is a speed advantage in looping over data within C rather than within R. - [Technical - enums in C](https://coolbutuseless.github.io/package/cairocore/articles/technical-C-enums-in-R.html) - [Technical - pointers in C](https://coolbutuseless.github.io/package/cairocore/articles/technical-C-pointers-in-R.html) - [Technical - structs in C](https://coolbutuseless.github.io/package/cairocore/articles/technical-C-structs-in-R.html) ## Example - Using `cairocore` as a drawing canvas Click to show/hide code wzxhzdk:1 wzxhzdk:2 ## Example - drawing 10,000 alpha blended lines Click to show/hide code wzxhzdk:3 ## Example - taking an array in R, drawing on it, returning it to R Click to show/hide code wzxhzdk:4 wzxhzdk:5 ## Related Software - The R [Cairo](https://cran.r-project.org/package=Cairo) package uses the CairoGraphics library internally to provide graphics output devices for plotting. - The R [cairoDevice](https://cran.r-project.org/package=cairoDevice) package appears to be almost identical to the `{Cairo}` package in that it provides graphics output devices for plotting. ## Acknowledgements - R Core for developing and maintaining R - CRAN maintainers, for patiently shepherding packages onto CRAN and maintaining the repository


coolbutuseless/cairocore documentation built on Aug. 31, 2020, 12:43 a.m.