使用 R 语言实现新媒体艺术作品
Authot: Tealeaf, Contra, AnYong Cui
2012 除夕夜北京地区短信数据的可视化作品
Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts
You know better than me!
Installation
HOWTO
2D
Event System
3D
Libraries
R Packages
settings <- function() {
size(480, 120)
}
draw <- function() {
if (mousePressedVar == TRUE) {
fill(0)
} else {
fill(255)
}
ellipse(mouseX, mouseY, 80, 80)
}
settings <- function() {
size(640, 360, P3D)
}
draw <- function() {
background(0)
camera(mouseX, height/2,
(height/2) / tan(PI/6), width/2, height/2, 0, 0, 1, 0)
translate(width/2, height/2, -100)
stroke(255)
noFill()
box(200)
}
The biggest advantage of Renjin is that the R interpreter itself is a Java module which can be seamlessly integrated into any Java application.
public class TryRenjin {
public static void main(String[] args) throws Exception {
// create a script engine manager:
RenjinScriptEngineFactory factory
= new RenjinScriptEngineFactory();
// create a Renjin engine:
ScriptEngine engine = factory.getScriptEngine();
engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))");
engine.eval("print(df)");
engine.eval("print(lm(y ~ x, df))");
}
}
public class PApplet {
public void draw() {
// Insert the logic to the template and compile it.
}
}
public class PApplet {
public void draw() {
rInterpreterInJVM.eval(code.getFunction("draw"))
}
}