Skip to main content

Implements l-system fractals. Has common ones such as fractal plant and Koch curve.

Project description

L-System Fractals

Implementation of L-System Fractals. This package draws fractals in turtle.

Sample Generations

Sample Colorful Fractal Plant Sample Colorful Koch Curve Sample Colorful Sierpinski Triangle Sample Colorful Sierpinski Arrowhead Curve Sample Colorful Dragon Curve


Table of Contents

  • Installation
  • Why Use l-system?
  • Usage
  • Versions
  • Coming Soon

Installation

pip install l-system-fractals

Why Use l-system?

This package includes an base LSystem class with default subclasses for common l-system fractals:

  • Fractal plant
  • Koch curve
  • Sierpinski triangle
  • Sierpinski arrowhead curve
  • Dragon curve

Usage

Example 1

Drawing custom L-Systems using the LSystem Class

from l_system import *

my_l_system = LSystem(
    iterations=5,
    start="X",
    rules=[("X", "-F+X"), ("F", "-F-[X+F]+F")],
    variable_rules=[("F", DRAW_FORWARD), ("X", MOVE_FORWARD)],
    constant_rules=[("-", TURN_RIGHT), ("+", TURN_LEFT), ("[", SAVE_POS_AND_ANGLE), ("]", GO_TO_POS_ANGLE_AND_RESET_THEM)],
    angle=30,
    scale=2,
    thickness=2,
    start_angle=10
)

my_l_system.draw_turtle(pos=(0, 0), speed=0, end_turtle=True, instant=False, make_colorful=True, color_density=10)

Example 2

Drawing custom L-Systems using subclass of LSystem Class

from l_system import *

class MyLSystem(LSystem):
    def __init__(self):
        super().__init__(
        iterations=5,
        start="X",
        rules=[("X", "-F+X"), ("F", "-F-[X+F]+F")],
        variable_rules=[("F", DRAW_FORWARD), ("X", MOVE_FORWARD)],
        constant_rules=[("-", TURN_RIGHT), ("+", TURN_LEFT), ("[", SAVE_POS_AND_ANGLE), ("]", GO_TO_POS_ANGLE_AND_RESET_THEM)],
        angle=30,
        scale=2,
        thickness=2,
        start_angle=10
        )

my_l_system = MyLSystem()

my_l_system.draw_turtle(pos=(0, 0), speed=0, end_turtle=True, instant=False, make_colorful=True, color_density=10)

Example 3

Drawing L-System using pre-made classes

from l_system import *

my_l_system = FractalPlant(iterations=6, start = "X", scale = 3, thickness = 1, start_angle = 0)

my_l_system.draw_turtle(pos=(0, -300), speed=0, end_turtle=True, instant=False, make_colorful=True, color_density=10)

Versions

Version 0.0.1: Main code for l-system added. (Latest) Version 0.0.2: README fixed.


Coming Soon

Version 0.0.3: Add support for drawing L-Systems on a specific pen given by the user instead of creating a new pen.

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

l_system_fractals-0.0.2.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file l_system_fractals-0.0.2.tar.gz.

File metadata

  • Download URL: l_system_fractals-0.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for l_system_fractals-0.0.2.tar.gz
Algorithm Hash digest
SHA256 3310321a1943325a0f5755adc1c008e2172ad4f8122bee9d8ac0282859e36ba7
MD5 877cecf8731ad9933cec52c9aca7e4f8
BLAKE2b-256 4fc2bc24d2b830dd76f61fe6d4d1c783ec14f990e93986f9c4566cd8b17fe8e3

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