Intro to Computational Media - HW4

Baby’s first Scala!

428 words

(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.