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.
First, let's install Gradle.
For Mac, you can install it with brew install gradle
.
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);
}
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
settings.gradle
rootProject.name='helloP5Lib'
build.gradle
group 'helloP5Lib'
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);
}
}
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
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