```
cantorset <- function(n = 1000, p = 3, add = F){
newpoint <- function(old){
new <- old/p
new <- new + rbinom(1,1,.5)*(1 - 1/p)
return(new)
}
if(!add){
plot.new()
abline(v = c(0,1))
}
newpnt = 0
for(i in 1:n){
newpnt = rbind(newpoint(newpnt[1]),newpnt)
}
abline(v = newpnt)
}
triangle <- function(n = 100, probLR = 1/3, probUM = 1/3, axis = T, add = F){
newpoint <- function(old){
new <- old/2
tmp <- runif(1)
add <- c(0,0)
if(tmp < probLR){
add <- c(.5,0)
}else if(tmp < (probLR + probUM)){
add <- c(.25,.5)
}
new <- new + add
return(new)
}
if(!add){
plot.new()
if(axis){
abline(v = c(0,1))
abline(h = c(0,1))
}
}
newpnt = matrix(c(0,0),nrow=1)
for(i in 1:n){
newpnt = rbind( newpoint(newpnt[1,]),newpnt)
}
points(newpnt[,1],newpnt[,2],pch=".")
}
sponge <- function(n = 100, add = F){
newpoint <- function(old){
new <- old/3
tmp <- runif(1)
add <- c(0,0)
if(tmp < 1/8){
add <- c(1/3,0)
}else if(tmp < 2/8){
add <- c(2/3,0)
}else if(tmp < 3/8){
add <- c(0,1/3)
}else if(tmp < 4/8){
add <- c(2/3,1/3)
}else if(tmp < 5/8){
add <- c(0,2/3)
}else if(tmp < 6/8){
add <- c(1/3,2/3)
}else if(tmp < 7/8){
add <- c(2/3,2/3)
}
new <- new + add
return(new)
}
if(!add){
plot.new()
abline(v = c(0,1))
abline(h = c(0,1))
}
newpnt = matrix(c(0,0),nrow=1)
for(i in 1:n){
newpnt = rbind( newpoint(newpnt[1,]),newpnt)
}
points(newpnt[,1],newpnt[,2],pch=".")
}
mapleleaf <- function(n = 100, add = F){
newpoint <- function(old){
new <- old
x <- old[1]
y <- old[2]
pars <- double(6)
tmp <- runif(1)
if(tmp < 1/4){
pars <- c(.14,.01,0,.51,-.08,-1.31)
}else if(tmp < 2/4){
pars <- c(.43,.52,-.45,.5,1.49,-.75)
}else if(tmp < 3/4){
pars <- c(.45,-.49,.47,.47,-1.62,-.74)
}else{
pars <- c(.49,0,0,.51,.02,1.62)
}
new[1] <- pars[1]*x+pars[2]*y+pars[5]
new[2] <- pars[3]*x+pars[4]*y+pars[6]
return(new)
}
if(!add){
plot.new()
abline(v = c(0,1))
abline(h = c(0,1))
}
newpnt = matrix(c(0,0),nrow=1)
for(i in 1:n){
newpnt = rbind( newpoint(newpnt[1,]),newpnt)
}
newpnt = (newpnt+3.5)/7
points(newpnt[,1],newpnt[,2],pch=".")
}
fern <- function(n = 100, add = F){
newpoint <- function(old){
new <- old
x <- old[1]
y <- old[2]
pars <- double(6)
tmp <- runif(1)
if(tmp < .01){
pars <- c(0,0,0,.16,0,0)
}else if(tmp < .08){
pars <- c(.2,-.26,.23,.22,0,1.6)
}else if(tmp < .15){
pars <- c(-.15,.28,.26,.24,0,.44,.07)
}else{
pars <- c(.85,.04,-.04,.85,0,1.6)
}
new[1] <- pars[1]*x+pars[2]*y+pars[5]
new[2] <- pars[3]*x+pars[4]*y+pars[6]
return(new)
}
if(!add){
plot.new()
abline(v = c(0,1))
abline(h = c(0,1))
}
newpnt = matrix(c(0,0),nrow=1)
for(i in 1:n){
newpnt = rbind( newpoint(newpnt[1,]),newpnt)
}
# Fit to screen
newpnt[,1] <- (newpnt[,1] + 3)/7
newpnt[,2] <- (newpnt[,2])/10.3
points(newpnt[,1],newpnt[,2],pch=".")
}
bufferedIFS <- function(func, total = 10000, buffer = 1000, add = F, ...){
if(!add){
func(buffer,...)
}
n <- total/buffer
for(i in 1:n){
func(buffer, add = T,...)
}
}
```