Skip to content

Instantly share code, notes, and snippets.

@runemadsen
Created February 7, 2012 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runemadsen/1762733 to your computer and use it in GitHub Desktop.
Save runemadsen/1762733 to your computer and use it in GitHub Desktop.
How to create a .jar Processing app that you can launch from the command line
import processing.core.*;
public class Generator {
private PApplet applet = null;
private PGraphics context = null;
Generator()
{
}
void initialize(int _width, int _height)
{
applet = new PApplet();
context = applet.createGraphics(_width, _height, PApplet.P2D);
applet.g = context;
}
void render(String _filename)
{
if (applet == null || context == null)
{
System.out.println("error: GraphRenderer::render(): call initialize() before rendering.");
return;
}
context.beginDraw();
context.background(0);
context.fill(255);
context.rect(0, 0, 200, 200);
context.endDraw();
context.save(_filename);
}
}

Create a Java project in Eclipse

When created, import Processings core.jar: http://processing.org/learning/eclipse/

In you Java Project, create the attached files.

To export as a .jar file, right-click your project. Choose "Java > runnable Jar". Remember to choose you MainClass as the main class in the dialog.

give you .jar file a name. Press export.

Now run your .jar file on the command line using: java -jar MyJarName.jar

public class MainClass {
public static void main(String args[])
{
Generator g = new Generator();
g.initialize(400, 400);
g.render("test.png");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment