MyNixOS website logo
Description

Convert R Graphics to Flash Animations.

Using the 'Ming' library <https://github.com/libming/libming> to create Flash animations. Users can either use the 'SWF' device swf() to generate 'SWF' file directly through plotting functions like plot() and lines(), or convert images of other formats ('SVG', 'PNG', 'JPEG') into 'SWF'.

Description

This is an R package to convert R graphics to Flash file (SWF format). The conversion can be done in two different ways:

  1. This package contains a SWF device in R, so you can create SWF file directly using plotting functions like plot() and lines(). The convention is that every time you call a high-level plotting function, e.g. plot(), the movie will create a new frame and draw the following shapes in this frame. In this way, you can create some animation by calling a series of plot() functions.
  2. This package also includes several functions to convert graphics of other formats into SWF format. For example, svg2swf() to convert from SVG to SWF, and image2swf() to convert PNG and JPG images into a single SWF file.

Installation

R2SWF depends on the following libraries:

The source code of libming is included in R2SWF, and you need to install the other three by yourself.

For Debian/Ubuntu users, the command to install dependent libraries is

sudo apt-get install zlib1g-dev libpng12-dev libfreetype6-dev

For rpm based systems (e.g. Fedora), try to run

sudo yum install zlib-devel libpng-devel freetype-devel

Examples

In the first example, we first create 20 images using png() function, and then convert them into a single SWF file R2SWF-ex1.swf.

## Creating png files
png("image-png-%03d.png", 480, 300)
x = seq(0, 2 * pi, length.out = 20)
cols = rainbow(20)
for(i in 1:20) plot(x[i], sin(x[i]), xlim = c(0, 2 * pi), ylim = c(-1, 1),
                    col = cols[i], pch = 16, cex = 2, main = "PNG => SWF")
dev.off()

## Obtain the filenames
pngfiles = sprintf("image-png-%03d.png", 1:20)

## Convert to SWF
image2swf(pngfiles, "R2SWF-ex1.swf", interval = 0.3)

Using svg2swf is pretty similar, except that the output animation contains vector graphics.

## Do similar things as above
svg("image-svg-%03d.svg", 8, 5)
x = seq(0, 2 * pi, length.out = 20)
cols = rainbow(20)
for(i in 1:20) plot(x[i], sin(x[i]), xlim = c(0, 2 * pi), ylim = c(-1, 1),
                    col = cols[i], pch = 16, cex = 2, main = "SVG => SWF")
dev.off()
svgfiles = sprintf("image-svg-%03d.svg", 1:20)

## Convert to SWF
svg2swf(svgfiles, "R2SWF-ex2.swf", interval = 0.3)

The third example shows how to use the SWF device to create (rather than converting) SWF file directly.

swf("R2SWF-ex3.swf")
set.seed(123)
x = rnorm(5)
y = rnorm(5)
for(i in 1:100) {
    plot(x <- x + 0.1 * rnorm(5), y <- y + 0.1 * rnorm(5),
         xlim = c(-3, 3), ylim = c(-3, 3), col = "steelblue",
         pch = 16, cex = 2, xlab = "x", ylab = "y")
    title("Brownian Motion")
}
dev.off()

In general, when using the SWF device, high-level plotting functions (e.g. plot()) will advance the movie by one frame, and low-level functions (lines(), text(), etc.) are effective only to the current frame.

Metadata

Version

0.9-9

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows