cutcutcodec.core.generation.video.fractal.fractal

This module, implemented in C, offers functions for calculating fractals.

Functions

mandelbrot

Compute a mandelbrot grayscale image in C language.

Details

cutcutcodec.core.generation.video.fractal.fractal.mandelbrot()

Compute a mandelbrot grayscale image in C language.

For each pixel, given by a complex point \(c\), compute \(n\) iterations of the suite:

\[\begin{split}\begin{cases} z_0 = 0 \\ z_{n+1} = z_n^2 + c \\ \end{cases}\end{split}\]

Parameters

cpx_plannp.ndarray

The 2d complex plane that associates the constant \(c\) to each pixel. If the real part is nan, The corresponding pixel will not be initialized. This array doesn’t has to be c contiguous.

iterationsint, default=256

The maximum number of iterations before declaring that the sequence does not diverge. It must be >= 1 and <= 2147483647.

inper2boolean, default=True

If True (default), performs a test for each pixel to determine whether the pixel in question is in the cardioid or in the main disk. If False, calculates the sequence directly without prior testing.

threadsint, optional

Defines the number of threads. The value -1 means that the function uses as many calculation threads as there are cores. The default value (0) allows the same behavior as (-1) if the function is called in the main thread, otherwise (1) to avoid nested threads. Any other positive value corresponds to the number of threads used.

outnp.ndarray[np.float32], optional

If provided, set the result in this array and return it. This array doesn’t has to be c contiguous.

Returns

fractalnp.ndarray[np.float32]

The convergence speed of the suite in [0, 1]. 1 means it converges and 0 it diverges. The shape is the same as cpx_plan.

Examples

>>> import numpy as np
>>> from cutcutcodec.core.generation.video.fractal.fractal import mandelbrot
>>> y, x = np.meshgrid(
...     np.linspace(1, -1, 2000, dtype=np.float128),  # imaginary part, -y axis
...     np.linspace(-2, 1, 3000, dtype=np.float128),  # real part, x axis
...     indexing="ij",
... )
>>> cpx_plan = x + 1j*y
>>> fractal = mandelbrot(cpx_plan)
>>>