Skip to content

Latest commit

 

History

History
290 lines (204 loc) · 10.8 KB

README.md

File metadata and controls

290 lines (204 loc) · 10.8 KB

Complex Fractals

Image generation of various fractals in the complex plane.

Built with Python 3.7.8, Numpy, and Numba.


Table of Contents


Todo List

  • Add additional fractals (3rd and 4th powers)?
  • Have .animate() create an .mp4 or .gif rather than a series of images.
  • Real time color map previews with adjustable phase inputs.
  • Real time viewer of fractals to explore and find inputs to use for final renders.

About The Project

  • todo - generic about segment

How it Works

Each fractal is generated using an iterative function. The mandelbrot, for example, uses the function     where     and     are both complex numbers in the form     with    . Here     is a constant representing the coordinate of a pixel and     is the point     in the complex plane. The point is iterated until it either escapes a given radius from the origin or the iteraiton count limit is hit. Points which do not escape are said to be part of the set (typically colored black), and points that do diverge are colored based on their highest iteration count before they escaped. The coloring is smoothed to give a nicer looking output.


Usage

Creating the workspace

# After cloning the repository and navigating to the directory
$ python -m venv venv
$ .\venv\scripts\activate
$ pip install -r requirements.txt

Importing to a fresh file

from complex_fractals import * # import all classes and functions

Fractal types

ComplexFractal("list") # list all identifiers to console

""" output will look as follows. Either the number (as int) or name (as str) can be used as identifier parameter

-1 - list
 0 - mandelbrot
 1 - mandelbar
 .
 .
 .
11 - perpendicular_buffalo
"""

Basic usage

f = ComplexFractal() # set up a mandelbrot with default parameters
f.draw() # create the image

Parameters

ComplexFractal

#rgb_phases used for all parameter images
phases = [0.4621369927925133,0.5109418659399724,0.5222266582635113]

identifier

see Fractal Types for how to retrieve a list of possible identifiers. The integer and string are both valid inputs.

width

number of pixels in the horizontal dimension of the output image.

aspect_ratio

aspect ratio of the output image. Input as type str in the form "W:H". Defaults to "16:9" (1920x1080), another common aspect ration is "21:9" (3440x1440).

16:9 21:9

ComplexFractal(aspect_ratio="16:9", rgb_phases=phases, 
    filename="aspect_ratio_16-9").draw()
ComplexFractal(aspect_ratio="21:9", rgb_phases=phases,
    filename="aspect_ratio_21-9").draw()

cycle_count

the number of iterations before the colormap cycles back to the start. Smaller values yield faster color transitions.

color map

cycle count 16 cycle count 32 cycle count 64

ComplexFractal(cycle_count=16, rgb_phases=phases, 
    filename="cycle_count_16").draw()
ComplexFractal(cycle_count=32, rgb_phases=phases, 
    filename="cycle_count_32").draw()
ComplexFractal(cycle_count=64, rgb_phases=phases, 
    filename="cycle_count_64").draw()

oversample

scale the image dimensions by a factor of oversample. The image is then downscaled to the desired size by averaging oversample*oversample grids of pixels. Creates a cleaner image, but large oversample values can greatly increase computation times. Value must be greater than or equal to 1.

oversample 1 oversample 4

ComplexFractal(oversample=1, rgb_phases=phases, 
    filename="oversample_1").draw()
ComplexFractal(oversample=4, rgb_phases=phases, 
    filename="oversample_4").draw()

real

the real value to focus on or to zoom in on. Defaults to the center of the set.

imag

the imaginary value to focus on or to zoom in on. Defaults to the center of the set.

zoom

the depth of the zoom. Value should be greater than or equal to 1. Defaults to 1.

rgb_phases

phases used to create cyclic color map. Each value should be in the range [0.0, 1.0].

colormap [0.0, 0.8, 0.15] colormap [0.05, 0.21, 0.31] colormap [0.85, 0.17, 0.55]

# Can preview colormaps using custom values with...
ColorMap(rgb_phases=[0.0, 0.8, 0.15]).preview_colormap()

# Or preview random colormaps with...
ColorMap(random_phases=True).preview_colormap() # random values generated are output to console

random_phases

Whether random rgb phases should be used. Will always overide any values passed to rgb_phases if True. Defaults to False.

iter_max

maximum number of iterations until a point that doesn't escape is considered part of the set. Deeper zoom levels require higher iter_max values.

stripe_density

how dense the stripes are in the final image.

stripe density 0 stripe density 2 stripe density 6

ComplexFractal(stripe_density=0, rgb_phases=phases, 
    filename="stripe_density_0").draw()
ComplexFractal(stripe_density=2, rgb_phases=phases, 
    filename="stripe_density_2").draw()
ComplexFractal(stripe_density=6, rgb_phases=phases, 
    filename="stripe_density_6").draw()

stripe_memory

the weight of historical values kept between iterations. Value should be in the range [0.0, 1.0]

stripe memory 0.0 stripe memory 0.4 stripe memory 0.9

ComplexFractal(stripe_memory=0.0, rgb_phases=phases, 
    filename="stripe_memory_0.0").draw()
ComplexFractal(stripe_memory=0.4, rgb_phases=phases, 
    filename="stripe_memory_0.4").draw()
ComplexFractal(stripe_memory=0.9, rgb_phases=phases, 
    filename="stripe_memory_0.9").draw()

blend_factor

how strong of a showing the stripes make in the final image, value in [0.1, 1.0].

blend factor 0.33 blend factor 0.66 blend factor 1.00

ComplexFractal(blend_factor=0.33, rgb_phases=phases, 
    filename="blend_factor_0.33").draw()
ComplexFractal(blend_factor=0.66, rgb_phases=phases, 
    filename="blend_factor_0.66").draw()
ComplexFractal(blend_factor=1.0, rgb_phases=phases, 
    filename="blend_factor_1.0").draw()

gpu

Compute with GPU or with CPU. True will render using the GPU. Defaults to False. GPU will render the image significantly faster than CPU but requires the CUDA toolkit to be installed. Details on how to install it to work with Numba can be found here.

filename

The name to be assigned to the output image. Defaults to the stringed version of the identifier.

Animate

start

the initial zoom level. Should be greater than or equal to 1.

end

the target zoom level to be reached in the final frame. Must be greater than start value.

rate

the speed at which the zoom level approaches the end value. Must be strictly greater than 1.


Examples

  • todo create example images/gifs/mp4s