/FractalGen

Fractal-gen is a python Fractal image generating library.

Primary LanguagePythonMIT LicenseMIT

FractalGen

FractalGen is a open library which can be used to generate, experiment and create fractal images using IFS'. IFS' are Iterated Function Systems which are used in one of the methods in constructing fractals. IFS' are simply set of Affine equations upon which we apply different algorithms to generate fractal images. For further more detailed explanation on IFS' and their workings we recommend users to go through these links below:

Out of many algorithms which generate fractals, our library generates fractals based on Deterministic and Random Iteration algorithms. There are notaions of affine transformations for iterated functions systems (IFS) which are as follows:

and

and

Out of all the most used notation is the third one. Many IFSs are available in similar format to the 3 notation or they can be derived from different forms to the 3rd one some of mostly used notations are below

Capture

Deterministic:

Tabular representation of values a, b, c, d, e, f of 4 Affine transformations.

a b c d e f
set 1 0.01 0 0 0.45 0 0
set 2 -0.01 0 0 -0.45 0 0.4
set 3 0.42 -0.42 0.42 0.42 0 0.4
set 4 0.42 0.42 -0.42 0.42 0 0.4

random iteration:

Tabular representation of values a, b, c, d, e, f, p of 4 Affine transformations.

a b c d e f probability
set 1 0 0 0 0.16 0 0 0.01
set 2 0.2 -0.26 0.23 0.22 0 1.6 0.07
set 3 -0.15 0.28 0.26 0.24 0 0.44 0.07
set 4 0.85 0.04 -0.04 0.85 0 1.6 0.85

So all the details we need to generate fractal image are values of a, b, c, d, e, f of an affine traformation in a IFS while using deterministic algorithm and probabilities in addition while using random iteration algorithm. We recommend users to get a good picture on working of IFS' and representations of IFSs before continuing further.

Installation

  • Using pip to install.

    You can find our project on PyPi FractalGen
    pip install FractalGen
    
  • Installing from whl file.

    The latest .whl is in FractalGen/build. To install the latest version use the below command.
    pip install FractalGen-0.2-py3-none-any.whl
    

How to use

How to create a IFS object and adding eqns.

ifs_obj = Ifs()
lst = [
    [0, 0, 0, 0.16, 0, 0, 0.01], # => [a, b, c, d, e, f, p]
    [0.85, 0.04, -0.04, 0.85, 0, 1.60, 0.85],
    [0.20, -0.26, 0.23, 0.22, 0, 1.60, 0.07],
    [-0.15, 0.28, 0.26, 0.24, 0, 0.44, 0.07],
]

ifs_obj.AddEquations(lst) # Length of all eqns should be equal. Length 7 of random iteration.
                          # length 6 for deterministic.

Printing IFS object.

print(ifs_obj)

# equation = 1: [[a = 0.0 b = 0.0]   [[e = 0]  p=0.01
# 	         [c = 0.0 d = 0.16]]  [f = 0]]

# equation = 2: [[a = 0.85 b = 0.04]   [[e = 0.0]  p=0.85
# 	         [c = -0.04 d = 0.85]]  [f = 1.6]]

# equation = 3: [[a = 0.2 b = -0.26]   [[e = 0.0]  p=0.07
# 	         [c = 0.23 d = 0.22]]  [f = 1.6]]

# equation = 4: [[a = -0.15 b = 0.28]   [[e = 0.0]  p=0.07
#  	         [c = 0.26 d = 0.24]]   [f = 0.44]]

Running fractal generating algorithms.

ifs_obj.randomIteration(1_00_000) # Run 1,00,000 iterations.

# For using deterministic algorithm use the below.
ifs_obj.deterministic(Shape.square(), iteration) # deterministic takes Shape and number of iterations as arguments.
                                                 # You can use pre-defined Shape check out Shape class.
                                                 # As of now we have 200-300 points to generate a shape.

Plotting fractal image.

ifs_obj.plot()

Output fractal image.

  • Random iteration output:

  • Deteministic output: