# # Example of using GC's and drawing primitives! # Create a drawing area and a GC (graphics context) # # Then draw # 1) a line, # 2) rectangle # 3) filled rectangle # 4) polygon # 5) circles # # Date: Sat Feb 10 23:02 PST 96 # (function() { load("Motif") X = XApplication("none") draw = Widget("draw","DrawingArea", X@widget,realize=T) XRealize(X) backingStore(draw,"Always") # options(check=T) # Background="red", gc = XGC(X@widget,LineWidth=1,Background="blue",Foreground="red",LineStyle="OnOffDash",Function="copy") x = c(20,100,100) y = c(20,100,150) XLines(x,y,draw,gc = gc) xr = seq(10,by=30,length=3) yr = seq(10,by=30,length=3) ht = rep(10,3) wd = rep(14,3) XRectangles(xr+50,yr+50,wd,ht,draw,gc=gc) XRectangles(xr,yr,wd,ht,draw,fill=T,gc=gc,Foreground="blue") cat("Taking 5\n") sleep(5) XClear(draw) xr = seq(5,by=15,length=10) yr = seq(5,by=15,length=10) ht = 10 wd = 10 colors = rep(c("red","blue","orange","cyan"),length.out=length(yr)) for(i in 1:length(yr)) { XRectangles(xr,yr[i],wd,ht,draw,gc=gc,fill=T,Foreground=colors[i]) } # Polygons z1 = c(100, 10, 100, 150) z2 = c(10,60,100, 60) XLines(z1+100,z2,draw,fill=T,gc=gc,Function="xor") # circles cx = 150 cy = 10 wd = 100 ht = 100 XArcs(cx,cy,wd,ht,w=draw,gc=gc,Foreground="sky blue") cat("Taking 5\n") sleep(5) # now draw the polygon again to remove it. # The GraphicsExposures does nothing but is a test for the NamedLogical class. XLines(z1+100,z2,draw,fill=T,gc=gc,Function="xor",GraphicsExposures=T) invisible(return(X)) })()