Skip to content

getGraphicsEvent() alternative for cairo graphics device?

8 messages · frederik at ofb.net, Paul Murrell, Mark O'Connell

#
Hi Paul,

Just checking in to see what the status is.
package, so development can proceed at a reasonable rate, but I
haven't yet tried to see if that's even possible.

Thanks,

Frederick
On Tue, Jul 26, 2016 at 09:23:35AM +1200, Paul Murrell wrote:
#
Hi

The current status is that I am keen for people to contribute some 
testing code (see https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16951)

There were also some getGraphicsEvent() changes/fixes suggested by 
Richard Bodewits (cc'ed), for which I am also seeking test code.

Paul
On 13/11/16 09:00, frederik at ofb.net wrote:

  
    
#
Hi Paul,

Thank you, for some reason I didn't seem to get an email notification
for your bugzilla comment!

I will try to send you something shortly.

Frederick
On Mon, Nov 14, 2016 at 08:55:20AM +1300, Paul Murrell wrote:
#
Great.  Thanks!

Paul
On 14/11/16 13:41, frederik at ofb.net wrote:

  
    
#
Hi Paul,

OK I tried not to make the examples too fancy.

Please let me know what you think. They should probably be amended to
support the Windows platform, but I think that task would be much
easier for someone with access to Windows...

By the way I'm Cc'ing Mark O'Connell who shared with me some great
getGraphicsEvent examples - well, I found them useful, perhaps if
these are going to the R distro somewhere, then his examples should be
included as well.

Thank you,

Frederick
On Mon, Nov 14, 2016 at 01:51:08PM +1300, Paul Murrell wrote:
-------------- next part --------------
# Examples for "onIdle" function in getGraphicsEvent
# FHE 13 Nov 2016 - public domain

# This should produce a "plot" display with 50 random points connected
# by lines. The points will scroll to the right at a fixed speed,
# which depends on how fast your computer is. Closing the plot window
# should terminate the function cleanly, and pressing Ctrl-C at the
# prompt should have the same effect.
testIdle1 = function() {
  # cairo is the flicker-free option for X11
  X11(type="cairo");
  on.exit(dev.off());

  ps=matrix(runif(100),ncol=2)
  getGraphicsEvent(
                   onIdle=function() {
                     plot(ps[,1],ps[,2],type="b",
                          xlim=c(0,1),ylim=c(0,1));
                     ps<<-t(t(ps)+c(0.001,0)) %% 1
                     NULL
                   }
                   );
}

# This is a more interactive example. You have to move the mouse to
# start, and then the mouse will leave a trail which shrinks and
# rotates towards the center of the screen. There is a 0.01 second
# delay (currently Linux-specific, since Sys.sleep() can't be used in
# onIdle) between successive updates, so, unlike the first example,
# this shouldn't use 100% of your CPU (I measured 20% on a 3.7GHz
# Xeon). Closing the window or pressing "q" should terminate the
# function, but sometimes Ctrl-C at the prompt is ignored due to the
# system() call.
testIdle2 = function(factor=0.99,theta=0.03) {
  n=200;

  xform=factor*
    rbind(c(cos(theta),-sin(theta)),
          c(sin(theta),cos(theta)));
  
  lastp=c(0,0);
  ps=matrix(lastp,ncol=2);

  # cairo is the flicker-free option for X11
  X11(type="cairo");
  on.exit(dev.off());

  getGraphicsEvent(
                   onIdle=function() {
                     plot(ps[,1],ps[,2],
                          xlim=c(-1,1),ylim=c(-1,1),type="l");
                     
                     ps<<-head(rbind(lastp,ps%*%xform),n);

                     # for Windows, comment or change appropriately
                     system("sleep 0.02");
                     
                     NULL
                   },
                   onMouseMove=function(buttons,x,y) {
                     newX=grconvertX(x,"ndc","user");
                     newY=grconvertY(y,"ndc","user");
                     lastp<<-c(newX,newY);
                     NULL;
                   },
                   onKeybd=function(key) {
                     if(key=="q") { 1 }
                     else { NULL }
                   }
                   );
}
#
Thanks Frederick.

Mark, if you have any examples to share, they would also be gratefully 
received.

Paul
On 14/11/16 14:53, frederik at ofb.net wrote:

  
    
#
Hi Paul,

No problem. Is it best if I post examples to the bug report 16951?

Kind regards,
Mark

--

Mark O'Connell, PhD student
Department of Mathematics & Statistics
231 Top Logic
National University of Ireland, Maynooth
----- Paul Murrell <paul at stat.auckland.ac.nz> wrote:
#
Hi

That sounds good - somewhere public like that would be best.

Thanks!

Paul
On 16/11/16 00:13, Mark O'Connell wrote: