Skip to content

Instantly share code, notes, and snippets.

@kohske
Created March 13, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohske/d001fce960c0540cb5104fb2c7e40876 to your computer and use it in GitHub Desktop.
Save kohske/d001fce960c0540cb5104fb2c7e40876 to your computer and use it in GitHub Desktop.
Müller-Lyer Wave
library(grid)
o = function(th) {
yd = -0.5
grid.circle(0, 1, 0.25)
grid.lines(c(0, 0), c(yd, 1-0.25))
grid.lines(c(0, 0), c(yd, 0.5), gp = gpar(col="blue", lwd = 3))
f = 0.25
grid.lines(c(0, -cos(th)*f), c(0.5, 0.5+sin(th)*f), gp = gpar(lwd=3))
grid.lines(c(0, +cos(th)*f), c(0.5, 0.5+sin(th)*f), gp = gpar(lwd=3))
grid.lines(c(0, -cos(th)*f), c(yd, yd-sin(th)*f), gp = gpar(lwd=3))
grid.lines(c(0, +cos(th)*f), c(yd, yd-sin(th)*f), gp = gpar(lwd=3))
}
d = function(offset) {
grid.newpage()
for (x in seq(0, 1, length.out = 17)) {
pushViewport(viewport(x, 0.5, 0.1, 0.1))
o(x*pi + offset)
popViewport()
}
for (x in seq(0, 1, length.out = 17)) {
pushViewport(viewport(x, 0.25, 0.1, 0.1))
o(x*pi + offset-pi/3)
popViewport()
}
for (x in seq(0, 1, length.out = 17)) {
pushViewport(viewport(x, 0.75, 0.1, 0.1))
o(x*pi + offset+pi/3)
popViewport()
}
}
library(animation)
saveGIF(
{for (i in seq(0, pi*2*5, pi/10)) {d(i)}}, movie.name = "mlwave.gif",
interval = 0.1,
ani.width = 600,
ani.heigth = 300
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment