JAVA & Processing

Knowledge Visualization is the ability to collect, store, and manage data is increasing quickly, but our ability to understand it remains constant. In an attempt to gain better understanding of data, fields such as information visualization, data mining and graphic design are employed, each solving an isolated part of the specific problem, but failing in a broader sense: there are too many unsolved problems in the visualization of complex data. As a solution, this dissertation proposes that the individual fields be brought together as part of a singular process titled Computational Information Design.

In order to use Processing API within Java IDE, e.g. Eclipse, it is important to implement core.jar as one of project libraries, which can be found in the package processing.core. All Processing sketches sub-class the PApplet class from processing.core. To run the sketch as JAVA application code will be something like this[1]:

import processing.core.*;
public class ProcessingSketch extends PApplet {
public static void main (String args[]) {
PApplet.main(new String[] { "--present",   "processing.ProcessingSketch" });
}
public void setup() {
size (200,200);
background (0);
}
public void draw() {
stroke (255);
if (mousePressed) {
line (mouseX, mouseY, pmouseX, pmouseY);
}
}
}

In case there are more classes within one project, lets say Sampler and Sample, then the code would be as follows[2]:

import processing.core.*;
public class Sampler extends PApplet{
Samples[] smp = new Samples [50];
public static void main (String args[]) {
PApplet.main(new String[] { "--present", "Sampler" });
}
public void setup() {
size(200,200);
for (int i=0; i < stripes.length ; i++) {
smp[i] = new Samples (this);
}
}
public void draw(){
background(100);
for (int i=0; i < stripes.length ; i++) {
smp[i].move();
smp[i].display();
}
}
}

And for class Sample:

import processing.core.PApplet;
public class Samples {
float x;
float speed;
float w;
boolean mouse;
PApplet parent;
Samples (PApplet p) {
parent = p;
x = 0;
speed = parent.random (1);
w = parent.random (10,30);
mouse = false;
}
void display() {
parent.fill (255,100);
parent.noStroke();
parent.rect(x,0,w,parent.height);
}
void move() {
x += speed;
if (x > parent.width+20) x = -20;
}
}

[1] Without main method it is only possible to run the code as an Applet.

[2] Without this procedure Java would not know where the find methods, since additional classes are treaded in Processing as inner classes to the main PApplet.

You must be logged in to post a comment.

Subscribe Scroll to Top