# Fractal Stars # # Change the fstar() call to get different effects. link graphics procedure main() WOpen("size=370,370") | stop("*** cannot open window") # fstar(20, 165, 330, 5, 5, 0.35, 4 * &pi / 5) # five-sided figure fstar(20, 245, 330, 4, 8, 0.47, &pi / 2) # square figure WDone() end # Draw a fractal star with the specified number of vertices, phases, # radius ratio, and angular increment. The parameter extent determines # the "diameter" of the star; x and y are used to position the # figure in the window. procedure fstar(x, y, extent, vertices, phases, ratio, incr) local theta, xprev, yprev, resid, factors, length, i theta := 0 # starting angle every i := 0 to vertices * (vertices - 1) ^ (phases - 1) do { resid := i # residual after division factors := 0 # number of factors # divide and count until (resid % (vertices - 1) ~= 0) | (factors >= (phases - 1)) do { resid /:= (vertices - 1) factors +:= 1 } length := extent * ratio ^ (phases - factors - 1) x +:= length * cos(theta) # end position y +:= length * sin(theta) if i > 0 then # skip first point DrawLine(xprev, yprev, x, y) xprev := x # update previous position yprev := y theta +:= incr } return end