Daniel Carr
2012-Jun-02 20:02 UTC
[R] Double-buffering problem, this time with an example.
Most of my animations that used to work on windows() version 2.11.1 and earlier now flash as if the double buffering is turned off or buffer swapping is triggered by other events than in the past. The simplified example below using symbols should illustrate the problem in a windows environment. windows() radius <- 8 n <- 6 ang <- seq(0,2*pi,length=n+1)[-(n+1)] ca <- cos(ang) sa <- sin(ang) size <- c(.1, .3, .5, .7, .9, 1) colors <- rainbow(length(size)) for (i in 1:1000){ radius <- radius*.998 bnd <- (radius+1)* c(-1, 1) cenX <- radius*ca cenY <- radius*sa symbols(cenX, cenY, circles = size, xlim=bnd, ylim=bnd, bg=colors) } I have not isolated the version when the flashing started but it somewhere between 2.11.1 and 2.14.1. I did some searching on double-buffering problems in R but didn't find indications of this particular problem. Slowing the animation down did not help. Dan
Bert Gunter
2012-Jun-02 20:52 UTC
[R] Double-buffering problem, this time with an example.
For the record, I confirm Dan's description on Windows:> sessionInfo()R version 2.15.0 (2012-03-30) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.0 -- Bert On Sat, Jun 2, 2012 at 1:02 PM, Daniel Carr <dcarr at gmu.edu> wrote:> Most of my animations that used to work > on windows() version 2.11.1 and earlier now flash > as if the double buffering is turned off or buffer swapping > is triggered by other events than in the past. > > The simplified example below using symbols > should illustrate the problem in a windows environment. > > windows() > > radius <- 8 > n <- 6 > ang <- seq(0,2*pi,length=n+1)[-(n+1)] > ca <- cos(ang) > sa <- sin(ang) > size <- c(.1, .3, .5, .7, .9, 1) > > colors <- ?rainbow(length(size)) > > for (i in 1:1000){ > ?radius <- radius*.998 > ?bnd <- (radius+1)* c(-1, 1) > ?cenX <- radius*ca > ?cenY <- radius*sa > ?symbols(cenX, cenY, circles = size, > ? ? ? ? ?xlim=bnd, ylim=bnd, bg=colors) > } > > I have not isolated the version ?when the flashing > started but it somewhere between > 2.11.1 and 2.14.1. > > I did some searching on double-buffering > problems in R but didn't find indications > of this particular problem. > > Slowing the animation down did not help. > > Dan > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Duncan Murdoch
2012-Jun-02 22:17 UTC
[R] Double-buffering problem, this time with an example.
On 12-06-02 4:02 PM, Daniel Carr wrote:> Most of my animations that used to work > on windows() version 2.11.1 and earlier now flash > as if the double buffering is turned off or buffer swapping > is triggered by other events than in the past. > > The simplified example below using symbols > should illustrate the problem in a windows environment. > > windows() > > radius<- 8 > n<- 6 > ang<- seq(0,2*pi,length=n+1)[-(n+1)] > ca<- cos(ang) > sa<- sin(ang) > size<- c(.1, .3, .5, .7, .9, 1) > > colors<- rainbow(length(size)) > > for (i in 1:1000){ > radius<- radius*.998 > bnd<- (radius+1)* c(-1, 1) > cenX<- radius*ca > cenY<- radius*sa > symbols(cenX, cenY, circles = size, > xlim=bnd, ylim=bnd, bg=colors) > } > > I have not isolated the version when the flashing > started but it somewhere between > 2.11.1 and 2.14.1. > > I did some searching on double-buffering > problems in R but didn't find indications > of this particular problem. > > Slowing the animation down did not help.I don't think there was ever a guarantee that double buffering would be sufficient for what you were doing: you just got lucky. What you need to do (and this should work, at least on the windows() device and some others), is use dev.hold() to stop redrawing, and dev.flush() when you are ready to display the new stuff. Your loop becomes something like this: for (i in 1:1000){ dev.hold() radius <- radius*.998 bnd <- (radius+1)* c(-1, 1) cenX <- radius*ca cenY <- radius*sa symbols(cenX, cenY, circles = size, xlim=bnd, ylim=bnd, bg=colors) dev.flush() } The dev.hold() function was introduced in 2.14.0. I think dev.flush() existed earlier, but not for all systems. Duncan Murdoch