Convert R Graphics to Flash Animations

Using the 'Ming' library < http://www.libming.org/> 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'.


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.

News

      CHANGES IN R2SWF VERSION 0.9

BUG FIXES

o Fix a bug in setting the dimension of the SWF file that occurs in
  image2swf()
o Eliminate R CMD check warnings





      CHANGES IN R2SWF VERSION 0.8-2

BUG FIXES

o Fix a misuse of abs() in the C code, thanks to Prof. Ripley





      CHANGES IN R2SWF VERSION 0.8-1

BUG FIXES

o Fix a memory bug detected by valgrind, thanks to Prof. Ripley





      CHANGES IN R2SWF VERSION 0.8

NEW FEATURES

o SWF graphics device now supports the hadj parameter

DEPRECATED AND DEFUNCT

o Functions list.fonts() and add.fonts() are removed
o Functions font.paths(), font.families(), font.files() and
  font.add() are moved to the sysfonts package which the
  current version of R2SWF depends on





      CHANGES IN R2SWF VERSION 0.7-1

BUG FIXES

o Fix a bug in detecting the OS type





      CHANGES IN R2SWF VERSION 0.7

NEW FEATURES

o Add function font.files() to list available font files

BUG FIXES

o Fix swf2html() to make it work properly with knitr hook hook_r2swf()
o Rename list.fonts() to font.families(), and add.fonts() to font.add().
  Old function names are deprecated but kept for compatibility.





      CHANGES IN R2SWF VERSION 0.6-1

BUG FIXES

o Remove configure.win so it should be built on both architectures
  on Windows
o Fix loading problem on R 2.15.3





      CHANGES IN R2SWF VERSION 0.6

BUG FIXES

o Clarify the copyrights
o Remove the source code of some external libraries





      CHANGES IN R2SWF VERSION 0.5

NEW FEATURES

o A SWF device for R through swf()

BUG FIXES

o Take care of absolute and relative paths of files
o Remove "outdir" argument from dev2swf()





      CHANGES IN R2SWF VERSION 0.4-1

BUG FIXES

o Update zlib to 1.2.8
o Update libpng to 1.6.2
o Add freetype 2.5.0
o Update libming to 0.4.5
o Fix several memory leak problems
o Use absolute paths for dev2swf(), swf2html() etc.
o HTML file created by swf2html() will have a copy of the SWF file
  in the same directory





      CHANGES IN R2SWF VERSION 0.4

NEW FEATURES

o A new function file2swf() as a wrapper of image2swf() and
  svg2swf()

o swf2html() uses a simple <embed> tag instead of the long ugly old
  <object> tag to write the Flash file in HTML; it also gained a new
  argument 'fragment' to decide whether to return an HTML fragment or
  a complete HTML document





      CHANGES IN R2SWF VERSION 0.3-1

NEW FEATURES

o Windows version of R supports svg() since 2.14.0.
  Now svg2swf() also accepts SVG files created by svg().

o dev2swf() now supports svg() device





      CHANGES IN R2SWF VERSION 0.3-0

NEW FEATURES

o Allow users to set the background color of the output SWF file

o Re-design the arguments list of image2swf() and svg2swf()
  for ease of use

BUG FIXES

o (Internal) Use a more appropriate way to insert frames in a SWF file





      CHANGES IN R2SWF VERSION 0.2-2

BUG FIXES

o Fix Makefile errors





      CHANGES IN R2SWF VERSION 0.2-1

BUG FIXES

o Fix compilation errors in Windows





      CHANGES IN R2SWF VERSION 0.2-0

NEW FEATURES

o svg2swf() to convert SVG files to a Flash animation





      CHANGES IN R2SWF VERSION 0.1-0

NEW FEATURES

o image2swf() and dev2swf() to convert png/jpeg files to a Flash animation

o swf2html() to embed a Flash file into an HTML page

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("R2SWF")

0.9-4 by Yixuan Qiu, 11 days ago


https://github.com/yixuan/R2SWF


Report a bug at https://github.com/yixuan/R2SWF/issues


Browse source code at https://github.com/cran/R2SWF


Authors: Yixuan Qiu , Yihui Xie , Cameron Bracken and authors of included software. See file AUTHORS for details.


Documentation:   PDF Manual  


GPL-2 license


Imports sysfonts, grDevices, utils

Suggests XML, Cairo

System requirements: zlib, libpng, FreeType


See at CRAN