Just in case: L-systems

In its simplest form, the formula is substituted in the axiom N times, where N is equal to the number of iterations. It turns out a long tape, on which construction takes place. The problem is that the size of the final "fractal" can vary quite seriously. I see only one way to fit the result into the viewport: build twice. The first time is to find out the maximum boundaries, the second one is to build with an adjusted length.

Is there a smarter way?

UPD:

Work example:
Angle π / 3 Axiom F
F-F ++ FF substitution
This is the Koch curve.

Iterations

  1. F-F ++ FF length 3F (since -F ++ F gives only half of its length due to rotation)
  2. F-F + + FF - F-F + + FF + + F-F + + FF - F-F + + FF length 9F
  3. length 27F well and so on

It's all easy. But there are formulas with branching or multilevel substitutions through other variables. Here it is already more difficult.

  • I am even satisfied with the answer "is / no." :) - knes
  • Hmm, why not build the result completely, calculate the bounding box, and then, when outputting the calculated result, bring the coordinates to the desired interval? Therefore, we count only once. Or memorize all the calculated points is more expensive than counting again? If so, then there really is no better way than double counting. - VladD
  • @VladD, because it is built as it moves along the tape. Or recursively (then generally seams). To store the coordinates is much more expensive than a tape: in a tape a stick is one letter, sometimes a letter and several pluses. Coordinates - minimum (1: 2) (3: 4) 10 bytes, and if with a floating point - all 30. - knes

1 answer 1

A little bit of formulas - like "is".

  • I have not read it yet, I have to fight there. In the evening I stop. - knes
  • heck. from Google immediately pdf opened. from here page. In general, you do not need to register, you need to "no, thanks" and click on the right view and immediately download. - Yura Ivanov