[R] animations?
Bill Simpson
wsi at gcal.ac.uk
Fri Nov 30 10:03:13 CET 2001
Here's an example.
- down() generates a 21 frame movie of drifting sinewave in noise
down<-function(con=1, fy=5,sd=0)
{
x<-1:100
y<-1:100
xn<-length(x)
yn<-length(y)
xc<-xn/2
yc<-yn/2
sigx<-xn/5
sigy<-yn/5
m<-length(x)*length(y)
par(mar=c(0,0,0,0))
for(i in 0:20) #21 frames
{
#contrast waveform
f0<-function(x,y)
{
( (x-xc)^2 +(y-yc)^2 < (sigx*2.5)^2)*
exp(-1/2*((x-xc)/sigx)^2 - 1/2*((y-yc)/sigy)^2) *
con*cos(2*pi*fy*(y-yc)/yn + i*.299)
}
noise<-rnorm(m,0,sd)
#noise truncated at +/- 2.5 SDs
noise[noise>2.5*sd]<-2.5*sd
noise[noise< -2.5*sd]<- -2.5*sd
z0<-outer(x,y,f0)+noise
image(x,y,z0, col=gray(0:63/63), axes=FALSE,ann=FALSE,zlim=c(-1,1))
if(i<10)
filename<-paste("~/papers/helle/paper1/talk/movie/fig0", i, ".jpg",
sep = "")
else
filename<-paste("~/papers/helle/paper1/talk/movie/fig", i, ".jpg",
sep = "")
dev.print(device=jpeg,width=240,height=240,file=filename)
}
}
# then at bash prompt, do:
# convert -delay 0 -loop 500 fig*.jpg movie.gif
# I find that jpeg makes much faster movies than png
- convert is from ImageMagick
Bill
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list