Skip to main content

An open-source CLI software for generating fractal images using the L-System.

Project description

L-System Fractal Generator

An open-source CLI software for generating fractal images using the L-System.

Features

  • Rewrite and draw a 2D deterministic context-free L-System. (D0L)
  • Support the following turtle commands:
Command Description
F Draw a line forward d pixels in the current heading
f Move forward d pixels in the current heading without drawing a line
+ Turn right by δ degrees
- Turn left by δ degrees
[ Push the current turtle's state into a stack
] Pop a turtle's state out of the stack
  • Support saving and previewing the output image
  • Support changing the drawing line's width

Background

L-System (Lindenmayer System) is a string rewriting system that uses an iterative process. An L-System starts with an axiom, an initial string, that will be rewritten following a set of production rules which contains pairs of predecessors and successors. For each iteration, each symbol or character will be replaced with its corresponding successor. Any symbols without a production rule will be replaced by themselves. For example,

Axiom: N
Production Rules:

Predecessor Successor
N MNO
O #

Iteration 0: N
Iteration 1: MNO
Iteration 2: MMNO#
Iteration 3: MMMNO##

For illustration, lfract reserves some characters for controlling a drawing pen called a turtle. The turtle keeps track of its position and heading throughout the evaluation process. After some finite number of iterations, the resulting string will be evaluated and an image will be drawn. (Supported turtle commands are listed in the previous section)

The current version of lfract supports only the deterministic and context-free version of the L-System. That is each rule has a probability of being applied of 1 and the location of each symbol in a string relative to other symbols doesn't matter.

Installation

This software is available to download on The Python Package Index (PyPI) and can be installed through pip.

Start by making sure that pip is installed and up-to-date

python -m pip install --upgrade pip

Run the following command on your terminal

pip install lfract

Usage

Invokes the program using lfract. There are seven optional arguments as follows:

Option Description
-x, --axiom Initial string or axiom, required
-r, --rules Production rules. Uses "->" to seperate predecessor from successor, optional
-a, --angle Turning angle, δ (degrees), default = 90
-d, --dist Distance, d (pixels), default = 100
-n, --iters Number of iterations, default = 0
-o, --output Output path. If specified, the image will be saved to the given path, optional
-w, --width Width of the drawing pen (pixels), default = 1

The user must provide at least an axiom or the initial string to the L-System. All predecessors in the set of production rules must be unique. If there are duplicates, lfract will use the latest rule.

For the full usage description of lfract, type:

lfract --help

Examples

  1. Hilbert curve by Prusinkiewicz and Hanan [1]

    lfract -x X -r X->-YF+XFX+FY- Y->+XF-YFY-FX+ -a 90 -d 50 -n 5 -w 5

hilbert

  1. Hexagonal tiling by Prusunkiewicz and Hanan [1]

    lfract -x X -r X->[-F+F[Y]+F][+F-F[X]-F] Y->[-F+F[Y]+F][+F-F-F] -a 60 -d 50 -n 10 -w 4

hex

  1. A fractal by Surasith Boonaneksap

    lfract -x A -r A->fB+AF+Fff+Bf B->Bf-FffF-FfA-Afff -a 120 -n 7 -d 50 -w 5

ex1

Notes

  • lfract adopts the L-System formal definition from [1]. It also follows the terminologies used in [1][2][3].
  • Symbols in the L-System can be any Unicode characters.
  • Currently not support:
    • Stochastic L-System
    • Context-sensitive L-System
    • Parametric L-System

Dependency

Pillow 4.0.0 (Depending on the Python's version, a more recent version may be required. Check Pillow's documentation)

License

MIT

References

[1]: Prunsinkiewicz, Przemyslaw and Hanan, James; "Lecture Notes in Biomathematics: Lindenmayer Systems, Fractals, and Plants" link
[2]: Wikipedia; "L-system" link
[3]: Santel, Jordan; "L-systems" link

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lfract-1.0.0rc1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lfract-1.0.0rc1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file lfract-1.0.0rc1.tar.gz.

File metadata

  • Download URL: lfract-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.8.6 Windows/10

File hashes

Hashes for lfract-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 ddeb430bf8b9431142103440da976fcdbb9e9e71f13c2a04d75f2d763528a047
MD5 5c50bc57865722925e6ecbebdffa2e1d
BLAKE2b-256 cd68453e5fa3c60ee38ab98b53cc3c42655ef4f920edf041f27dcfb5b5139531

See more details on using hashes here.

File details

Details for the file lfract-1.0.0rc1-py3-none-any.whl.

File metadata

  • Download URL: lfract-1.0.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.8.6 Windows/10

File hashes

Hashes for lfract-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7e991cb8ad4acd5ff3e36fdfb2e26ef80227c997d485a2fff0cd03cb01e84bb
MD5 aa8e059e397370326d6be68e70cfcf27
BLAKE2b-256 995f1903b87c271c53160d0b4953d8385c9f636222be4c62162a5abe6705e361

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page