Koch flake anyone?
Moderators: MtnViewJohn, chris, mtnviewmark
Koch flake anyone?
I'm racking my brain on how to create a Koch snowflake (or just one side)... anyone have any examples/suggestions?
The problem with creating a Kich snowflask or other such fractals is that you can't have the recursion "bottom out" and just draw a line or some other primitive. This is by design (as I understand it) since the language in context free and the rules aren't allowed to know things like what recursion level they are at or any contextual information like that when they're invoked.
Ironically, this is really the only way to draw a "true" Koch snowflake, since it should never bottom out, but just keep going down more levels. But you can't really draw it like you'd want to. You can leave a trail of primitive "footprints", though, like MtnViewMark did in his version of Serpinki's Triangle
Ironically, this is really the only way to draw a "true" Koch snowflake, since it should never bottom out, but just keep going down more levels. But you can't really draw it like you'd want to. You can leave a trail of primitive "footprints", though, like MtnViewMark did in his version of Serpinki's Triangle
- MtnViewJohn
- Site Admin
- Posts: 882
- Joined: Fri May 06, 2005 2:26 pm
- Location: Mountain View, California
- Contact:
Nevertheless, some of us are suckers for pain.MtnViewJohn wrote:Koch triangles and other fractals are L-systems. Context Free was not architected to create L-systems.
Code: Select all
startshape snowflake
rule snowflake {
triangle { r 180 s 1.154701}
kochedgetrans {}
kochedgetrans { r 120 }
kochedgetrans { r -120 }
}
rule kochedgetrans {
kochedge { y .288675 }
}
rule kochedge {
triangle {s .38490 y .09622}
kochedge {
y 0.14433
x -0.08333
s 0.33333
r 60
}
kochedge {
y 0.14433
x 0.08333
s 0.33333
r -60
}
kochedge {
s 0.33333
x -0.33333
}
kochedge {
s 0.33333
x 0.33333
}
}
rule triangle {
meta_TRIANGLE{ s .25}
}
rule meta_TRIANGLE{
TRI{}
TRI{r 120}
TRI{r -120}
}
rule TRI{
SQUARE{x -0.183013 y 0.683013 r -30 }
SQUARE{x 0.183013 y 0.683013 r 30 }
TRI{y 1.1547 s 0.42265 }
}
-
- Posts: 21
- Joined: Wed Jul 06, 2005 4:53 pm
Or, if you don't like work
I took a quick and dirty way of making a kinda mod/deco triangle, and used that to make a quick and dirty Koch.
God, I'm lazy.
God, I'm lazy.
Code: Select all
startshape BUD
rule TRIANGLE {
LINE{}
TRIANGLE {y 1 s .9}
}
rule LINE {
CIRCLE {x 5 s 2}
CIRCLE {x -5 s 2}
LINE {s .9}
}
rule BUD {
TRIANGLE{}
BUD {x -3 y 4 r 65 s .5}
BUD {x 3 y 4 r -65 s .5}
}
Koch Snowflake
Here's a very simple (terminating) Koch snowflake grammar:
You can remove all but one of those recursive snowflake lines (your choice) and add "snowflake { r 60 }" and it will still draw a correct Koch snowflake, but it won't terminate — it will overdraw the figure ad infinitum.
Enjoy,
Justin Knoll
Code: Select all
startshape snowflake
rule snowflake {
TRIANGLE { }
snowflake { x .3333 y 0.1924 s 0.3333 }
snowflake { x -0.3333 y 0.1924 s 0.3333 }
snowflake { y -0.3849 s 0.3333 }
snowflake { x 0.3333 y -0.1924 s 0.3333 }
snowflake { x -0.3333 y -0.1924 s 0.3333 }
snowflake { y 0.3849 s 0.3333 }
}
Enjoy,
Justin Knoll
Simple Koch
I apologize for resurectting a long dead conversation, but I didn't see the harm in this case, and I couldn't help myself... I saw this page looking for algorithms to draw a Koch flake/island with...
And I came up with this code:
Now, I admit that this is not a fully TRUE Koch flake, and it actually renders more prims than the above by aaronstj, but it is really simple code..
Here it is in a "debugging" mode to demonstrate the reasons why it isn't a true koch.
I just noticed that my code creates close to the same grammar as J's example just above. (Only a difference between "y 0.385" and "y 0.3849" and how many decimals 1/3 is approximated to...) Funny, since I had not seen this article before I created the code!
And I came up with this code:
Code: Select all
startshape SNOWFLAKE
background { b -1 }
rule SNOWFLAKE {
TRIANGLE { b 1 }
6 * { r 60 }
SNOWFLAKE {
size .333333333333333333333
y 0.385
}
}
Here it is in a "debugging" mode to demonstrate the reasons why it isn't a true koch.
Code: Select all
startshape SNOWFLAKE
background { b -1 }
rule SNOWFLAKE {
TRIANGLE { b .2}
6 * { r 60 }
SNOWFLAKE {
size .333333333333333333333
y 0.385
b +.2
}
}
Ricky