Skip to content

Processing sketches written in Kotlin, built with Gradle

License

Notifications You must be signed in to change notification settings

anoniim/visuals3

Repository files navigation

Gradle Setup

I tried to avoid having to include the library JARs in the project as much as I could, but it was not sustainable. I want this project to be runnable with minimum effort and that was no longer possible. That is because there are some dependencies (including some specific to Processing) that cannot be obtained from maven.

Therefore, all project dependencies are included in the project (in /libs folder).

Maven

For those curious, there are the instruction to use maven:

Using Kotlin DSL for Gradle, the Processing dependency can be defined as follows:

implementation(group = "org.processing", name = "core", version = "3.3.7")

Public maven

The public maven artefacts (taken from mavenCentral()) are not owned by the Processing Foundation and therefore are out of date (only version up to 3.3.7 available).

Local maven

For a newer version, download Processing, open the application files and install the library file in local maven repository. On MacOS, this can be done by:

cd /Applications/Processing.app/Contents/Java/core/library
mvn install:install-file -Dfile=core.jar -DgroupId=org.processing -DartifactId=core -Dversion=3.5.4 -Dpackaging=jar
implementation(group = "org.processing", name = "core", version = "3.5.4")

Same technique can be used to install any number of Processing libraries. Just download the library via Processing PDE and install the JARs in local maven by the method described above.

Processing 4

The project is using the latest version of Processing 4.0. The binaries are included in the project.

Java 11 is needed to run Processing 4 sketches. Everything else seems to work fine so far.

Libraries

The project uses the following Processing libraries:

Running Sketches with Kotlin

To run a Processing Sketch, you need to run the static PApplet.main() method. This method takes an array of PApplet class names to run. To avoid having to add the main method to every sketch, type the applet class name and change the run configuration every time, there is the SketchLibrary class that contains all sketches with class references.

From Android Studio

The application then needs just a single Run Configuration that launches SketchLibraryKt main class.

fun main() {
    PApplet.main(Bubbles::class.java)
}

Whenever I create a new sketch, I add it to this class and comment the old one out.

From command line

SketchLibraryKt is also set as the main class of Java application Gradle plugin, so the project can be run from the command line:

.gradlew run

Convenience methods

BaseSketch TBD

Sketch Recording + create GIFs

I added a convenience method to my .bash_profile. It takes all .png files in given folder and creates a GIF of the same name.

makegif() {
  name=$1
  framerate=30
  if [[ "$2" ]] then
    framerate=$2
  fi
  ffmpeg -f image2 -pattern_type glob -framerate $framerate -i ${name}'/*.png' $name.gif
}

Then I can go to a location where the folder with captured PNGs is present and run:

makegif bubbles

However, easier way is to use Abe Pazos' VideoExport library

Known issues

FX2D renderer doesn't work

When run with FX2D renderer, the sketch fails to load with:

Caused by: java.lang.ClassNotFoundException: javafx.scene.image.PixelFormat

Looks like a missing library dependency, even though the JavaFx JARs are now included in the project.

About

Processing sketches written in Kotlin, built with Gradle

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published