-
Notifications
You must be signed in to change notification settings - Fork 94
Under the hood
Martin Prout edited this page Apr 8, 2014
·
9 revisions
Simple vanilla processing sketch:-
CircleTest.pde
Circle circle;
void setup() {
size(200, 200);
circle = new Circle(100);
}
void draw() {
background(0);
circle.draw();
}
Circle.pde (class in separate tab in ide)
class Circle {
float size;
Circle(float sz) {
size = sz;
}
void draw() {
fill(200);
ellipse(width / 2, height /2, size, size);
}
}
When translated to java (by processing) prior to compiling
CircleTest.java
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class CircleTest extends PApplet {
Circle circle;
public void setup() {
size(400, 400);
circle = new Circle(100);
}
public void draw() {
background(0);
circle.draw();
}
class Circle { // sketch width and height accessible to this java inner class
float size;
Circle(float sz) {
size = sz;
}
public void draw() {
fill(200);
ellipse(width / 2, height /2, sz, sz);
}
}
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "CircleTest" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
circle_test.rb
attr_reader :circle
def setup
size 200, 200
@circle = Circle.new 100
end
def draw
background 0
circle.draw
end
class Circle # cannot access Sketch width and height without using $app
attr_reader :size
def initialize sz
@size = sz
end
def draw
fill 200
ellipse $app.width / 2, $app.height / 2, size, size
end
end
As wrapped by ruby-processing before sending to jruby
class Sketch < Processing::App
attr_reader :circle
def setup
size 200, 200
@circle = Circle.new 100
end
def draw
background 0
circle.draw
end
class Circle
attr_reader :size
def initialize sz
@size = sz
end
def draw
fill 200
ellipse $app.width / 2, $app.height / 2, size, size
end
end
end