Coding Challenge #16: Fractal Trees – L-System

[ad_1]
In this third installment of my series on algorithmic botany, I discuss L-systems and how they can be used to generate tree and other fractal patterns in p5.js.

Support this channel on Patreon:

Send me your questions and coding challenges!

Contact:

Links discussed in this video:
Nature of Code class on Kadenze:
Algorithmic Botany:

Source Code for the Video Lessons:

p5.js:
Processing:

For More Coding Challenges:

Help us caption & translate this video!


Posted

in

by

Tags:

Comments

20 responses to “Coding Challenge #16: Fractal Trees – L-System”

  1. Markus Nilssen Avatar

    You're an amazing human being

  2. Stefan van der Heijden Avatar

    As said before, the Bob Ross of coding

  3. Annie Avatar

    Trees should be green, not WHITE dude!!!!

  4. Valen Avatar

    PLEASE do the animated OOP tree with springs and stuff

  5. Jonathan David Layne Stribling Avatar

    WOW! I can't believe you implemented LOGO! I used that language as a kid. Congratulations on finding a use for it along with javascript.

  6. Simon Farre Avatar

    Pretty cool. I'm going to try and follow through with this one what I have time, but just a quick thought you may be able to answer, when you mention at ~10:30 that you should have the rules in an array, isn't it better to have the rules mapped in some associative container like data structure? So instead of
    "for every char,
    for every rule
    if char == rule.char)"

    do
    nextSentence += assoc[char] ? I dunno if this works, but it seems that it would be more efficient.
    ("hash(map) rules everything around me, unique look up dollar dollar bill yo – Wu Tang / CS nerd mixup…)

  7. Matthew Niles Avatar

    I made something so stupid with this
    For every letter that is in the P, i transform it to its phonetic pronunciation
    Ex: "XD" becomes "ECKS DEE", which then becomes "EE SEE KAY ESS DEE EE EE" and so on
    (I'm sorry, planet)

  8. Fullstack Devs Avatar

    its not word-wrapping because the sentence is one word (for those wondering) he can fix that by adding spaces between them

  9. MisterMajister Avatar

    If someone wants something like a spruce-branch:

    len = 1;
    axiom: F.
    rule: F –> FFF[-FF][+FF[xFF[yFF]F]FFF]F
    – : -45
    +: +45
    x: -90
    y: +30

  10. Alex Harrison Avatar

    I genuinely have no idea how i'd pass my uni course without your guidance!!

  11. Dor Peled Avatar

    Beautiful algorithm.

  12. Cristi Neagu Avatar

    Fun fact about Logo. Even though it was designed to teach kids how to program, it had some very advanced features. A very interesting one which you don't come across all that often is that it had the capability of executing the contents of variables. Like, you could define two variables x=5 and y="2*x+3" and you could interpret y and it would output 13. I used it to make a function plotter when i was a kid. You'd give it a function and it would plot it out for you.

  13. Olaf Wisselink Avatar

    Thanks for the video! Here are some of my experiments trying out different axioms, rulesets and colors: http://cargocollective.com/olafwisselink/Woeker

  14. eyewars Avatar

    This is like when you ask your perants for something. "Mom can I have this?" "Go ask dad" "Dad can I have this?" "Go ask mom"

  15. iOverThoughtThis Avatar

    Hey! love your videos.

    I just wanted to mention you could have clarified your rules from the beginning and avoided some complexity.

    Since you're rules match characters to strings you could just have the characters as keys in a dictionary and the strings as values. Then you can use .hasOwnProperty to check if a character matches a rule and don't need to use a loop to find the matching rule. e.g.


    var rules = {
    A: 'AB',
    B: 'A"
    };

    var current = sentence.charAt(i);
    if (rules.hasOwnProperty(current)) {
    nextSentence += rules[current];
    } else {
    nextSentence += current;
    }

    Thanks for the awesome videos!

  16. otto vosberg Avatar

    So glad I found this channel. This is a nice break from my ReactJS adventures!

  17. Gay Avatar

    marijuana algo

  18. Michael Dere Avatar

    this is cool!!! I think I would've had more fun with my CSE courses if you were my instructor lol

  19. Dilan De Silva Avatar

    great channel. keep it up!

Leave a Reply

Your email address will not be published. Required fields are marked *