The goal of attractor
is to generate and plot strange attractors.
Using this package is fast, because:
Rcpp
for speed.You can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("andrie/attractor")
Create a strange attractor with 10 million points, then discretize to a
matrix with dimensions 400 x 400
:
library(magrittr)
library(attractor)
a <- seed_sprott_7e(21031)
#> setting seed
dat <-
a %>%
attractor_sprott_7e(1e6, dims = c(400, 400))
str(dat)
#> num [1:400, 1:400] 0 0 0 0 0 0 0 0 0 0 ...
par(mar = rep(0, 4), mai = rep(0, 4))
dat %>%
recolour() %>%
plot()
Use recolour()
to change the colours. You can use any of the colours
defined by the scales::col_numeric()
function. From the help of
?scales::col_numeric()
:
The palette argument can be any of the following:
A character vector of RGB or named colours. Examples: palette()
,
c("#000000", "#0000FF", "#FFFFFF")
, topo.colors(10)
The name of an RColorBrewer
palette, e.g. "BuPu"
or "Greens"
.
A function that receives a single value between 0 and 1 and returns
a colour. Examples: colorRamp(c("#000000", "#FFFFFF"),
interpolate="spline")
.
Use the Oranges
palette:
dat %>%
recolour("Oranges") %>%
plot()
To change the background colour, specify a zero_colour
:
dat %>%
recolour("Oranges", zero_colour = "#FFFAF6") %>%
plot()
You can also invert the palette
dat %>%
recolour("Oranges", zero_colour = "grey20", invert = TRUE) %>%
plot()
Try the Spectral
palette:
dat %>%
recolour("Spectral", zero_colour = "#9E0142") %>%
plot()
With inversion:
dat %>%
recolour("Spectral", invert = TRUE, zero_colour = "#5E4FA2") %>%
plot()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.