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
Oh my goodness how did that bug creep in there. Ignore that last post and try this instead. 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. num.frames = 120 omega.xs = 1:5 omega.ys = 1:5 deltas = seq(0, 2 * pi, length = num.frames) par(mar = c(1, 1, 1, 1)) par(mfrow = c(5, 5)) for (omega.x in omega.xs) { for (omega.y in omega.ys) { plot.lissajous(omega.x, omega.y) } } ## Animate them. image.dir = 'images' if (! file.exists(image.dir)) { dir.create(image.dir) } 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 displays the image files in rapid succession ## to animate them: # animate -delay 2 images/*.png ## This ImageMagick command combines the image files into a GIF animation: # convert -delay 3 images/*.png images/animation.gif
Pretty neat. Jarek ====================================================\==== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation <\__,| (703) 676-4192 "> \ Jaroslaw.W.Tuszynski at saic.com ` \ -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of rlist.10.phftt at xoxy.net Sent: Saturday, October 15, 2005 11:34 PM To: r-help at stat.math.ethz.ch Subject: [R] Animated lissajous 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