Get started with Processing in Scala on Ubuntu
I love Processing in a way that’s almost unseemly for a gentleman and a programming language but there’s something about Java that feels, how can I put this, a bit inelegant and crufty. Lots of braces, lots of type declaration and so on. That feeling put me on a search for a way to do cross-platform graphics in a tidier language. The options that I’ve come up with so far are:
I had a bit of a struggle getting started today with Scala so I thought I’d share a quick step by step for Ubuntu:
-
Install Scala:
sudo aptitude install scala
-
Install Processing
-
Create a file Test.scala and add the following:
import processing.core._ object Test extends processing.core.PApplet { override def setup() { size(100, 100) } override def draw() { background(0) rect(10, 10, 10, 10) } def main(args: Array[String]) { var frame = new javax.swing.JFrame("Test") var applet = Test frame.getContentPane().add(applet) applet.init frame.pack frame.setVisible(true) } }
-
Compile it:
scalac -cp [path_to_processing]/lib/core.jar Test.scala
-
Run it:
scala -cp .:[path_to_processing]/lib/core.jar Test
-
Hopefully you should see a window with a black background containing a white rectangle.
I have no idea whether I’m going to like Scala or not (to be honest Python is looking more promising at the moment) but it’ll be interesting to see whether it’s an improvement on straight Java for the kind of code I’m writing.