(Sorry for the late post – I was hoping to find a better way to post this online, but no luck so far.)
I had been wanting to try a programming language called Scala for a while, and recently there were a few posts on the Coderspiel blog about a Scala fork for the Processing Development Environment. I decided to take this weeks ICM assignment as an opportunity to try it out. Jorge Ortiz, a friend and Scala programmer extraordinaire, deserves immense credit for teaching me much about the new language and helping me resolve various issues.
For the second Coderspiel post, n8an rewrote Flocking (a simple emergent behavior simulation) in Scala, basing his work on a Processing applet written by my ICM instructor Daniel Shiffman. I based my work off of n8an’s Scala code, worked through everything carefully to get a feel for it, and added a couple of modifications (more on those in a minute). I worked in Eclipse (rather than the Spde that Coderspiel made available), and this was helpful for dealing with the syntax of a new language and a project with multiple classes, but I ran into problems trying to export my applet. I was able to use the Fat Jar Eclipse plugin (being sure to have both core.jar and scala-library.jar added to my build path) and a couple of semi-hacks recommended by Jorge (scroll to the end of Flocking.scala) to get a working applet. The Scala library jar is ~3.5mb and Fat Jar incorporates the entire thing, and this made my applet much bigger than it needed to be, so I tried to use ProGuard (as recommended by Coderspiel) to shrink it down. I couldn’t get this to give me a jar file that I could run, and I also couldn’t get the larger jar file to display in a browser. I needed to move on to other things, and hopefully I can get it working later.
The first modification I made to Flocking was the introduction of multiple species (represented by color). Boids only flock with members of the same species, and they steer away from members of other species. The second modification was collission detection – when two boids collide (because they were unable to turn quickly enough), both boids are removed from the screen, and there is a quickly shrinking ‘poof’ to represent the collision.

Right click and save this jar to try it out, and let me know if you have any questions about the code.
- Flocking_solo.jar (click to make new boids)
- Flocking.scala
- Flock.scala
- Boid.scala
- Poofs.scala
- Poof.scala
- Vector.scala

n8 | 13-Oct-08 at 4:23 pm | Permalink
Hi, sorry I wasn’t able to get back to you on my own post. The truth is I know very little about ProGuard, only enough to get it running with Spde through a painful session of trial and error. And I’d like for Spde to be the best place to learn Scala and Processing, of course!
One idea is to integrate it with the Scala interpreter, so people have instant feedback on their code, and provide some kind of live API browser. I think we can get the best parts of code completion and incremental compilation, as learning tools, that way.
Lehrblogger | 15-Oct-08 at 2:32 am | Permalink
I had a similar experience with ProGuard, and ultimately decided it wasn’t worth worrying about any more. I initially tried to get Scala and Processing working in Eclipse because I’m more used to it as an IDE and found the error checking helpful for learning Scala syntax. Spde has worked very smoothly for the stuff I’ve done since though.
Ive found the interpreter useful for getting the hang of things, but new programmers might find the Terminal command line somewhat intimidating, and that’s a great idea to integrate it in Spde.
I’m going to be showing Spde to a few friends at ITP next week – thanks again!
Lehrblogger | 27-Oct-08 at 5:43 pm | Permalink
A funny flocking story -
http://www.flight404.com/blog/?p=135