**Bridget Riley's Moving SquaRes**

This morning at R-Bloggers I saw Markus' https://plus.google.com/118201313972528070577/ post, providing R code to produce one of Bridget Riley's Op Art pictures. Very nice! I played around with it, making it a little more general and adding colour, see attached image for a nearly equiluminant version (the luminance of red and blue are nearly the same), making it even more dynamic. See this paper http://dx.doi.org/10.1068/i0457aap from Johannes Zanker's lab on eye movements and their role in Op Art pictures. R code below:

# Moving SquaRes

# Michael Bach 2012-07-12

#

# Inspired by

# http://lamages.blogspot.de/2012/07/bridget-riley-exhibition-in-london.html

# in turn inspired by Bridget Riley's Moving Squares

distortionFunc <- function(x) { # this is a rounded fit to Markus' data

return (845*x - 46*x*x +0.88*x*x*x)

}

odd <- function(arg) {

return (arg/2 != round(arg/2))

}

pntsX = 32; pntsY = 12

x = distortionFunc(1:pntsX)

plot(y=x, x=1:pntsX) # for a look at the distortion function

y = 1:pntsY

z = matrix(nrow=pntsX, ncol=pntsY)

for (ix in 1:pntsX) { # I'm sure this could be more elegant in R!

for (iy in 1:pntsY) {

z[ix, iy] = ifelse(xor(odd(ix), odd(iy)), 0, 1)

}

}

cols = c(rgb(0, 0.8, 0), rgb(1, 0, 0)) # nearly equiluminant red&green

image(x[-pntsX], y[-pntsY], z[-pntsX,-pntsY], col=cols, axes=FALSE, xlab="", ylab="")