Simple sdl tool for generating fractals
Find a file
AlexeyDomozhirov 02878ce6c1
Update README.md
Fix images links
2025-08-20 22:34:20 +06:00
app First version 2025-08-20 22:28:15 +06:00
examples First version 2025-08-20 22:28:15 +06:00
LICENSE First version 2025-08-20 22:28:15 +06:00
README.md Update README.md 2025-08-20 22:34:20 +06:00
TFractalGenerator.cabal First version 2025-08-20 22:28:15 +06:00

T-Fractal Generator

A simple SDL-based tool for generating visually T-shaped fractals.

Overview

The T-Fractal Generator is a lightweight application that creates unique fractal patterns using SDL. These fractals, named "T-shaped fractals" for their distinctive structure, are generated by overlaying patterns of rectangles that can be either transparent or semi-transparent. This project is designed to be cross-platform and easy to use, with customizable settings for generating a wide variety of fractal designs.

To get a better understanding of the fractals, explore the examples provided below or try generating your own using the tool!

What is a T-Fractal?

A T-fractal is a pattern created by overlaying grids of rectangles. Each rectangle in the pattern can be either transparent (allowing underlying layers to show through) or semi-transparent (with a specified color and alpha channel). The name "T-fractal" reflects the unique, often T-like shapes that emerge from this process.

Installation

Prerequisites

  • Cabal: Ensure Cabal is installed on your system. It is typically included with Haskell installations.
  • SDL2: The SDL2 library is required for rendering. Most systems have the necessary binaries, but if they are missing, installing them is straightforward. Refer to your package manager or the SDL2 website for instructions.

Steps

  1. Clone the repository:
    git clone https://github.com/your-username/t-fractal-generator.git
    
  2. Navigate to the project directory:
  3. Build the project using Cabal:
    cabal run
    
    Note: During the build process, Cabal may require certain binary files (e.g., SDL2 libraries). These are typically pre-installed on most systems. If they are missing, their installation is simple and should not pose a problem.

Usage

To run the T-Fractal Generator, execute the compiled binary with or without arguments:

Default Settings

Run the program without arguments to generate a fractal with default settings:

./TFractalGenerator

Custom Settings

For customized fractals, provide arguments in the following format:

./TFractalGenerator {pattern_size_x},{pattern_size_y} {base}^{power} #{hex_color_with_alpha} {pattern}

Argument Breakdown

  • pattern_size_x,pattern_size_y: The dimensions of the pattern grid (e.g., 4,4 for a 4x4 grid).
  • base^power: these two numbers describe the size of the largest square in the pattern, base also sets the number of splits in one iteration, it is not recommended to use too large values. in general, the description may not be very informative, it will be better to see for yourself how everything works
  • hex_color_with_alpha: A hex color code with an alpha channel for semi-transparent rectangles (e.g., #3af03a23).
  • pattern (optional): A string of 0s and 1s defining the pattern. It must contain exactly pattern_size_x * pattern_size_y characters, where:
    • 1 represents a semi-transparent rectangle with the specified hex color.
    • 0 represents a transparent rectangle.

Pattern Example

For a 4x4 pattern (pattern_size_x=4, pattern_size_y=4) with the pattern 1001011001101001, the grid is interpreted as:

1001  // 1 = semi-transparent, 0 = transparent
0110
0110
1001

Program settings examples

  1. Without specifying a pattern (uses empty pattern):
    ./TFractalGenerator 4,4 2^8 #3af03a23
    
  2. With a custom pattern:
    ./TFractalGenerator 4,4 2^8 #3af03a23 1001011001101001
    

Interactive Mode

The T-Fractal Generator when launched can be used in interactive mode that allows you to dynamically modify and visualize fractal patterns in real-time.

Features

  • Toggle Rectangle State: Click on any rectangle in the pattern grid to switch its state between semi-transparent (using the specified color with alpha channel) and transparent.
  • Keyboard Controls:
    • SPACE: Toggle pattern view mode (displays rectangles on top of the fractal in places of the pattern where semi-transparent rectangles are used)
    • D: Toggle dynamic mode. When dynamic mode is enabled (default), the fractal automatically regenerates after every change to the pattern. Disabling dynamic mode allows you to make multiple changes before regenerating the fractal.
    • E: Export the current fractal settings to the terminal where the executable was launched. The output includes the command-line arguments (e.g., pattern size, scaling factor, color, and pattern) that can be reused to recreate the same fractal.
    • Q: Exit the program.

Examples

Fractals examples, also note that the names of the image files represent the settings used for generation.

image

image

image

image

image

image

Contributing

Feel free to share your ideas, report issues, or suggest improvements by opening an issue or submitting a pull request on the GitHub repository

Platform Support

The T-Fractal Generator is built without platform-dependent code, making it compatible with any operating system that supports SDL2 and Haskell, including:

  • Windows
  • macOS
  • Linux

License

This project is licensed under the MIT license