## Making Simple Fractals in R

In my GHP Fractals class this summer, I opted to write my sample programs in R. I selected R because it has very nice graphing libraries and built-in complex numbers. Overall, I was pleased with R; it definitely let me built some incredibly straightforward fractal code. It’s not as fast or pretty as other choices might have been, but it highlighted the underlying math which was most important to me.

.You can see an example on the left, rendered by R. The source of this particular fractal comes from Clifford Pickover’s . The graph is made by repeatedly iterating a simple function of x and y based on sine and cosine.

You can see the code in R here:

a <- -0.966918 b <- 2.879879 c <- .765145 d <- .744728 pointsToPlot <- 100000 x <- .1 y <- .1 allXs = rep(0,pointsToPlot) allYs = rep(0,pointsToPlot) for(i in 1:pointsToPlot) { newx <- sin(y*b) + c*sin(x*b) newy <- sin(x*a) + d*sin(y*a) x <- newx y <- newy allXs[i] <- x allYs[i] <- y } plot(allXs, allYs, pch=".", col="red", main="Strange Attractor: King's Dream")

Here’s a few more pretty pictures: