Skip to main content

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

Project description

Diamond Square

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

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


Coming Soon

Version 0.0.2: 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.1.tar.gz (3.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: l_system_fractals-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 62c3563bd1820972fdf3ccd5a22a211c3b9ba2903614dc17b2ca4e2f723319ca
MD5 43bf003666a2cf519b73b52fa32ee72b
BLAKE2b-256 c966e96b3cb141f2ce52826eca65a4a1354e8195fb3ad1e431856f0e6f2df916

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