Skip to content

Instantly share code, notes, and snippets.

@joannecheng
Last active December 5, 2016 23:43
Show Gist options
  • Save joannecheng/7225934 to your computer and use it in GitHub Desktop.
Save joannecheng/7225934 to your computer and use it in GitHub Desktop.
Make Processing sketches with scala on OSX

Setting up Processing for Scala

(on OSX)

  • Install Processing
  • Move Processing.app/ to your preferred destination (mine is in /Applications/)
  • set scala classpath to include your-install-location/Processing.app/Contents/Resources/Java/core/library/core.jar. I created a little runner called run-sketch that looks like this:
export PROCESSING_CLASS_PATH=$CLASSPATH:/Applications/Processing.app/Contents/Resources/Java/core/library/core.jar

scala -cp $PROCESSING_CLASS_PATH $1

In mySketch.scala:

import processing.core._

object MySketch extends PApplet {
  private var mySketch:MySketch = _

  def main() = {
    mySketch = new MySketch

    val frame = new javax.swing.JFrame("MySketch")
    frame.getContentPane().add(mySketch)
    mySketch.init
    
    //setting JFrame size directly, since it doesn't seem to work otherwise.
    frame.setSize(600, 600)

    frame.setVisible(true)
  }
}

// Processing sketch code goes here!
class MySketch extends PApplet {

  // Just like Processing!
  override def setup() = {
  }

  override def draw() ={
  }
}

// PApplet.main(Array[String]) <-- takes arguments and classname in Java
MySketch.main()

I can call ./run-sketch mySketch.scala and view the sketch! Plus I can use my editor of choice and keep up to date with the latest version of Processing.

Horray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment