A collection of R scripts that generate and visualise classical fractals and chaotic sets across several algorithmic families: escape-time iteration of the Mandelbrot set, line-rewriting (L-system / turtle-geometry) construction of the Koch snowflake and recursive trees, matrix iterated-function-system (IFS) construction of the Sierpinski triangle and carpet, iterative H-tree subdivision, the logistic-map bifurcation diagram, and a radial mathematical surface. Rendering uses both the ggplot2 grammar of graphics and R base graphics, with perceptually-uniform (viridis, turbo) and ColorBrewer palettes.
The scripts are an R companion to the fractal-geometry methodology applied in:
Lemenkova, P. Fractal Surfaces of Synthetical DEM Generated by GRASS GIS Module r.surf.fractal from ETOPO1 Raster Grid. Journal of Geodesy and Geoinformation 2020, 7(2), 86-102.
- DOI: https://doi.org/10.9733/JGG.2020R0006.E
- figshare: https://doi.org/10.6084/m9.figshare.13047815
- HAL: https://hal.science/hal-02956736
- Zenodo: https://zenodo.org/record/4064662
- SSRN: http://ssrn.com/abstract=3704194
- ISSN: 2147-1339
In that study, synthetic fractal digital elevation models (DEMs) were generated in GRASS GIS with the r.surf.fractal module, which synthesises a surface of a prescribed fractal dimension, from an ETOPO1 raster grid. The scripts in this repository explore the underlying fractal-geometry concepts that motivate that surface synthesis: self-similarity, iterative and recursive generation, escape-time and IFS algorithms, and fractal dimension.
- mandelbrot_set_escape_time_ggplot2.R: the Mandelbrot set computed directly by iterating z <- z^2 + c over a lattice of the complex plane (expand.grid + mapply with complex arithmetic). Each point is coloured by the iteration count at which the orbit escapes the disc of radius 2, or by the maximum iteration if it stays bounded; rendered with ggplot2 geom_point and a rainbow gradient.
- mandelbrot_set_fractal_package.R: the same set rendered via the fractal package's mandelbrot() and base image().
A shared framework builds fractal curves from line segments: newLine() rotates and scales a segment by trigonometry (atan / cos / sin), and iterate() applies a production rule to every current segment.
- koch_snowflake_line_rewriting.R: the Koch curve and snowflake, where each segment is replaced by four segments (-60, +120, -60 degree turns, one-third scaling), seeded from a triangle; also includes recursive trees.
- koch_snowflake_standalone.R, koch_snowflake_variant.R: compact standalone Koch-snowflake variants.
- recursive_tree_fractals.R: recursive branching trees, where each segment spawns two child branches at plus/minus a branch angle with a reduction factor and optional Gaussian angular randomness (rnorm), drawn with base-graphics segments over successive iterations.
- sierpinski_triangle_carpet_ifs.R: the Sierpinski triangle and carpet built by recursive self-embedding of the indicator matrix via cbind / rbind block composition (a Kronecker-product-like construction), rendered as a binary raster with image().
- fractal_h_tree_ggplot2.R, fractal_h_tree_variants_ggplot2.R: the H-fractal (H-tree), generated by iterative subdivision stored in a data.frame with binary-tree row indexing (rows 2^(m-1) to 2^m-1), modulo direction flipping, and a geometric shortening factor a = 1/sqrt(2) per level; drawn with ggplot2 geom_segment and a colour gradient keyed to iteration depth.
- logistic_map_bifurcation_diagram.R: the logistic-map bifurcation diagram (the period-doubling route to chaos) via the fractal package, rendered with image().
- radial_interference_surface.R: a radial surface cos(r^2) * exp(-r / 2pi) evaluated over an outer-product grid and drawn with filled.contour and turbo / viridis palettes.
- Escape-time algorithm on the complex plane (Mandelbrot iteration and escape radius test).
- L-system / turtle-geometry line rewriting with trigonometric segment rotation and scaling.
- Iterated-function-system self-embedding via matrix block composition.
- Recursive branching with stochastic perturbation (Gaussian angle noise).
- Binary-tree iterative subdivision (H-tree) with geometric length decay.
- Logistic-map dynamics and the bifurcation (period-doubling) diagram.
- Grammar-of-graphics (ggplot2) and base-graphics rendering; perceptually uniform and qualitative colour mapping.
- R (>= 3.5)
- Packages: ggplot2, fractal, RColorBrewer, viridisLite
Install with:
install.packages(c("ggplot2", "fractal", "RColorBrewer", "viridisLite"))
Run any script directly, e.g.:
Rscript mandelbrot_set_escape_time_ggplot2.R
Base-graphics scripts open a plotting device; ggplot2 scripts print a plot object.
Polina Lemenkova ORCID: https://orcid.org/0000-0002-5759-1089
If these scripts support your work, please cite the related article:
Lemenkova, P. Fractal Surfaces of Synthetical DEM Generated by GRASS GIS Module r.surf.fractal from ETOPO1 Raster Grid. Journal of Geodesy and Geoinformation 2020, 7(2), 86-102. https://doi.org/10.9733/JGG.2020R0006.E
No license file is currently included. For reuse terms, please contact the author via the ORCID record above.