[JAVA] Develop Processing with IntelliJ + Kotlin + Gradle

Processing editor is hard to use, Java-like is slightly unpleasant, Anyway, I want to write in Kotlin and manage it in Gradle.

Install Java 8

Because Processing does not work if it is Java 9 or higher https://github.com/processing/processing/wiki/Supported-Platforms#user-content-java-versions

$ brew cask reinstall caskroom/versions/zulu8
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    10.0.2, x86_64:	"Java SE 10.0.2"	/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
    1.8.0_222-zulu-8.40.0.25, x86_64:	"Zulu 8"	/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home

Create a new project

Select Gradle and check Java and Kotlin.

For Project SDK, specify the 1.8 that you just installed.

The rest is along the road

Added Processing to Gradle

build.gradle


dependencies {
    compile group: 'org.processing', name: 'core', version: '3.3.7'
}

Open build.gradle Add processing inside dependencies.

Then the download will start. When the download is complete, it is OK if ʻorg.processing: core is added to ʻExternal Libraries.

Create a program

Create a new Kotlin file in src / main / kotlin.

The file name is Main.tk.

src/main/kotlin/Main.tk


import processing.core.*

class Main : PApplet () {
    fun run() {
        return PApplet.main(Main::class.java.simpleName)
    }
}

fun main() : Unit = Main().run()

It is a super-simple state that describes only the part necessary for processing execution.

Try to run

Run Run MainKt from the triangle that appears next tofun main ().

When executed,

An empty Processing app has run.

Try to implement with Kotlin

Let's try ** Follow 3 ** in Examples in the Processing formula and implement it in Kotlin. https://processing.org/examples/follow3.html

src/main/kotlin/Main.tk


import processing.core.*

class Main : PApplet () {
    var x = FloatArray(20)
    var y = FloatArray(20)
    var segLength = 18

    override fun settings() {
        size(640, 360)
    }

    override fun setup() {
        strokeWeight(9F)
        stroke(255F, 100F)
    }

    override fun draw() {
        background(0f)
        dragSegment(0, mouseX.toFloat(), mouseY.toFloat())
        for (i in 0 until x.size - 1) {
            dragSegment(i + 1, x[i], y[i])
        }
    }

    private fun dragSegment(i: Int, xin: Float, yin: Float) {
        val dx = xin - x[i]
        val dy = yin - y[i]
        val angle = PApplet.atan2(dy, dx)
        x[i] = xin - PApplet.cos(angle) * segLength
        y[i] = yin - PApplet.sin(angle) * segLength
        segment(x[i], y[i], angle)
    }

    private fun segment(x: Float, y: Float, a: Float) {
        pushMatrix()
        translate(x, y)
        rotate(a)
        line(0F, 0F, segLength.toFloat(), 0F)
        popMatrix()
    }

    fun run() {
        return PApplet.main(Main::class.java.simpleName)
    }
}

fun main() : Unit = Main().run()

When you do this

You can see that Processing is working properly.

Add library

If you write in gradle

build.gradle


repositories {
    mavenCentral()
    maven { url "https://clojars.org/repo" }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compile group: 'org.processing', name: 'core', version: '3.3.7'
    compile group: 'ddf.minim', name: 'ddf.minim', version: '2.2.0'
    compile group: 'controlp5', name: 'controlp5', version: '2.2.4'
    compile group: 'de.sojamo', name: 'oscp5', version: '0.9.8'
}

I added clojars.org to the repositories because mavenCentral didn't have ʻoscp5 and controlp5`.

end

You can fight with this.

Recommended Posts

Develop Processing with IntelliJ + Kotlin + Gradle
(IntelliJ + gradle) Hello World with Spring Boot
Christmas with Processing
Use ProGuard with Gradle
Integration Test with Gradle
How to build docker environment with Gradle for intelliJ
Install Gradle with ubuntu16.04
DataNucleus starting with Gradle
Remote debugging with intellij
How to install Gradle and Kotlin with SDKMAN (Mac)
Use WebJars with Gradle
Get started with Gradle
Use jlink with gradle
Java multi-project creation with Gradle
Getting Started with Doma-Annotation Processing
Gradle + Kotlin-Generate jar with DSL
Write Processing in IntelliJ IDEA
Develop C programs with guard
Spring with Kotorin --6 Asynchronous processing
Hot deploy with IntelliJ IDEA
Lombok not working with Gradle5
Develop Arduino with vscode @Ubuntu
Remote debugging with Gradle test
Presentation slides made with Processing
Hello World with SpringBoot / Gradle