Previous | Next Fractal snowflake Home ▸ Documentation ▸ Smile ▸ The graphic library ▸ Samples ▸ Fractal snowflake
 The snow flake is obtained by iterating a process where each line segment is replaced by a broken line of four segments, each long by 1/3 of the original one's length. Here the original figure was an equilateral triangle. The script demonstrates a method that you can use to speed the generation of long polygons. Instead of using the standard LineTo, use the primitive addstr on a batch of points as shown in the script. Import script property s : {} on DrawSnowflakeLoop(a, b, n)     global xmlgk     if (n > 0) then         set {x1, y1} to a         set {x2, y2} to b         set {dx, dy} to {(x2 - x1) / 3, (y2 - y1) / 3}         set c to {x1 + dx, y1 + dy}         DrawSnowflakeLoop(a, c, n - 1)         set {dx2, dy2} to {dx / 2 - (sqrt 3) / 2 * dy, (sqrt 3) / 2 * dx + dy / 2}         set d to {x1 + dx + dx2, y1 + dy + dy2}         DrawSnowflakeLoop(c, d, n - 1)         set c to {x1 + 2 * dx, y1 + 2 * dy}         DrawSnowflakeLoop(d, c, n - 1)         DrawSnowflakeLoop(c, b, n - 1)     else         set s to s & b         if (count s) > 1000 then             tell xmlgk to AddPath("L " & (printf parameters s))             set s to b         end if     end if end DrawSnowflakeLoop on DrawIt(a, b, n)     global xmlgk     set s to {}     DrawSnowflakeLoop(a, b, n)     tell xmlgk to AddPath("L " & (printf parameters s)) end DrawIt set i1 to 20 set i2 to 350 set j to 120 set a to {i1, j} set b to {i2, j} set c to {(i1 + i2) / 2, j + (i2 - i1) * (cos pi / 6)} set t to {c, a, b, c} set w to 0 repeat with n_steps from 1 to 5     set w to BeginFigure(w)     SetPenWidth(0.5)     SetPenColor({0, 0, 0.8, 1})     repeat with i from 2 to 4         MoveTo(item i of t)         DrawIt(item i of t, item (i - 1) of t, n_steps)     end repeat     DrawPath(2)     EndFigure()     smilepause 0.2 end repeat