Describe your fractal:
Lindenmayer systems (L-systems) use symbols, which are single characters - on this website you can use A-Z, 1-9, and punctuation.
The most important part of an L-system is its rules, for example A=>BCD or B=>BB These rules say to replace A (the starting symbol) with BCD (the result) and to replace B with BB. A rule must have exactly one starting symbol, and 0 or more symbols in the result. The computer uses these rules to generate successive iterations of the L-systems's output.
The zero-th iteration is called the axiom, and is normally just 1 or 2 symbols (but never 0). To generate the first iteration, the computer reads through the zero-th one, and looks at each symbol. If there's a rule which starts with that symbol, then it replaces the symbol with that rule's result, otherwise it leaves the symbol where it is. For example, if the axiom was AB and our rules were D=>EF and B=>DC, then the first iteration would be ADC, since there aren't any rules that start with A, so the A in the axiom is in the same place in the first iteration, but there is a rule for the B, B=>DC, so the first iteration is ADC instead of AB.
The computer uses this same process to generate the second iteration from the first, and so on. Here's a diagram showing the process in detail for a couple of iterations:
| # | Iteration | |||
|---|---|---|---|---|
| 0 (Axiom) | A | B | ||
| 1 | A | D | C | |
| 2 | A | E | F | C |
| ⋮ | ⋮ | |||
The grey lines show a symbol that isn't replaced by a rule, the violet shows the rule D=>EF, and the light blue B=>DC
- Letter
- means
- F,G
- both draw a straight line one step forwards
- +,-
- turn right/left by degrees
- X,Y
- turn right/left by the same angle as above. (Note these extra direction commands are useful to align all the iterations the same way TODO better)
- [
- save position and heading (TODO step length??) to a stack, so
F[+F]Fwould draw 1 step forwards, draw one step to the right, and then return to the end of the first line and draw 1 step parallel to the first line. - ]
- restore the last saved position and heading
Use the table below to set up drawing rules for each symbol you've used. If you don't provide an entry for a symbol, it will be assumed that it has no effect on the drawing. (e.g. the symbol X in the Dragon Curve [wikipedia])
In the editors below, you should write the body of a function that draws what the corresponding symbol represents. For example, the code that goes where the comment is below:
Methods available on state:
There are 2 sets of commands available. The simpler works like the turtle drawing system:
You can draw or move forward 1 step, adjust the step by a multiplicative factor, turn left or right by an angle, or push/pop (save, restore respectively) the current state (incl position, angle and step). Angles are in degrees.
And the more advanced set exposes most of the relative SVG commands:
These commands do not use or change any state, so you'll need to pass in the stored angle (from angle()) or step(), for example). Also, you can store whatever state you like in the state dictionary. (Note that the basic commands refer to state["angle"] and state["step"], if you want to mix and match between command sets).
Note 'z' has not been implemented because the drawn output is supposed to be a line, not a closed shape. In addition, the lineA and moveA commands have been added to save trig calculations.
Please refer to the MDN documentation on SVGs to learn about the SVG commands available.
Warning: the code in the table will be run on your computer in this browser tab. I have taken no security precautions, so you could be vulnerable to XSS, for example. Check the code below carefully if you didn't write it.
| Symbol | Function |
|---|
F for a line, or a non-drawing characterA>B+C-D..., mapping 1 letter to 0 or more other ones (so for the placeholder example + and - will always stay the same). If you don't include a letter then the program will assume it will stay the same.Turning it 3D
Given that a F command draws a line long (as set below), a F command on the layer below will scaled down by the fractal's scale factor (as set above), and would a produce a line long.
Based off the drawn previews above, a first-layer line length of will produce a model around on the XY plane.
As you can see in the diagram below, your chosen settings result in a model tall.
on first layer
Means that the very top layer and the very bottom layer are extended up and down (resp.) by . This helps ensure the top and bottom aren't too fragile, and at the bottom can help ensure the model sticks to the printer bed.
Curving works by drawing a circle at each corner and folllowing that to produce a smooth curve. The percentage above controls how much, on each end, of a line can be used for that curve.
The blue line is the final curve, and the dotted lines are the construction lines, including the the parts of the lines that originally met at a sharp point.
When a line on one level and the line it projects from the on the previous are parallel, instead of filling this trapezium in, make a hole instead.
The outer trapeziums are the spaces available for the hole, and the shaded section is the bit that would be solid.