library(knitr)
library(rgl)
knit_hooks$set(webgl = hook_webgl)
gasket3d <- function(n=100000) {
    m <- diag(0.5, 3)       # 反復関数系
    lst <- matrix(0, n, 3)  # リストを用意

    prb <- sample(1:4,n,rep=TRUE)
    for(i in 2:n) {
        lst[i,] <- switch(prb[i],
                          m %*% lst[i-1,] + c(0,0,0),
                          m %*% lst[i-1,] + c(60,0,0),
                          m %*% lst[i-1,] + c(30,60,0),
                          m %*% lst[i-1,] + c(30,30,60))
        }
col <- c("#00A0E9", "#E60012", "#1E2C5C", "#910000") # 4色

    plot3d(lst, pch=".",axes=F,col=col[prb],xlab="",ylab="",zlab="")
#    .anime = rgl::spin3d(axis=c(0, 1, 0), rpm=15) # クルクル回る
#   rgl::play3d(.anime)
}
gasket3d()

plotsnapshot
You must enable Javascript to view this page properly.