>[!abstract] >A fractal that looks like a fern. ## Code ```r png("barnsley_fern.png", width=1600, height=2400, bg="transparent", res=300) n <- 1e5 x <- y <- numeric(n) for (i in 2:n) { r <- runif(1) if (r < .01) { x[i] <- 0 y[i] <- .16 * y[i-1] } else if (r < .86) { x[i] <- .85*x[i-1] + .04*y[i-1] y[i] <- -.04*x[i-1] + .85*y[i-1] + 1.6 } else if (r < .93) { x[i] <- .2*x[i-1] - .26*y[i-1] y[i] <- .23*x[i-1] + .22*y[i-1] + 1.6 } else { x[i] <- -.15*x[i-1] + .28*y[i-1] y[i] <- .26*x[i-1] + .24*y[i-1] + .44 } } plot(x, y, pch=".", col=rgb(0, runif(n, .35, .9), 0, .6), axes=FALSE, xlab="", ylab="", asp=1) dev.off() ``` ## Output ![[Barnsley Fern.png]] >[!related] >- **North** (upstream): — >- **West** (similar): — >- **East** (different): — >- **South** (downstream): — ![[idea compass.base|no-toolbar]]