# Sigma motion visual illusion in R

August 21, 2012
By

(This article was first published on mages' blog, and kindly contributed to R-bloggers)

Michael Bach, who is a professor and vision scientist at the University of Freiburg, maintains a fascinating site about visual illusions. One visual illusion really surprised me: the sigma motion.

The sigma motion displays a flickering figure of black and white columns. Actually it is just a chart, as displayed below, with the columns changing backwards and forwards from black to white at a rate of about 30 transitions per second.

It can be a bit irritating to watch the movement, hence I use a button here to display and hide the animation.

Now, put your finger on the animated chart and move the finger to the left or right, so that you cover the chart in about 2 seconds and you will notice that the flickering stops and instead it appears that the columns move in the same direction as your finger! It works particular well on a touch screen device.

You find more information, details and another implementation on Michael’s page. Below is the little R script which produced the charts/GIFs used in this post.

### R code to replicate plots

``` ```

``````library(animation)
fps <- 30
nstripes <- 20
ani.options(interval=1/fps, ani.width=600, ani.height=100)

sm <- function(n=20, col=c("black", "white")){
x <- c(1:(2*n))
y <- 1
z <- matrix(rep(c(1,0),n), ncol=1)
image(x, y, z, col=col, bty="n",
xaxt="n", yaxt="n", xlab="", ylab="")
}

saveMovie({
op <- par(mar=c(0,0,0,0))
for(i in c(1:(2*fps))){
sm(nstripes, col=c("black","white"))
sm(nstripes, col=c("white","black"))
}
par(op)
})
## You will find the output here:
file.path(tempdir(), "animation.gif")

sessionInfo()
## R version 2.15.1 (2012-06-22)
## Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
##
## 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] stats     graphics  grDevices utils     datasets  methods   base
##
## other attached packages:
## [1] animation_2.1
``````
``` ```

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

Tags: , , , , , , ,