Using R and PhotoScape to make sine wave animation


for (i in 1:30){
  x=seq(-5*pi+i-1.6,-3*pi+i-1.6,by=.02)
  y=sin(x)
  png(paste0(i,".png"),width=640,height = 400)
  plot(x,y,xlim=c(-3*pi,3*pi),type="l" ,ann=F,lwd=2,col="red")
  abline(h=0)
  dev.off()
}

for(i in 1:30) file.copy(from=paste0(getwd(),"/",i,".png"),to=paste0(getwd(),"/",61-i,".png"),overwrite = T)

for (i in 1:30){ 
x=seq(-6*pi,-4*pi,by=.02)
y=sin(x)
png(paste0(i,".png"),width=640,height = 400)
plot(x+i,y,xlim=c(-3*pi,3*pi),type="l" ,ann=F,lwd=2,col="blue")
abline(h=0)
dev.off()
}

for(i in 1:30) file.copy(from=paste0(getwd(),"/",i,".png"),to=paste0(getwd(),"/",61-i,".png"),overwrite = T)

這個網誌中的熱門文章

Python: character sort