Infinite Plant Variations with Random L Systems Rules

Sdílet
Vložit
  • čas přidán 31. 05. 2024
  • Code from video: editor.p5js.org/BarneyCodes/s...
    L-Systems are a really great way of generating all kinds of different shapes, especially plants, but it bothers me that they always generate the SAME plant each time. In this video, I fix this by adding random elements to the L-System definition to create some very easy procedural plants!
    Follow me:
    Support the channel: www.youtube.com/@BarneyCodes/...
    Twitter: / barneycodes
    Reddit: / barneycodes
    Chapters:
    0:00 What's wrong with L Systems?
    0:31 How we're going to fix it
    1:12 The setup
    1:32 The upgraded generate function
    2:23 Choosing a random rule
    2:51 Using array rules
    3:38 Adding more variety
    4:20 MORE VARIETY
    5:21 Final thoughts
    #creativecoding #p5js #javascript #lsystem

Komentáře • 19

  • @BarneyCodes
    @BarneyCodes  Před rokem +3

    Hope you all enjoyed the video! I would love to see what awesome stuff you guys come up with using this method so please share them in the comments!
    If you'd like to see what else I'm working on, it would be great if you could wishlist my game Star Mining Co. on Steam! s.team/a/2584800/

  • @SuperMaramau
    @SuperMaramau Před 3 měsíci +1

    Another concise and clear explanation.
    Really like that you sum probabilities. I'm used to using multiple conditional statements.
    Your idea is definitely an improvement.

  • @Meverynoob
    @Meverynoob Před rokem +2

    Really interesting, I'd like to try making randomised fractals but they're so open ended I'm not sure what'll look good but also have high variability

    • @BarneyCodes
      @BarneyCodes  Před rokem +1

      That sounds very cool! I'd love to see what you come up with!

  • @StevesMakerspace
    @StevesMakerspace Před rokem +2

    Man, you really rocked the editing in this one! I especially liked the sprinkles edit. Must have taken a while for that half second. One question. I could probably figure this out if I played around with it, but thinking about making a tree with some girth to it. I suppose simplest would be just starting with a high strokeWeight and then reducing it as you go out. Not sure how much it would look like a real tree though.

    • @BarneyCodes
      @BarneyCodes  Před rokem +3

      Thanks Steve, very kind! I'm enjoying being a bit more creative with the edits at the moment, glad someone appreciates the sprinkles, they were a bit labour intensive!
      That's a great question, and one I'm trying to figure out as well! I had a very similar thought to you, but the two issues I can see would be first, knowing the initial stroke weight (I think you could just do a pre-render pass on the final string of characters to figure it out, but just seems a bit "finicky". Maybe you could just use the number of generations to know the beginning stroke weight? Might have to do some experimentation) and secondly, the transitions between different stroke weights might be a bit clunky.
      I would love to figure out a way to generate a polygon of the L System, but I think it'll take some serious thought to navigate given the recursive nature of the L System!
      If you have any ideas, I'd love to discuss them!

    • @StevesMakerspace
      @StevesMakerspace Před rokem +2

      @@BarneyCodes Got it.

    • @duncancarr7822
      @duncancarr7822 Před rokem +2

      @@StevesMakerspace Just start off with a thickness "1.00". Then reduce this thickness by a factor "0.95" each iteration (for example). Then it'll never disappear, as it's reducing by a percentage. You just need a starting value (float) and a multiplier (float). Hope this helps.

    • @BarneyCodes
      @BarneyCodes  Před rokem +2

      That's a great idea! I think you could probably also draw a trapezoid instead of a line that reduces to the next thickness at its end to create smoother transitions between the thicknesses

    • @duncancarr7822
      @duncancarr7822 Před rokem +2

      @@BarneyCodes Awesome! That's a great idea - I guess it will be a lot more complicated than a line. Maybe there's are "transformation" that can be applied (a matrix) to to "shape" that would adjust the box and squish the top, but not the bottom. I don't know if this is possible? I know it is in possible Postscript.

  • @annalisa-amadi
    @annalisa-amadi Před rokem +1

    How can the user edit the strings from an input box without going into the code?

    • @BarneyCodes
      @BarneyCodes  Před rokem +1

      That's a great question! If you check out the createInput function (p5js.org/reference/#/p5/createInput) you can easily make a text box for your sketch, and can give it a default value too!
      You can then read the value of the input using input.value().
      Hope that helps, let me know if you've got any other questions!

  • @Mablemb
    @Mablemb Před rokem +1

    What do you use to generate the images?

    • @BarneyCodes
      @BarneyCodes  Před rokem +1

      All of these images were generated using the code linked in the description. I'm using a library called P5js which builds on top of the JavaScript canvas.
      If you follow the link in the description you can run the code for yourself in the browser and generate your own images!
      Hope that helps!

  • @pedrosuarez544
    @pedrosuarez544 Před rokem +2

    Can the game of life emulate another game of life with other rules than the first?

    • @BarneyCodes
      @BarneyCodes  Před rokem +2

      Hey! I replied with more detail on your other comment, but yes, you can change the rules to be for any cellular automata :)