メモ

  • Rで動画
  • 掲載図のようなウェブページもできれば、以下のような動画埋め込みPDF(こちら)も
convert hoge.gif hoge.mpeg
library(animation)
library(fields) # for tim.colors
library(caTools) # for write.gif
munit<-30 # 解像度指定 (30は重い、20くらいが適当)
m = munit^2 # grid size
C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), imag=rep(seq(-1.2,1.2, length.out=m), m ) )
C = matrix(C,m,m)

Z =0.1 # z(n+1)=z(n)^2+Cのz
K<-20 # 漸化式の「漸化」回数(gifアニメの枚数)
X = array(0, c(m,m,K))
for (k in 1:K) {
#X = array(0, c(m,m,20))
#for (k in 1:20) {
Z = Z^2+C
X[,,k] = exp(-abs(Z))
}

#image(X[,,K], col=tim.colors(256)) # show final image in R



## set some options first
oopt = ani.options(interval = 0.2, nmax = 10)
for(i in 1:length(X)){
	image(X[,,i], col=tim.colors(256))
	ani.pause()   ## pause for a while ('interval')
}
ani.options(oopt)
## see ?ani.record for an alternative way to set up an
#   animation

### 2. Animations in HTML pages ###
saveHTML({
    ani.options(interval = 0.05, nmax = 30)
    par(mar = c(3, 3, 2, 0.5), mgp = c(2, 0.5, 0), tcl = -0.3, 
        cex.axis = 0.8, cex.lab = 0.8, cex.main = 1)
for(i in 1:K){
	image(X[,,i], col=tim.colors(256))
	ani.pause()   ## pause for a while ('interval')
}
}
)



### 3. GIF animations ###
saveGIF({
    ani.options(nmax = 30)
for(i in 1:K){
	image(X[,,i], col=tim.colors(256))
	ani.pause()   ## pause for a while ('interval')
}
}
)

### 4. Flash animations ###
saveSWF({
    par(mar = c(3, 2.5, 1, 0.2), pch = 20, mgp = c(1.5, 0.5, 
        0))
    for(i in 1:K){
	image(X[,,i], col=tim.colors(256))
	ani.pause()   ## pause for a while ('interval')
}


}, ani.dev = "pdf", ani.type = "pdf", swf.name = "buffon.swf", 
    interval = 0.1, nmax = 40, ani.height = 7, ani.width = 7)


### 5. PDF animations ###
saveLatex({
    par(mar = c(3, 3, 1, 0.5), mgp = c(2, 0.5, 0), tcl = -0.3, 
        cex.axis = 0.8, cex.lab = 0.8, cex.main = 1)
for(i in 1:K){
	image(X[,,i], col=tim.colors(256))
	ani.pause()   ## pause for a while ('interval')
}


}, img.name = "BM_plot", latex.filename = ifelse(interactive(),