{"id":20553570,"url":"https://github.com/mrtj/lsystem","last_synced_at":"2025-06-29T13:36:05.122Z","repository":{"id":69169715,"uuid":"329691942","full_name":"mrtj/lsystem","owner":"mrtj","description":"L-System renderer in python","archived":false,"fork":false,"pushed_at":"2021-01-19T13:37:06.000Z","size":2570,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-16T17:30:31.234Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrtj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-14T17:49:03.000Z","updated_at":"2024-12-31T04:58:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"2937a897-7daf-42c0-ae3d-9129b78c0235","html_url":"https://github.com/mrtj/lsystem","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrtj%2Flsystem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrtj%2Flsystem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrtj%2Flsystem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrtj%2Flsystem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrtj","download_url":"https://codeload.github.com/mrtj/lsystem/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242157374,"owners_count":20081052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T02:42:28.864Z","updated_at":"2025-03-06T06:19:25.896Z","avatar_url":"https://github.com/mrtj.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# L-System renderer\n\nThis repository contains an implementation of an *L-System* renderer. \n\n## What is an L-System?\n\nAn *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* (`actions`) that can be used to make strings, a collection of *production rules* (`rules`) that expand each symbol into some larger string of symbols, an initial *axiom string* (`axiom`) from which to begin construction, and a mechanism for translating the generated strings into geometric structures. (From [Wikipedia](https://en.wikipedia.org/wiki/L-system)).\n\nFor example a binary tree can be described in L-System as:\n```python\nactions = {\n    \"A\": \"draw_forward\", \n    \"B\": \"draw_forward\",\n    \"+\": \"left_turn\",\n    \"-\": \"right_turn\",\n    \"[\": \"save_state\",\n    \"]\": \"restore_state\"\n}\nrules = {\n    \"A\": \"B[+A]-A\",\n    \"B\": \"BB\"\n}\naxiom = \"A\"\nangle = 30\n```\n\nThe `angle` parameter defines the angle of the left or right turns in degrees.\n\nWhen rendering the L-System one might define how much time the substition rules should be applied, in order words the maximum depth of the recursions. This parameter is called `order`.\n\n## Usage\n\nThe LSystem library provides a default symbol -\u003e actions mapping that conforms the [Inkspace](https://inkscape.org) L-System renderer conventions. So at minimum you should specify only the `rules` map, the initial `axiom` and the turn `angle`:\n\n```python\nfrom lsystem import LSystem\n\ntree_renderer = LSystem(rules, axiom, angle)\ntree_renderer.execute(tree_renderer.axiom, order=4, unit=10)\n```\n\nThe `LSystem` class also contains a convenience `demo` method that draws the curve with the predefined parameters:\n\n```python\ntree_renderer.demo()\n```\n\n### json support\n\nYou can initialize the `LSystem` class also from a json file:\n\n```python\nLSystem.from_json(\"examples/levyc.json\").demo()\n```\n\nFor the available json keys refer to the documentation of the `LSystem()` constructor.\n\n### Command line interface\n\n```\n$ python lsystem.py -h\nusage: lsystem.py [-h] [-u UNIT] [-o ORDER] [-t] input_file\n\nL-System renderer\n\npositional arguments:\n  input_file               json definition of the L-System\n\noptional arguments:\n  -h, --help               show this help message and exit\n  -u UNIT, --unit UNIT     base unit of the drawing in pixels\n  -o ORDER, --order ORDER  depth of the recursion\n  -t, --trace              print tracing info to stdout\n\nClick on the drawing window to exit.\n```\n\n## Examples\n\n![examples/binarytree.json](doc/binarytree.png \"examples/binarytree.json\")\n![examples/cesaro.json](doc/cesaro.png \"examples/cesaro.json\")\n![examples/levyc.json](doc/levyc.png \"examples/levyc.json\")\n![examples/penrose3.json](doc/penrose3.png \"examples/penrose3.json\")\n![examples/plant.json](doc/plant.png \"examples/plant.json\")\n![examples/randtree.json](doc/randtree.png \"examples/randtree.json\")\n![examples/sierpinskiarrow.json](doc/sierpinskiarrow.png \"examples/sierpinskiarrow.json\")\n![examples/dragon.json](doc/dragon.png \"examples/dragon.json\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrtj%2Flsystem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrtj%2Flsystem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrtj%2Flsystem/lists"}