Processing with Eclipse
Finally I’m back doing a Processing project and decided to do it with Eclipse to have features like code completion and code templates of this professional IDE. After reading this forum post and this blog posts it was really an easy job to get started. Here are the steps I did:
- Create a new Eclipse Project: File -> New -> Project, Java Project, Next and give him a name
- Include Processing core library: Right mouse button over project name in Package Explorer, Build Path -> Add External Archives, select file core.jar from lib folder in processing install folder
- Create a source folder for java files: Right mouse button over project name in Package Explorer, New -> Source Folder, name it something like src
- Create new class: Right mouse button over src folder, New -> Class, name it
- Extend defined class with extends PApplet
- Write code (here example Linear) so you get a structure like:
import processing.core.*; public class Test extends PApplet { float a = 100; public void setup() { size(200, 200); stroke(255); frameRate(30); } public void draw() { background(51); a = a - 1; if (a <0) { a = height; } line(0, a, width, a); } }
- Run example with Run As -> Java Applet
data folder for external resources
In order to use resources like images and fonts in Processing we have to create a data folder in our src folder. The following example only displays a string using the font from the data folder:
import processing.core.*; public class testProcessing extends PApplet { public void setup() { size(200, 200); PFont font = loadFont("muktinarrowbold-14.vlw"); textFont(font, 14); text("processing & eclipse\nthe dynamic duo", 30, 30); } }
using Processing libraries
In order to use Processing libraries we have to include the right references like we did with the core library. To test the functionality we use the HTTPClient example using the Net library: Click with the right mouse button over project name in Package Explorer, Build Path -> Add External Archives, select file net.jar from libraries folder in processing install folder. Then we add the import statement for the library and get the following code:
import processing.core.*; import processing.net.*; public class testProcessing extends PApplet { Client client; public void setup() { size(200, 200); noStroke(); // Open a TCP socket to the host: client = new Client(this, "processing.org", 80); // Print the IP address of the host: println(client.ip()); // Send the HTTP GET request: client.write("GET /index.php HTTP/1.1\n"); client.write("HOST: processing.org\n\n"); } public void draw() { background(0); // Print the results of the GET: if (client.available() > 0) { int inByte = client.read(); print((char)inByte); } else { println("\n\nThat's all, folks!\n"); } } }
Tags: processing.org
June 21st, 2007 at 10:11 am
Great tutorial!! I am looking for the way that I can have Processing in my Eclipse plug-ins. Any ideas?
October 4th, 2007 at 8:36 pm
With respect to Processing’s PFont, loadFont and using it with Eclipse. Things are a bit difficult if you are using ‘Packages’.
I had Processing/Eclipse things working, exporting from Processing and importing into Eclipse, but I was using a Package within the Eclipse Project. I could not get things going with fonts, but…
To get font things happening, I had to:
in my eclipse workspace, create a ‘Project’ then ‘import’ into the ‘default package’ (which is not recommended by Eclipse),
then copy the ‘data’ directory created in Processing (with the .vlw file) into the file system path:
//data
There is also:
//src (created by Eclipse)
containing the .java file originally from Processing and
//bin (created by Eclipse)
November 23rd, 2008 at 6:56 am
you examples work – thanks. However I am unable to get my sketches to run with openGL or P5sunflow. I get runtime errors…
May 17th, 2011 at 7:06 pm
Thanks for the tutorial!
Short and with just enough detail to be quick and easy. And it worked where others didn’t in helping me get the data folder working!