2
我有一个数据帧随着时间的推移,t
和x
,一个人走的x:0-520
,y:0-300
已知地图上的坐标y
创建动画与PNG背景XY图。我想创建一个人在每个t
步行的动画与背景的情节是地图。R:使用saveVideo()和rasterImage(太慢)
我尝试使用动画包中的saveVideo()
,但没有先显示背景,它运行良好。当我尝试使用rasterImage()
添加背景时,在背景中绘制PNG需要太多时间,因为它会在每个循环中从头开始绘制PNG。
有没有一种方法可以通过不让rasterImage()
在每个循环上运行来加速此过程?
是否可以删除绘制点并绘制一个新点,以便我不必再次运行rasterImage()
?
您的帮助将不胜感激!
下面是我的代码: 一个是x
数据帧,y
,t
栏目
saveVideo({
ani.options(interval = 1/100, nmax = 50)
xy = a[,1:2]
t = a$t
ima <- readPNG("floorplan.png")
for (i in 600:800) {
plot(xy[i,], xlim = c(0,520),ylim = c(0,300))
####to plot my png as background. works fine if this section is omitted
lim <- par()
rasterImage(ima, lim\$usr[1], lim\$usr[3], lim\$usr[2], lim\$usr[4])
#####
legend('topright',legend=paste('time =',i), bty='n')
ani.pause()
}
},movie.name = "pathBG.mp4")