I am playing with fractals, and drawing them with Python turtle

I am using this rules to create l-string for my koch fractal:

begin: f
f -> f+f--f+f

In here, f means go forward by a fixed length, - means turn right for 60 degrees, + means turn right for 60 degrees.

What I am trying to do is, calculate the value of fixed length in order for final fractal to have the same width, regardless of level of complexity of my fractal.

I can use length or the string or number of recursion that is used to create l-string.

I have tried dividing a fixed number with length of string or diving it for length of string to the power 3 (don't ask why, I just tried if it would work).

Bonus Points: Can you show me how to generalize the solution for other types of fractals?

  • $\begingroup$ At each recursion level, divide the step length by 3. This is because f+f--f+f essentially moves by 3f (the gap in the middle and the two "detour" steps form an equilateral triangle) $\endgroup$ – Hagen von Eitzen Jul 11 '14 at 20:26
  • $\begingroup$ @HagenvonEitzen So, step / 3 ^ depth? $\endgroup$ – yasar Jul 11 '14 at 20:33

The first four iterations.

An intuitive approach:

Take $f$ to be the fixed movement amount you refer to in your question. Observe the first four iterations of the fractal above (apologies for the slightly stretched image). Clearly, the width of the first iteration is your step length, $f$. It is also clear that the width of the second iteration is $3f$ (since the new "triangles" formed are equilateral). You can use this observation$-$that the four lines which replace each old line in successive iterations "span" three of your new $f-$ to easily also observe that the third iteration will be $9f$ wide and that the fourth iteration will be $27f$ wide. Since you understand this trend and why it is occurring, you can conclude that the general formula for the width of the $n$th iteration is $w=3^{n-1}f$. Since we want constant $w$ by modifying $f$ depending on $n$, we can rearrange to find $f$ as a function of $n$. We have $f(n)=\frac{w}{3^{n-1}}$. So, to maintain constant width, we must divide $f$ by 3 upon every successive iteration.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.