 So plans are recursive, and today we're going to see how we can use something called L-Systems to generate really stick-looking plans. So my name is Sherman, and I'm from Malaysia. I literally flew halfway across the world to be here. So thank you, BankBankCon, for having me. I work in Singapore as a front-end web engineer at Vicky, where we crowdsource subtitles, so I'm super excited to get live subtitles here today. It's awesome. Sometime last year, I spent a bit of time at a recursive center if you don't know what it is. It's a programming retreat that started me learning cool stuff like L-Systems. So shout out to RC. All right, so today, we're going to talk about plans and recursion. And I'll spoiler. Plans, most of us are familiar with plans, and here are a couple of really cool plans that I recently interacted with in Singapore. Yay, plans. And recursion, if you've been programming for a while, you might be familiar with recursion in terms of functions. So good ol' Fibonacci function thing. But today, we're going to talk about recursion in its most basic form, which is repetition in a self-similar sort of way. And what that means, for example, here is a coast snowflake. It's my favorite fractal curve, and it looks like this. And the way that this is drawn is by taking a simple edge and replacing every single straight edge in this curve with another version of the curve itself, and then taking every single straight edge and replacing it with another version of that curve. And again, we put this together and we get a really cool-looking fractal. So we're going to talk about what this means in the context of plans today. Recursion also happens in nature. Most of us think of it in a very mathematical kind of sense, but there are really cool fractals that happen. For example, ferns. Ferns are one of my favorite fractal plans. Where each branch of a fern leaf here looks like a tiny little fern leaf, and every little branch in that tiny little fern leaf looks like a tiny little fern leaf, and so on and so forth. And then we have fractal broccoli. I just want to touch it, it looks so textured. Where each point on it looks like a tiny little broccoli, and a point on that looks like a tiny little broccoli. Which is really cool. Trees are also recursive. Like each branch looks like a tiny little tree, and so on and so forth. So biologists have noticed this repetitive nature in plants, especially this guy by the name of Aristide Lindenmeyer, who is gently cradling a flower plant over here. And he noticed this repetitive nature in algae cell growth. So he wanted a way to be able to describe this very succinctly, and he came out with this thing called L-Systems. So L-Systems is essentially a string rewriting system. And what it looks like is that you start off with a string that could represent a structure. For example, if you're talking about algae, like A could be a type of algae cell. And you have a set of rules. And what the rules does is that you can use it to replace parts of that string. So A gets replaced with AB, and B gets replaced with A as a way to model the evolution of growth. So what happens here is that we can iterate through it multiple times. So you start off with A, replace A with AB, and replace B with A, and AB, and B with A, and so on so forth. And what it gives us is this resulting string after four rounds of replacements. So at Tansal, this system is really great for also describing recursive patterns. And the next question is like, okay, what does strings have to do with drawing? How do you convert something that's a string into something that's visual? So what we do is that we use the string to describe steps in drawing. And what we have is that we can use symbols, let's say F or A and B, as instruction to draw a line, and then plus to rotate clockwise by a predefined angle, and negative to rotate counterclockwise by that same angle. So I'm gonna do a quick demo. Can people in the back see this? All right, okay, we good. So we have a predefined angle. We have a axiom, which is a start, which is like one straight edge. And we define the edge as F, which is draw a straight line, and I rotate negative 60, draw another line, rotate 60 and 60 again, and draw another line, rotate negative 60, and then draw a straight line. And this is what it looks like here in the first iteration of the string. And what we can do is that we can iterate this again. So we replace all instances of F with this rule over here, and that will give us the second iteration of your course snowflake edge. And we can do that again and again. It gets bigger and bigger because I have a predefined length here for each edge, but we can make it a little bit smaller so we can fit all of it in the screen, and then we can go all the way up to like, not seven, seven, seven, seven, seven, it's gonna take too long over here. All right, I'm just gonna make it a little bit, oops. And what we can have is the entire course snowflake, which is like three of these edges. So rotate F, and we have like a course snowflake described here in just like a few lines, which is pretty freaking amazing. And you can also do this with other fractal shapes, patterns that you may be familiar with. So for example, the dragon curve, this is pretty cool over here. And also like surface is triangle, which is what you might be familiar with. So yeah, L-System is great for describing recursive patterns in very simple rules. And then we come to describing plants, like how does this work for plants? So for plants, oops, spoiler. So for plants is a little bit different because we have branching structures. So just drawing lines and changing angles is not gonna cut it. Here are some examples of L-System generated plants, which are pretty, really pretty. And so we introduce two other symbols. So firstly, you need something to save your current state and another symbol to restore your safe state with these square brackets. And so here's an example of a simple binary tree, not that kind of tree. All right, so what we have here is that we have X, and X will describe your tree. And X is basically a branch, sorry, a trunk, and then you save your state with the square bracket, and then you rotate negative angle, draw a smaller tree, come back, come back here, and then draw another tree on the other side. So what happens is that when we replace it, all the X's with more X's, we can see the replacements here, you get it's a tree with trees branching out of it. And you can do this over and over again until you get like, you know, a bigger tree. So what happens is that with all the weeds that we saw just now, it's basically the same thing, they're all just like different branching structures. So for example here, this is a arrow shaped weed. I should just give these names according to what they look like, they don't really have names. Where the original structure just looks like this, and then like as you add iterations to it, you just add on more and more branches. And that gives us what we have. And there are different variations of this, for example, it's fuzzy weed, and then this twiggy weed, and then the tall seaweed thing, and like a wavy seaweed. Yes, I kind of just call it like Bob or something. So that's cool and all, but right now it's all deterministic. Every time the string gets replaced, it's replaced by the same thing. So we get the same plant over and over again. So that's not very interesting, it's not very natural. What we really want is to introduce an element of randomness. So you get a variety of plants that look like they're of the same species, but different from one another, which is like real life. So what I have here is an additional thing that you can do. So for example here, this is actually the, oops, sorry, this is a fuzzy weed, but instead of just having one rule, I have a definition for an alternative replacement for X. And that gives me a slight variation every time I draw it. There's a 50-50 chance of it going either way. And so we get like this really natural looking plant. And what we can see here, for example, this seaweed thingy, I can just take this existing replacement and then add it on and maybe make a few changes and that will give us more variation in like how it looks. So this one's not too crazy, but I could like remove things or add things and it's like even more variation there. So yeah, it's pretty cool stuff. It's adding a little bit of randomness, really makes a lot of difference. So all we've seen today is 2D drawings of weed-like plants, but we can take it further and draw more complex structures like trees or in 3D or even flowers. And this is applications in like let's say game development where I need to generate realistic-looking structures, but don't wanna like write too much code. So it's pretty cool stuff. And what really fascinates me is the fact that you can have such simple rules described like really beautiful and complex patterns and that's part of the beauty of recursion. Recursion allows you to describe infinite states with a very finite set of rules and that's pretty amazing. So I have here a couple of resources that I found really useful in learning L-Systems. This is the book on L-Systems that was also co-ordered by Lyndon Mayer. It's free and here's the article that I read on like generating plants in 3D with L-Systems and this was an inspiration for the demo app that I built today. And I also have code for this thing here and you can like write your own L-Systems. So yeah, that's it. If you think L-Systems are cool, you should come and talk to me later on or you can tweet at me and I'll tweet these slides later on today. And that's all I got. Thank you. Thank you.