Tunnel
Recursive viewport scaling and rotating

Inspired by Päivi Julin.
Sample generated images:



library(grid)
## Number of frames
N <- 500
## Number of colors
k <- 100
## N/k is number of times color palette will repeat
## Some sample colors
colors <- rep(rainbow(k, s=0.8), N/k)
#colors <- rep(colorRampPalette(c('orange','yellow', 'darkorange'))(k), N/k)
#colors <- rep(colorRampPalette(c('white', 'pink', 'white', 'lightblue', 'white'))(k), N/k)
#colors <- colorRampPalette(c('beige', 'forestgreen', 'darkgreen'))(N)
## Draw background
dev.new()
pushViewport(viewport(width=1, height=1, angle=0))
grid.rect(gp = gpar(col = NA, fill = colors[1]))
## Scale viewport and rotate
for(i in 2:N){
## Optionally try increasing the angle or increasing the scale rate
pushViewport(viewport(width=0.99, height=0.99, angle=1))
# Optionally try: grid.circle(), grid.roundedrect()
grid.rect(
# Optionally shift: x = 0, y = 1,
gp = gpar(col = NA, fill = colors[i])
)
}
