{"id":16068049,"url":"https://github.com/ged/lsystem","last_synced_at":"2025-08-03T19:33:47.475Z","repository":{"id":65988006,"uuid":"242420559","full_name":"ged/LSystem","owner":"ged","description":"A Ruby toolkit for constructing and using Lindenmeyer systems","archived":false,"fork":false,"pushed_at":"2020-02-27T00:55:45.000Z","size":112,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T20:56:57.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ged.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2020-02-22T22:27:52.000Z","updated_at":"2021-11-28T23:36:43.000Z","dependencies_parsed_at":"2023-07-10T17:16:33.050Z","dependency_job_id":null,"html_url":"https://github.com/ged/LSystem","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"4142ad1c144a980c65e44ad9d1274ea7170d3d4d"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ged%2FLSystem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ged%2FLSystem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ged%2FLSystem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ged%2FLSystem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ged","download_url":"https://codeload.github.com/ged/LSystem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318746,"owners_count":20919483,"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-10-09T06:08:15.683Z","updated_at":"2025-04-05T10:14:09.709Z","avatar_url":"https://github.com/ged.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LSystem\n\nhome\n: https://hg.sr.ht/~ged/LSystem\n\ncode\n: https://hg.sr.ht/~ged/LSystem\n\ngithub\n: https://github.com/ged/LSystem\n\ndocs\n: https://deveiate.org/code/l_system\n\n\n## Description\n\nA toolkit for creating and using [Lindenmayer Systems][l-system] (L-systems).\nIt consists of a class that allows for declaration of the L-system's grammar,\nand another class that allows for the definition of how the symbols output by a\ngrammar should be translated into work.\n\n**Note** if you just want to draw with it, you should consider using\n[kaki-lsystem][] instead; it has a nice interface with drawing already\nintegrated. This gem is intended for using l-systems for things other than\ndrawing (though it can obviously do that too), so it requires a bit more work.\n\n\n### Examples\n\nMost of these were stolen from [the examples on Wikipedia][l-system], and can be found in the `examples/` directory of the source.\n\n#### Algae\n\nLindenmayer's original L-system for modelling the growth of algae.\n\n* variables : A B\n* constants : none\n* axiom : A\n* rules : (A → AB), (B → A)\n\nDeclare the rules:\n\n    algae = LSystem.declare do\n    \n    \tvariables :A, :B\n    \taxiom 'A'\n    \trules 'A -\u003e AB',\n    \t    'B -\u003e A'\n    \n    end\n\nthen iterate it 8 times and print out each generation:\n\n    iter = algae.each\n    8.times do |i|\n        puts \"n = %d : %s\" % [ i, iter.next ]\n    end\n\nThis outputs:\n\n    n = 0 : A\n    n = 1 : AB\n    n = 2 : ABA\n    n = 3 : ABAAB\n    n = 4 : ABAABABA\n    n = 5 : ABAABABAABAAB\n    n = 6 : ABAABABAABAABABAABABA\n    n = 7 : ABAABABAABAABABAABABAABAABABAABAAB\n\n\nYou can also do more complex tasks with the symbols in each generation. For example, to generate pretty pictures.\n\n#### Barnsley fern\n\n* variables : X F\n* constants : + − [ ]\n* axiom : X\n* rules : (X → F+[[X]-X]-F[-FX]+X), (F → FF)\n* angle : 25°\n\nDeclare the rules:\n\n    fern = LSystem.declare do\n    \n      variables 'X', 'F'\n      constants '+', '-', '[', ']'\n      axiom 'X'\n      rules \\\n        'X → F+[[X]-X]-F[-FX]+X',\n        'F → FF'\n    \n    end\n\nThen hook them up to a Logo interpreter ([a monkeypatched version][tortoise-patch] of the [Tortoise gem][tortoise-gem]):\n\n    LSystem.run( fern, 8 ) do\n    \n      # The size of the canvas to draw on\n      CANVAS_SIZE = 2000\n    \n      # F: draw forward\n      # X : no-op\n      # -: turn left 25°\n      # +: turn right 25°\n      # [: push position and angle\n      # ]: pop position and angle\n      production_map \\\n        'F' =\u003e :forward,\n        '-' =\u003e :turn_left,\n        '+' =\u003e :turn_right,\n        '[' =\u003e :save_pos_and_angle,\n        ']' =\u003e :restore_pos_and_angle\n    \n      ### Set up some instance variables\n      def initialize( * )\n        super\n        @turtle = nil\n        @positions = []\n      end\n    \n    \n      on_start do |i, _|\n        @turtle = Tortoise::Interpreter.new( CANVAS_SIZE )\n        @turtle.setpos( CANVAS_SIZE / 2, 0 )\n        @turtle.direction = 90\n        @turtle.pd\n      end\n    \n    \n      on_finish do |i, _|\n        File.open( \"fern_gn#{i}.png\", File::WRONLY|File::TRUNC|File::CREAT, 0644, encoding: 'binary' ) do |fh|\n          fh.write( @turtle.to_png )\n        end\n      end\n    \n    \n      ### Draw a line forward\n      def forward\n        @turtle.fd( 5 )\n      end\n    \n    \n      ### Turn 25° to the left\n      def turn_left\n        @turtle.lt( 25 )\n      end\n    \n    \n      ### Turn 25° to the right\n      def turn_right\n        @turtle.rt( 25 )\n      end\n    \n    \n      ### Save the drawing position and angle\n      def save_pos_and_angle\n        @positions.push([ @turtle.position, @turtle.direction ])\n      end\n    \n    \n      ### Restore the next saved position and angle\n      def restore_pos_and_angle\n        to_restore = @positions.pop or raise IndexError, \"Position stack underflow\"\n    \n        @turtle.setpos( *to_restore.first )\n        @turtle.direction = to_restore.last\n      end\n    \n    end\n\nThis generates a sequence of images, which for generation 8 yields:\n\n![Fern Gen 7](examples/fern_gn7.png)\n\n\n## Prerequisites\n\n* Ruby\n\n\n## Installation\n\n    $ gem install l_system\n\n\n## Contributing\n\nYou can check out the current development source with Mercurial via its\n[project page](https://hg.sr.ht/~ged/LSystem). Or if you prefer Git, via\n[its Github mirror](https://github.com/ged/l_system).\n\nAfter checking out the source, run:\n\n    $ rake setup\n\nThis task will install dependencies, and do any other necessary setup for development.\n\n\n## Authors\n\n- Michael Granger \u003cged@faeriemud.org\u003e\n\n\n## License\n\nCopyright (c) 2020, Michael Granger\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice,\n  this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice,\n  this list of conditions and the following disclaimer in the documentation\n  and/or other materials provided with the distribution.\n\n* Neither the name of the author/s, nor the names of the project's\n  contributors may be used to endorse or promote products derived from this\n  software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n[l-system]: https://en.wikipedia.org/wiki/L-system\n[kaki-lsystem]: https://rubygems.org/gems/kaki-lsystem\n[tortoise-gem]: https://rubygems.org/gems/tortoise\n[tortoise-patch]: https://hg.sr.ht/~ged/LSystem/browse/default/examples/tortoise_monkeypatches.rb\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fged%2Flsystem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fged%2Flsystem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fged%2Flsystem/lists"}