MORE 3D L systems! Exciting stuff, right? This time, the focus was all about trying to make more sophisticated L systems as opposed to changing the code around. This consisted of two main changes: now, I can put stuff like (3)F into the system, which is interpreted as "go forward 3 times the normal amount. This also works with angles. The second change is related: now I can make rules like rule: (x)F -> (x*1.2)F, which means "change all the "blank" F's so that they are going 1.2 times as far as they did before. Clever readers (so, probably anyone who is reading this) will note that with multiple iterations in the L system, this effect will stack. That is, if your initial X is 5, and your rule is (x*2)F, then after 3 iterations you will be going forward 40 times! Wow!
The downside of this is that it is not consistent with my old super-cool dictionary based way of implementing rules. So I had to replace a lot of things with how I was supposed to be doing it all along. Sigh. BUT thats okay, and also brings me to my first extension:
Most of the things I did for this lab are more code based and aren't noticeable in the final product. So, to make up for losing my dictionary based system builder, I made a dictionary based string interpreter! The old was of interpreting strings was a LONG LONG LONG list of elif statements, which is super ugly. It was probably 50-100 lines. Here is the new interpreter (or the equivalent part of it):
if char in self.dict:
That's it! Two lines. I created a dictionary (self.dict) in the init function of the builder pairs each character with its associated function. Then, I had to go through and make sure each function required no arguments besides self (otherwise the code would be like self.dict[char](variable)), which is problematic since the variable is dependent on the character). Obviously this required lots of things like self.width and self.angle, and the init function is rather cluttered now.
This method doesn't seem to be any quicker, but I like it for one main reason: with lots of elif statements, I feel like the code is going like "Do I have an F? No? Well is it a ?[? How about a R?" whereas with the dictionary method, the code knows what character it has and goes straight to the associated definition. So I guess this whole thing was more of a proof of concept because it doesn't actually change the product at all.
OH AND I ALMOST FORGOT: I also made several more methods for drawing lines. There are five methods in total:
1) The normal method. It draws a line.
2) Jitter: draws a line with the endpoints offset from the normal endpoints in 3 dimensions.
3) Jitter 3: draws THREE lines with all the endpoints offset
4) Jitter ULTRA: Draws lines in a a circular arrangement around the original line
5) Jitter Circle: Draws a circle perpendicular to the direction of the normal line.
Here are some examples, using my fancy stick cube
Clockwise from bottomleft: Normal, jitter, Jitter3, jitter circ, jitter ULTRA. Jitter ultra is my favorite.
Here are some more shapes with the same things:
AND WHAT'S THAT I SEE? A tetrahedron! Yes, with the new methods, it is now easy to draw a tetrahedron despite the crazy dihedral angle.
Here's the seen from last time revisted, now with a third wall:
I used the jitter technique on the wall paper. Wild stuff, when paired with fill.
OKay. Trees. I made a new L system for an "oak" tree. This tree is SUPER sophisticated in that each rules has multiple options, and the angles and everything is all modified. I also made different rules for the main stem and for the branches. The main stem branches at a wider angles than the branches, and starts with an initial "stump". Furthermore, I made a rule thats like:
(x)F -> (x*1.0)F(x*0.8)F
This means that the distance between branches towards the top will be smaller than at the bottom (see? that's why I talked about stacking at the beginning). This creates a somewhat "pleasant" shape to the tree.
Here it is:
Here it is in a forest (these are all the same system: check out the stochasicity!):
Here is what the tree looks like when draw with jitter Ultra:
Nothing. Jitter ultra is super computationally intense and it takes like a year for it to draw and I need to graduate so I can't just sit around waiting for it to render. Sorry.
Oh, Okay, here it is:
Yeah its kinda worth it I suppose.
So my extensions were:
Making an extra draw method or two
Making a tetrahedron
making my tree l system do lots of cool things and look real perdy.
And using dictionaries to interpret my l systems.
I didn't work with anyone, but the last grader gave me the idea to use dictionaries in string interpreter.
The server was down this morning for about 12 or 13 minutes which is why this is about 18 hours late.