I was looking at the wikipedia page for the Koch Snowflake (here) and was bothered by the all the examples all being in the logo/turtle style. So i set out to make my own that returned a list or coordinates.
My implementation is in python and i basically ripped off the python turtle implementation but replaced the turtle specific stuff with basic trig. It resulted in some ugly code. My challenge for you is to either improve my code or come up with a more elligant solution of your own. It can be in python, or your favorite language.
My Code:
from math import sin, cos, radians
def grow(steps, length = 200, startPos = (0,0)):
angle = 0
try:
jump = float(length) / (3 ** steps)
except:
jump = length
set="F"
for i in xrange(steps): set=set.replace("F", "FLFRFLF")
coords = [startPos]
for move in set:
if move is "F":
coords.append(
(coords[-1][0] + jump * cos(angle),
coords[-1][1] + jump * sin(angle)))
if move is "L":
angle += radians(60)
if move is "R":
angle -= radians(120)
return coords
EDIT: due to lazy copying, i forgot the import