Endlessly repeating...

Get started with Processing in Scala on Ubuntu

12 January 2010

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:

  1. Install Scala:

    sudo aptitude install scala
    
  2. Install Processing
  3. 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)
        }
    }
    
  4. Compile it:

    scalac -cp [path_to_processing]/lib/core.jar Test.scala
    
  5. Run it:

    scala -cp .:[path_to_processing]/lib/core.jar Test
    
  6. 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.