Easy to create Processing library

When I try to create a Processing library There is a lot of tedious work such as setting the path. So, I made a template that makes it easy to create a library using Gradle, so I would like to introduce it.

Preparation

First, let's install Gradle. For Mac, you can install it with brew install gradle.

processing-library-template-gradle

How to make a library using processing-library-template-gradle

This time, I will write it on the assumption that a library called helloP5Lib will be created. The only class is the Hello class in the hello.p5.lib package. How to use this library is like this.

Sample.pde


import hello.p5.lib.*;
Hello hello;

void setup() {
    size(300, 300);
    hello = new Hello(this, "Taro");
}
void draw() {
    background(0);
    hello.draw(100, 100);
}
スクリーンショット 2018-03-08 18.30.43.png

Download template

mkdir helloP5Lib
cd helloP5Lib
git clone https://github.com/enkatsu/processing-library-template-gradle.git .

The directory structure at this time looks like this.

.
├── LICENSE
├── README.md
├── build.gradle
├── examples #Library sample sketch
│   └── HelloLibrary
│       └── HelloLibrary.pde
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
    └── main
        └── java #Where to actually write the source code of the library
            └── processing
                └── library
                    └── template
                        └── Sample.java

Build settings

settings.gradle


rootProject.name='helloP5Lib'

build.gradle


group 'helloP5Lib'

Library implementation

Next, edit the contents under src / main / java / to write the contents of the library.

rm -rf src/main/java/processing
mkdir -p src/main/java/hello/p5/lib
touch src/main/java/hello/p5/lib/Hello.java

Hello.java


package hello.p5.lib;

import processing.core.*;

public class Hello {
    PApplet app;
    String name;
    public Hello(PApplet app, String name) {
        this.app = app;
        this.name = name;
    }
    public void draw(float x, float y) {
        app.text(this.name, x, y);
    }
}

Library build

Build is the following command.

gradle -q

The reference can be output like this.

gradle javadoc

The directory structure at this point looks like this.

.
├── LICENSE
├── README.md
├── build.gradle
├── examples
│   └── HelloLibrary
│       └── HelloLibrary.pde
├── gradlew
├── gradlew.bat
├── library #Built library
│   ├── classes
│   │   └── java
│   │       └── main
│   │           └── hello
│   │               └── p5
│   │                   └── lib
│   │                       └── Hello.class
│   ├── processingLibraryTemplate.jar
│   └── tmp
│       ├── compileJava
│       ├── jar
│       │   └── MANIFEST.MF
│       └── javadoc
│           └── javadoc.options
├── reference #Output reference
│   └── javadoc
├── settings.gradle
└── src
    └── main
        └── java
            └── hello
                └── p5
                    └── lib
                        └── Hello.java

Install and use in Processing

Copy the helloP5Lib directory under processing / libraries and you're done. Restart Processing and see if it appears in Sketch> Import library. If helloP5Lib is displayed, the original library is complete.

Recommended Posts

Easy to create Processing library
Easy way to create JSP custom tags
Create versatile processing
Easy way to create an implementation of java.util.stream.Stream
Create assert_equal to make it easy to write tests
How to create docker-compose
Easy to maintain FizzBuzz
Challenge to create inquiry form
[Swift] Processing to share screenshots
Easy library introduction with Maven!
Easy to use array.map (&: method)
How to create a method
Easy way to create a mapping class when using the API
Processing to issue an error message
Preparing to create a Rails application
Function is very easy to use
SpringBoot + Redis Easy to make demo
Delegate some Java processing to JavaScript
[Rails] Easy way to check columns
Introduction to Ruby processing system self-made
[Processing × Java] How to use variables
[Java] How to create a folder
How to insert an external library
Easy to use Cloud Firestore (Android)
Manually perform processing equivalent to @ConfigurationProperties
Welcome to the Java Library Swamp! !!
Add processing to original annotation to Jackson
Try to create a server-client app
[Processing × Java] How to use arrays
Easy way to create an original logo for your application (easy with your smartphone)
[Active Admin] I want to customize the default create and update processing
Created a library that makes it easy to handle Android Shared Prefences