Skip to main content

Display images generated by L-Systems.

Project description

L-System

An L-system or Lindenmayer system is a parallel rewriting system and a type of formal grammar. An L-system consists of an alphabet of symbols that can be used to make strings, a collection of production rules that expand each symbol into some larger string of symbols, an initial "axiom" string from which to begin construction, and a mechanism for translating the generated strings into geometric structures. L-systems were introduced and developed in 1968 by Aristid Lindenmayer, a Hungarian theoretical biologist and botanist at the University of Utrecht. Lindenmayer used L-systems to describe the behaviour of plant cells and to model the growth processes of plant development. L-systems have also been used to model the morphology of a variety of organisms and can be used to generate self-similar fractals.1

Installation

You can download and install the latest release using pip.

pip install LSystemRenderer

Usage

After installing the latest version you can run the script as follows:

lsystem-gui lsystem=LSYSTEM_NAME

Where LSYSTEM_NAME is the name of the L-System configuration file. There are several configuration files provided, but you can create your own custom L-System configuration as well.

Implemented L-Systems
1. dragon_curve
2. hexagonal_gosper_curve
3. koch_snowflake
4. koch_quadratic_island
5. plant_edge_rewriting_1
6. plant_edge_rewriting_2
7. plant_node_rewriting_1
8. plant_node_rewriting_2
9. sierpinsky_triangle
10. squared_squares
11. stochastic_plant_edge_rewriting

Plant Edge Rewriting 1

Plant Edge Rewriting 1

Plant Edge Rewriting 2

Plant Edge Rewriting 2

Plant Node Rewriting 1

Plant Node Rewriting 1

Plant Node Rewriting 2

Plant Node Rewriting 2

Stochastic Plant Edge Rewriting

Stochastic Plant Edge Rewriting

Configuration File Structure

The main config.yaml file extends application and lsystem configuration files. This file contains the default configuration of the application when it is called without command line arguments.

defaults:
  - app: APP_CONFIG
  - lsystem: LSYSYSTEM_CONFIG

L-System Configuration

The lsystem *.yaml files contains the following:

  1. Name of the L-System
_target_: lsystem.config.LSystemConfig
name: LSYSTEM_NAME
  1. Context-free grammar $G = (N, T, P, S)$ of the L-System:
    • $N$ - a list of non-terminal symbols $n \in N$ (appear on the left side of the rules)
    • $T$ - a list of terminal symbol $t \in T$ (only appear on the right side of the rules)
    • $P$ - a list of production rules in the form of $N \rightarrow (N \cup T)^*$
    • $S$ - starting axiom, $S = (N \cup T)^*$
grammar:
  _target_: lsystem.model.grammar.Grammar.from_dict
  nonterminals: LIST_OF_NONTERMINAL_SYMBOLS
  terminals: LIST_OF_TERMINAL_SYMBOLS
  rules: LIST_OF_RULES
  axiom: STARTING_AXIOM
  1. Renderer configuration for the L-System:

    • line_segment_length - starting length of the line segments

    • line_segment_length_reduction - percentage length reduction with each successive generation (step)

    • angle_offset - angle by which the renderer turns to the left/right

    • instruction_mapping - dictionary mapping symbols $s \in N \cup T$ to their corresponding renderer instuctions from InstructionEnum:

      • NOP - no operation
      • FORWARD - draw line segment of given length in the direction the renderer is facing
      • LEFT - turn left by a number of degrees
      • RIGHT - turn right by a number of degrees
      • SAVE - push the (X, Y, angle) state of the renderer onto a stack
      • LOAD - pop the (X, Y, angle) state of the renrerer from a stack
    • starting_state - starting state of the renderer:

      • x - starting X coordinate
      • y - starting Y coordinate
      • angle - starting angle
renderer_config:
  line_segment_length: LENGHT_PIXELS
  line_segment_length_reduction: LENGTH_REDUCTION_PERCENTAGE
  angle_offset: ANGLE_IN_DEGREES
  
  instruction_mapping:
    _target_: lsystem.mapping.InstructionMapping.from_dict
    map: INSTRUCTION_DICT

  starting_state:
    _target_: lsystem.renderer.RendererState
    x: STARTING_X
    y: STARTING_Y
    angle: STARTING_ANGLE

L-System Configuration File Example

Example of a lsystem configuration file dragon_curve.yaml:

_target_: lsystem.config.LSystemConfig
name: "Dragon Curve L-System"

grammar:
  _target_: lsystem.model.grammar.Grammar.from_dict
  nonterminals: [F, G]
  terminals: [+, -]
  rules: [
    [F, F+G],
    [G, F-G]
  ]
  axiom: F

renderer_config:
  line_segment_length: 50
  line_segment_length_reduction: 0.80
  angle_offset: 90

  instruction_mapping:
    _target_: lsystem.mapping.InstructionMapping.from_dict
    map: {
      'F': FORWARD,
      'G': FORWARD,
      '+': RIGHT,
      '-': LEFT,
      '[': SAVE,
      ']': LOAD,
    }

  starting_state:
    _target_: lsystem.renderer.RendererState
    x: 0
    y: 0
    angle: 0

App Configuration File

The app *.yaml configuration file contains parameters for setting up the GUI of the application.

window_size: [WIDTH, HEIGHT]
line_color: [R, G, B]
background_color: [R, G, B]

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

LSystemRenderer-0.0.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distributions

LSystemRenderer-0.0.2-py3.10.egg (57.8 kB view details)

Uploaded Source

LSystemRenderer-0.0.2-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: LSystemRenderer-0.0.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for LSystemRenderer-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4ce6c0b55c9d37b107fc45bd3f9feae03a212fb3547ef56c307b6701267ab090
MD5 3a6895158f9ed44ea99416dc5fb79bc1
BLAKE2b-256 405d17f4ddd779f6cfc5fb6e2d09a08567f702ebdcdf62b2466c216f4fae2cde

See more details on using hashes here.

File details

Details for the file LSystemRenderer-0.0.2-py3.10.egg.

File metadata

  • Download URL: LSystemRenderer-0.0.2-py3.10.egg
  • Upload date:
  • Size: 57.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for LSystemRenderer-0.0.2-py3.10.egg
Algorithm Hash digest
SHA256 a4f9e1dd04109b386a5e68da6d2f3ca30c7f3acb97cc5d64c8845147d2560826
MD5 8021a55856ecd93a4c0fc97ec27fabc9
BLAKE2b-256 fd29bb2f8808d73dc07c96deebf22a2d17fdf04ae73dfbd6bd70320afd418ce4

See more details on using hashes here.

File details

Details for the file LSystemRenderer-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for LSystemRenderer-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6416f7d790954c00937f7f59fd445a1de270785c5c2f3ec2a415cfb0a16df9c5
MD5 d130ebe4f1e2624de6d2d5f5a90fb5fe
BLAKE2b-256 8f07d6e79c331e5955d1f461800cb77194a8122a18990094a519af250a905d09

See more details on using hashes here.

Supported by

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