Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use processing in Java application

I downloaded processing from http://processing.org. How is it possible to use porcessing in my Java application. I want drawing stuff depending on the logic in my Java application. To avoid the drawing in Java I want to use processing instead.

like image 477
DenicioCode Avatar asked Jan 23 '14 13:01

DenicioCode


People also ask

Can you use Processing in Java?

Processing uses Java mode by default and it not only allows the programmers to write code to draw a variety of shapes, but also enables them to write a complex program.

What do you use Processing for?

Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology.

Do I need Java for Processing?

Processing uses its own version of Java, not whatever Java you have installed on your system. Also, if you want to use the Processing library you'll need to add the core. jar file to your classpath.

What is a Processing example?

A few examples of processes might include: Preparing breakfast. Placing an order. Developing a budget.


2 Answers

Piece of cake,

First,

In your IDE (eg Netbeans) first include the processing jar in your build, put it some place your program can find it. For example if you use maven just add the dependancy:

<dependency>
    <groupId>org.processing</groupId>
    <artifactId>org.processing.core</artifactId>
    <version>2.1.1</version>
</dependency>

Second,

Add a main class to your program this can be very simple. You just need to reference the class where your code will be:

public class Application {

    public static void main(String[] args) {
        new Application();
    }

    public Application() {
        init();
    }

    private void init() {
        Visualization.main("me.qcarver.ballsack.Visualization");

    }
}

Lastly,

Add your new class with the package name as you gave in quotes above. The only thing to remember is this class must (1) import processing.core.PApplet (2) extend PApplet (3) implement public void draw and public void setup

Eg:

   package me.qcarver.ballsack
   public class Visualization extends PApplet{

    public void setup() {
        size(500,400);
        background(grayValue);        
    }

        public void draw(){
            elipse(200,200,50,50);
        }
    }

Snippets above are based on this example project which runs Processing.org code in a java application.

like image 188
Quinn Carver Avatar answered Sep 30 '22 19:09

Quinn Carver


If anyone has trouble with the earlier code example and the latest Processing libraries - I've updated for v3.2.1 and uploaded the working code:

https://github.com/thomasbratt/ProcessingInIntellij

package com.github.thomasbratt.processingtest;

import processing.core.PApplet;

public class Visualization extends PApplet {

    public static void main(String[] args) {
    PApplet.main("com.github.thomasbratt.processingtest.Visualization");
    }

    @Override
    public void settings() {
        size(640, 480);
    }

    @Override
    public void setup() {
        fill(120,50,240);
    }

    @Override
    public void draw(){
        ellipse(width/2,height/2,second(),second());
    }
}

pom.xml:

<dependency>
    <groupId>org.processing</groupId>
    <artifactId>core</artifactId>
    <version>3.2.1</version>
</dependency>
like image 29
Thomas Bratt Avatar answered Sep 30 '22 20:09

Thomas Bratt