sp5repl

A Scala Read-Eval-Processing Loop


sp5repl is a small layer around Scala and Processing that allows you to write Processing sketches dynamically using an interactive read-eval-loop. The code entered into the Scala REPL is actually compiled, thus it runs at full speed; we get most of the flexibility of Jython and Clojure/Quil with the speed and error checking of Scala. It has been tested on Mac OSX and Ubuntu.

Getting Started

web: http://drablab.org/sp5repl/
bitbucket: https://bitbucket.org/keithohara/sp5repl/
download: https://bitbucket.org/keithohara/sp5repl/downloads/sp5repl.tgz

Currently three tools are provided:

Some examples:

 >./sp5repl
 sp5repl>size(600, 600) 
 sp5repl>background(24) 
 sp5repl>smooth() 
 sp5repl>fill(196, 128, 64)
 sp5repl>ellipse(width/2, height/2, 150, 150)    
 sp5repl>fill(64, 128, 196)
 sp5repl>for (i <- width to 0 by -1) ellipse(random(i), i, i/20, i/20)

The above example shows how to create a sketch line by line. It creates an 600 by 600 window with a dark gray background. Smooth drawing is enabled and orange is used as the fill color. One large ellipse is drawn in the center of the screen along with many randomly placed blue circles.

 >./sp5repl examples/draw.sp5   
 sp5repl>stroke(255, 0, 0)    

This code runs one of the provided drawing examples and changes the line color dynamically while the sketch is running.

 >./sp5repl examples/draw.sp5   
 sp5repl>noStroke()           
 sp5repl>(64, 128, 196)      
 sp5repl>def drawEllipse() = ellipse(mouseX, mouseY, 5, 5)                                    
 sp5repl>onMouseDragged(drawEllipse)                                    

Like the previous example, this code runs one of the provided drawing programs and changes the line color dynamically. In addition, the drawing method is changed to draw ellipses while the sketch is running.

The Good

The Bad

The Ugly

Tips

Motivation

I teach two introductory computing classes: one using Python (IPRE's Calico) and robots and the other with Processing. This project was an attempt to build a tool that leverages the best of both of these worlds.

Python's interactive read-eval-print loop (REPL) is helpful for students building an intuition for programming. More generally, the REPL is useful for quick calculations, debuggin, prototyping, and testing. Python's easy-to-use lists, dictionaries, and libraries make many tasks simple enough for CS-1, e.g., slurping in files and doing text analysis. Python's dynamic typing and syntax make programs succinct and there is little boilerplate code.

On the other hand, Python can be quite slow, making things like image processing in Python problematic. Image processing tasks like convolution are no problem in Processing because it compiles to Java. Along with the large collection of libraries, and the great community around Processing, it is a pretty good choice for introducing computing. In my experience, students were able to write really interesting programs in one semester. Sadly it is still Java -- which in my experience teaching introductory students, has lots of baggage compared with Python. Java's obtuse syntax due to its type system, lack of operator overloading, and semicolons confuse introductory students.

Personally, so far anyway, I have found Scala to be a nice statically typed replacement for Python. The curly brace delimited blocks aren't as common since everything is an expression. The type inference removes lots of redundancy. And of course, the higher-order functions and for comprehensions make programs pretty. I hope to try it out in an introductory course next year.

Keith O'Hara

Jan 2013

sp5repl>