Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

11 Commits

Repository files navigation

Template for setting up a project with Processing and Java

Instead of working inside the processing IDE, you can use your prefered IDE and have a much better experience.

Setup

  1. Create a new project in your prefered IDE. In this case I'm using IntelliJ IDEA CE.

  2. Add the processing core to your project's library

    • Go to file -> project structure
    • Go to thee library section and add click the + button to add a new library.
    • On Mac OSX this is located at /Applications/Processing.app/Contents/Java/Core.jar
  3. Create your main class that extends PApplet (add your import - import processing.core.PApplet;)

Sample App Class

importprocessing.core.PApplet;
publicclassAppextendsPApplet {
publicvoidsetup() {
frameRate(30);
}
publicvoidsettings() {
size(500, 500);
}
publicvoiddraw(){
// Global Draw Logicbackground(64);
rectMode(CENTER);
rect(mouseX, mouseY, 5, 5);
if (mousePressed) {
// ... example of handling mouse clicks
}
if (keyPressed) {
// example of handling keypressesif (key == 'a'){
// ...
} elseif (key == 'b'){
// ...
}
}
}
publicstaticvoidmain(String[] passedArgs) {
String[] appletArgs = newString[] { "App" };
PApplet.main(appletArgs);
}
}

Example Secondary/Component Class

importprocessing.core.PApplet;
publicclassComponent {
privatePAppletp;
publicComponent(PAppletp, /* ...other params */) {
/* Component constructor */this.p = p;
// ... other constructor/initialization logic
}
publicvoidcalculate() {
/* Do all your calculations/setup here before drawing */
}
publicvoiddraw() {
// First, run the calculations/setupthis.calculate();
// To use processing methods just use the app instance.// e.g.// p.stroke(...);// p.fill(...);// p.rect(...);// etc.
}
}

Using the Component in the main App

/* ... Main App Class */publicvoiddraw(){
// ... Other draw logic// Instantiate a new component and pass instance (this) as argument to have access to all processing methodsComponentcomponent = newComponent(this);
component.draw();
// ... Rest of main app draw logic
}
/* ... Rest of Main App Class */
Note: Ideally you wouldn't instantiate the component inside the draw function, you would have it as a private class attribute or something, but it was shown this way for simplicity. The main idea is that the component does not get drawn until the .draw() method is called on that specific component.

About

This repository contains a template and documentation on how to set up processing with an IDE - allowing you to ditch the clunky processing editor. This way you get access to all the IDE features, version control, and full auto-completion.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages