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.

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.

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

Interactively construct a Processing sketch

Manipulate a Processing sketch at run-time

Create multiple sketch windows using createSketch()

The Scala REPL supports a command history and tab-completion (allowing quick look up of processing methods)

Tips

newSketch() - will activate a new processing sketch and make its methods visible at the top-level.

createSketch() - create and return a new processing sketch, but does not make its methods visible at the top level.

sp5repl.sp5repl exists as a single source file that can be compiled and used independently of the provided shell scripts. Just make sure the Scala and Processing jars are in your classpath.

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.