# [R] Animated lissajous

From: <rlist.10.phftt_at_xoxy.net>
Date: Sun 16 Oct 2005 - 13:34:29 EST

Here's some code to make lissajous dance. I've attached a small sample GIF. Cheers,
Rob Steele
robsteele at yahoo dot com

plot.lissajous = function(omega.x, omega.y, delta = 0, num.thetas = 200) {

thetas = seq(0, 2 * pi, length = num.thetas)    xs = sin(omega.x * thetas + delta)
ys = cos(omega.y * thetas)
plot(xs, ys, type = 'l', lwd = 3, ann = FALSE, axes = FALSE)
}

## Show one.
par(mar = c(2, 2, 2, 2))
plot.lissajous(4, 3)

## Animate it.
while (TRUE) {

for (delta in seq(0, 2 * pi, length = 120)) {

```       plot.lissajous(4, 3, delta)
Sys.sleep(1 / 30)
```

}
}

## Show a bunch.
par(mar = c(1, 1, 1, 1))
par(mfrow = c(length(omega.xs), length(omega.ys))) for (omega.x in 1:5) {

for (omega.y in 1:5) {

plot.lissajous(omega.x, omega.y, deltas[i])    }
}

## Animate them. (Requires ImageMagick.) num.frames = 120
image.dir = 'images'

if (! file.exists(image.dir)) {

dir.create(image.dir)
}

deltas = seq(0, 2 * pi, length = num.frames)

for (i in 1 : length(deltas)) {

```   png(file = file.path(image.dir, sprintf('img-%03d.png', i)))
par(mar = c(1, 1, 1, 1))
par(mfrow = c(length(omega.xs), length(omega.ys)))
for (omega.x in 1:5) {
for (omega.y in 1:5) {
plot.lissajous(omega.x, omega.y, deltas[i])
}
```

}
dev.off()
}

## This ImageMagick command combines the image files into a GIF animation: # convert -delay 3 images/*.png images/animation.gif

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Oct 16 13:42:28 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:45 EST