Flowing triangles
[This article was first published on mages' blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I have admired the work of the artist Bridget Riley for a long time. She is now in her eighties, but as it seems still very creative and productive. Some of her recent work combines simple triangles in fascinating compositions. The longer I look at them, the more patterns I recognise. Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Yet, the actual painting can be explained easily, in a sense of a specification document to reproduce the pattern precisely. However, seeing the real print, as I had the chance at the London Art Fair last week, and a reproduction on the screen is incommensurable.
Having said that, I could not resist programming a figure that resembles the artwork labelled Bagatelle 2. Well, at least I can say that I learned more about
grid
[1], grid.path
[2] and gridSVG
[3] in R. R Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
ya <- sqrt(3) * 0.5 | |
yp <- c(2, 2, 2 - ya) | |
x_iter <-c(1:6, 0.5:7.5, 1:8, 0.5:7.5, 2:7) | |
DT <- data.table( | |
x = unlist(lapply(x_iter, | |
function(t) c(1, 2, 1.5) + t)), | |
y = c(rep(yp, 6) + 4, rep(yp, 8) + 4 - ya, | |
rep(yp, 8) + 4 - 2*ya, rep(yp, 8) + 4 - 3*ya, | |
rep(yp, 6) + 4 - 4*ya), | |
id = rep(1:36, each=3) | |
) | |
n <- 49 | |
t <- seq(pi*7/3, pi*2, length=n) | |
xin <- cos(t) - min(cos(t)) | |
yin <- sin(t) - max(sin(t)) | |
xout <- cos(t - pi) - min(cos(t - pi)) | |
yout <- sin(t - pi) | |
DT <- rbindlist( | |
list( | |
DT, | |
rbindlist(lapply(c(10, 11, 13, 15, 25:28, 30, 35), function(i){ | |
data.table(x=DT[id==i, x][3] - xin, | |
y=DT[id==i, y][3] - yin, id=i) | |
})), | |
rbindlist(lapply(c(4, 6, 7, 17:19, 21, 31:33), function(i){ | |
data.table(x=DT[id==i, x][3] - rev(xout), | |
y=rev(DT[id==i, y][3] - yout), id=i) | |
})) | |
) | |
) | |
xmax=max(DT[,x]) | |
ymax=max(DT[,y]) | |
library(grid) | |
grid.newpage() | |
pushViewport( | |
viewport(name="vp1", | |
layout=grid.layout(1,1, | |
widths=9, | |
heights=5, | |
respect=TRUE))) | |
pushViewport( | |
viewport(name="vp2", layout.pos.row=1, | |
layout.pos.col=1, xscale=range(DT[,x]), | |
yscale=range(DT[,y]), clip=TRUE)) | |
grid.rect(gp=gpar(fill="white")) | |
grid.path(DT[,x]/xmax-0.05, DT[,y]/ymax-0.1, id=DT[,id], | |
gp=gpar(fill="black")) | |
library(gridSVG) | |
grid.export("Bagatelle_2.svg") | |
browseURL("Bagatelle_2.svg") |
References
[1] P. Murrell. R Graphics, Second Edition. CRC Press. 2011[2] P. Murrell. What’s in a Name? . The R Journal, 4(2):5–12, dec 2012.
[3] P. Murrell and S. Potter. gridSVG: Export grid graphics as SVG. R package 1.5-0. 2015
Session Info
R version 3.2.3 (2015-12-10) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.11.2 (El Capitan) locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets [7] methods base other attached packages: [1] gridSVG_1.5-0 data.table_1.9.6 loaded via a namespace (and not attached): [1] tools_3.2.3 RJSONIO_1.3-0 chron_2.3-47 XML_3.98-1.3
To leave a comment for the author, please follow the link and comment on their blog: mages' blog.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.