L-System Algae, should I use ofNode, ofMesh or vector to store vertices?

Hi!

I’m trying to make simple 2D Algae(https://en.wikipedia.org/wiki/L-system#Example_1:_Algae). I have the function to generate the iterations/rules from which to draw. For example having A as an axiom and with 6 recursions I get the following:

ABAABABAABAABABAABABA

which should be correct as far as I know.

So now I asume I should pass that string to another function which would create the vertices from which to draw, and I’m not sure how to proceed with that.

So my first question is that should I use ofNode or ofMesh or for example vector to store the locations to where the lines should be drawn?

My second question is, that what are the exact rules how the drawing should be done, I’ve been reading that wikipedia article and can’t really figure it out. For example if the first A in the string is the middle of the screen, where should the second character in the string(B) go?

Thank you for your time, hope I wasn’t too unclear.

Hi,
you should use an ofMesh. if you just want simple lines use yourOfMeshInstance.setMode(OF_PRIMITIVE_LINES).
the ofNode is completely different and it doesn’t store vertices. It stores space transformations and it is able to nest these.
As for the L-system, there are some addons to deal with it, check ofxaddons.com

the A and B you get from the lsystem iterations are rules, like, move upwards or rotate 20 degrees or what ever. These really depend on what you are trying to do.
There’s a lot of good tutorials on youtube. In particular I remember Daniel Shiffman’s, although in processing or p5.js, the logic is quite the same.
best

Alright, thanks a lot! I’ll check those tutorials. Did some more reading about that Algae rewriting rules, so it appears that the Algae thing is supposed to represent some cell-like bacterium(Anabaena catenula) so the A and B stand for different size of rectangles. So I think I don’t need to draw any lines after all. Quote from the Algorithmic beauty of plants(page 6):

The geometric interpretation of strings applied to generate schematic images of Anabaena catenulais a very simple one. Letters of the L-system alphabet are represented graphically as shorter or longer rectangles with rounded corners. The generated structures are one-dimensional chains of rectangles, reflecting the sequence of symbols in the corresponding strings.

So yeah I think I have to now make the mesh to contain the locations for the rectangles and then draw them(probably visually not that intersting :D). Here’s also some code and pictures of the Algae, in case somebody else will end up reading this thread:

http://www.spatial-computing.org/mgs/gallery/lsystem/start

@Buoyancist I’ve worked with L-System in the past and the approach that I’ve used was indeed using ofNode and its method “getGlobalPosition”. ofNode allowed me to keep track of the previous branch, apply rotations and movements in an easy way.

I would create a yourOfMeshInstance.setMode(OF_PRIMITIVE_LINES) as Roy was suggesting and then use ofNode.
Then define a starting point, this will be an of node and from this node all the children will follow.
Then I would define a parser, that for each letter in your string defines an action that affects (or not) your mesh. For example, for the letter A you add a new segment. This could be done adding a new ofNode, that has as parent the previous branch (in case it is the first segment, the parent is the root, the first branch you’ve added). This node move forward, let’s say, 20. With ofNode you can simply call move. If you want to get the global position of where it is the node, you call getGlobalPosition, and you get a vec3 back. Add this position to your mesh, and move forward. This approach to me the more flexible. It is also a good occasion to use ofNode because it is really useful when drawing things composed by multiple objects, in examples/3d there is also the ofNode app example. In case you are interested, this is how I’ve used ofNode for L-System https://github.com/edap/ofxLSystem/blob/master/src/ofxLSTurtle.cpp#L25

If you are interested in a more immediate mode, there is this example https://github.com/bschorr/OFAnimation_Spring2015/tree/master/week_10/07_L_System by @bschorr . If you new to L-system and OF, I would definitely suggest this app (the whole course is also really good).