Giter VIP home page Giter VIP logo

ifs-fractals-gpu's Introduction

Fast IFS Fractal Generation with PyTorch on GPU

This repository contains Python scripts for generating fractal images using Iterated Function Systems (IFS) with customizable configurations. The scripts utilize PyTorch for computations, allowing for GPU acceleration.

Design 7

Key Components

  • examples.py: Demonstrates how to generate fractals using predefined configurations.
  • fractal_config.py: Contains definitions for various fractal configurations.
  • gen_ifs_fractal.py: Defines the IFSFractal class and methods for generating and rasterizing fractals.

Custom Fractal Configurations

You can create custom fractal configurations by modifying or creating instances of FractalConfig in fractal_config.py. Each configuration requires:

  • name: A unique name for the fractal.
  • transformations: A list of tuples, each containing a transformation matrix and a translation vector.
  • colors: A list of RGB color tuples for each transformation.
  • probability_weights: (Optional) A list of probabilities for each transformation.
  • activation: (Optional) The activation function to use (e.g., 'none', 'relu', 'sigmoid'). Default is 'selu'.
  • batch_size: The number of points to process in each batch.
  • num_iterations: The number of iterations to perform.

Example configuration:

SIERPINSKI_TRIANGLE = FractalConfig(
    name="SierpinskiTriangle",
    transformations=(
        (torch.tensor([
            [0.5, 0.0],
            [0.0, 0.5]
        ]), torch.tensor([0.0, 0.0])),
        (torch.tensor([
            [0.5, 0.0],
            [0.0, 0.5]
        ]), torch.tensor([0.5, 0.0])),
        (torch.tensor([
            [0.5, 0.0],
            [0.0, 0.5]
        ]), torch.tensor([0.25, 0.5]))
    ),
    colors=(
        (0, 127.5, 205),
        (255, 127.5, 10),
        (180, 190, 254)
    ),
    num_iterations=200000,
)

"Composing" Fractals

Fractal configurations can be composed easily

A_comp_B = FractalConfig(
    name="A_comp_B",
    transformations=(
        *fractal_A.transformations,
        *fractal_B.transformations
    ),
    colors=(
        *fractal_A.colors,
        *fractal_B.colors
    ),
    probability_weights=(1., 1., 8., 8., 8., 1., 1., 8.),
    activation='selu',
)

Usage

To generate fractals, you can use the generate_fractal_image function in gen_ifs_fractal.py. For example:

image = generate_fractal_image(SIERPINSKI_TRIANGLE, 
                               device='cuda', 
                               size=8192, 
                               batch_size=1000000)
image.save('sierpinski_triangle.png')

Gallery

Design 5 Design 9 Design 1 Design 2 Design 3 Design 4 Design 10 Design 6 Design 11 Design 8 Design 12

Color Spaces

Averaging the colors of the fractal points in each iteration results in a single color for each point. The color is then mapped to a color space and the image is rasterized. I have found that HSL creates the most interesting results.

RGB Design 2

HSL Design 2

ifs-fractals-gpu's People

Contributors

kettukaa avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.