Fractals
From GenerativeArt
(Difference between revisions)
:<var>N! = N * (N - 1) * (N - 2) * ... * 1</var> | :<var>N! = N * (N - 1) * (N - 2) * ... * 1</var> | ||
- | ===== | + | =====Non-recursive factorial function===== |
'''function''' FACTORIAL(m) | '''function''' FACTORIAL(m) | ||
total = 1 | total = 1 | ||
'''return''' total | '''return''' total | ||
- | ===== | + | =====Recursive factorial function===== |
'''function''' FACTORIAL(m) | '''function''' FACTORIAL(m) | ||
'''if''' m > 1 | '''if''' m > 1 | ||
'''return''' 1 | '''return''' 1 | ||
'''end''' | '''end''' | ||
+ | |||
+ | =====Recursive Koch Curve===== | ||
+ | koch curve image here | ||
+ | // Given: | ||
+ | // DRAW(x1, y1, x2, y2) :draws a point from (x1, y1) to (x2, y2) | ||
+ | // res :length of smallest line to be drawn | ||
+ | // DIST(x1, y1, x2, y2) :distance between points (x1, y1) and (x2, y2) | ||
+ | <br> | ||
+ | '''function''' KOCH(x1, y1, x2, y2, res) | ||
+ | '''if''' DIST(x1, y1, x2, y2) < res | ||
+ | DRAW(x1, y1, x2, y2) | ||
+ | '''else''' | ||
+ | // calculate new set of line segments tx1, ty1, tx2, ty2, ..., tx5, ty5 | ||
+ | KOCH(tx1, ty1, tx2, ty2, res) | ||
+ | KOCH(tx2, ty2, tx3, ty3, res) | ||
+ | KOCH(tx3, ty3, tx4, ty4, res) | ||
+ | KOCH(tx4, ty4, tx5, ty5, res) | ||
+ | '''endif''' | ||
+ | image of koch line calculation here |