Package 'mandelbrot'

Title: Generates Views on the Mandelbrot Set
Description: Estimates membership for the Mandelbrot set.
Authors: Ben Moore [aut, cre], Mario dos Reis [aut]
Maintainer: Ben Moore <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0
Built: 2025-03-06 04:03:12 UTC
Source: https://github.com/blmoore/mandelbrot

Help Index


Convert Mandelbrot object to data.frame for plotting

Description

Converts objects produced by mandelbrot to tidy data.frames for use with ggplot and other tidyverse packages.

Usage

## S3 method for class 'mandelbrot'
as.data.frame(x, ...)

Arguments

x

a Mandelbrot set object produced by mandelbrot

...

ignored

Value

a 3-column data.frame

Examples

mb <- mandelbrot()
df <- as.data.frame(mb)
head(df)

Calculate the Mandelbrot set

Description

Generates a view on the Mandelbrot set using an underlying C function.

Usage

mandelbrot(xlim = c(-2, 2), ylim = c(-2, 2), resolution = 600,
  iterations = 50)

mandelbrot0(xlim = c(-2, 2), ylim = c(-2, 2), resolution = 600,
  iterations = 50)

Arguments

xlim

limits of x axis (real part)

ylim

limits of y axis (imaginary part)

resolution

either an integer nn for n2n^2 pixels or a list with x and y components specifying the resolution in each direction (e.g. list(x = 500, y = 500))

iterations

maximum number of iterations to evaluate each case

Details

mandelbrot0 is an experimental interface for generating tidy data.frames faster than as.data.frame(mandelbrot()).

Value

a mandelbrot structure with components: x a vector of the real parts of the x-axis; y the imaginary parts of each number (the y-axis); z a matrix of the number of iterations that z<2|z|<2

Mandelbrot set

In brief, the Mandelbrot set contains the complex numbers where the 0 orbit of the following function remains bounded (<2<2):

fz+1=z2+cf_{z+1} = z^2 + c

For information and discussion on the Mandelbrot and related sets, one great resource is plus.maths.org. There's also a popular YouTube video by Numberphile.

Credits

Wraps original C code by Mario dos Reis, September 2003.

References

https://stat.ethz.ch/pipermail/r-help/2003-October/039773.html http://people.cryst.bbk.ac.uk/~fdosr01/Rfractals/index.html


Generate palette suitable for coloring a set

Description

Takes a simple palette and expands / oscillates it for use with Mandelbrot sets.

Usage

mandelbrot_palette(palette, fold = TRUE, reps = 1L, in_set = "black")

Arguments

palette

vector of color hex strings (e.g. '#FFFFFF')

fold

wrap or fold the palette back on itself

reps

number of times to replicate the color vector

in_set

color for areas in the Mandelbrot set

Value

an extended color vector

Examples

view <- mandelbrot(xlim = c(-0.8438146, -0.8226294),
  ylim = c(0.1963144, 0.2174996), iter = 500)

# can be used to simply interpolate a color gradient
spectral <- RColorBrewer::brewer.pal(11, "Spectral")
cols <- mandelbrot_palette(spectral, fold = FALSE)
plot(view, col = cols, transform = "inv")

# simple palettes might need folds / reps to look good
blues <- RColorBrewer::brewer.pal(9, "Blues")
cols <- mandelbrot_palette(blues, in_set = "white",
  fold = TRUE, reps = 2)
plot(view, col = cols, transform = "log")

Plot a Mandelbrot set using base graphics

Description

Draws colored set membership using image.

Usage

## S3 method for class 'mandelbrot'
plot(x, col = mandelbrot_palette(c("white",
  grey.colors(50))), transform = c("none", "inverse", "log"), asp = 1, ...)

Arguments

x

an object generated by mandelbrot

col

a vector of colors, such as those generated by mandelbrot_palette

transform

the name of a transformation to apply to the number of iterations matrix

asp

the asp parameter to image which controls aspect ratio

...

extra arguments passed to image