this in a classroom setting at DePauw provided good a reference point for the ... This open source Scala library was a former DePauw University REU project.
SCALES ABSTRACT Aimed at developing a software library to facilitate the teaching of functional programming concepts using Scala in an undergraduate curriculum, this project provides a high-level language to create and manipulate graphics, music, animation, and interactivity. After surveying the successes of similar projects in other languages, and observing the limited ecosystem of existing tools in Scala itself, we sought to integrate the most advantageous features of other libraries into a single, easy-to-use tool.
A MULTIMEDIA LIBRARY FOR TEACHING FUNCTIONAL PROGRAMMING CONCEPTS
Vivian Chen Mervin Fansler Ben Harsha Rudra Vishweshwar
EXAMPLES: THE POWER OF A SIMPLE API
GUIDING PRINCIPLES During the development process we sought to acheive the following goals:
HIGH-LEVEL LANGUAGE
• • • • •
Building upon an existing library called Scales, we: • extended its functionality to include common graphics manipulation procedures • improved upon the existing features, such as primitive construction and compositing • designed a simple, yet powerful expressive API • reduced the boilerplate code required to accomplish basic tasks • wrote documentation and examples The resulting work is to be integrated into an undergraduate course in Fall 2013.
PREVIOUS WORK Kojo1
API OVERVIEW
This example demonstrates the ease with which complex graphics can be generated using recursion, simple transformations, and high-level methods for composing graphics objects. With each iteration a new segment of the spiral (via a Path object) and a colored square are placed beside a rotated copy of the previous iteration. The first iteration is a simple square. FEATURES:
Many of the most common methods in the API are available both as expressive verbs and as intuitive operator-like aliases. This allows for those new to the library to write expressive code, while at the same time providing an avenue for writing more concise, but still readable code as familiarity increases. TRANSFORMATIONS
Figure 1. A Fibonacci Spiral with colored squares in a Fibonacci sequence.
Path Primitive / High-Level Composition / Alignment Methods / Recursive Graphic
This Scala-based learning environment provides an excellent platform to introduce novices to functional programming via multimedia manipulation. Experience with using this in a classroom setting at DePauw provided good a reference point for the advantages of giving students a high-level language with minimal overhead. The imperative form of parts of the API, as well as the lack of professional IDE integration prompted us to seek alternatives.
EFFICIENT FEATURES
Square(10) scale 10
Square(10) -* 10
Square(10) rotate (45 deg)
Square(10) -% (45 deg)
Square(10) translate (20, 50)
Square(10) -+ (20, 50)
STYLES Square(10) fill Colors.Red
Square(10) -* Colors.Red
Square(10) stroke 4
Square(10) -~ 4
ALIGNMENT
Advantages: Mature Multimedia Support / Uses Scala Disadvantages: Limited Extensibility / Imperative API / Isolated Framework
Diagrams2
Square(10) over Circle(20)
Square(10) -& Circle(20)
Square(10) above Circle(20)
Square(10) -^ Circle(20)
Square(10) beside Circle(20)
Square(10) -|| Circle(20)
MUSIC
The Haskell graphics library Diagrams is exemplary of a powerful functional graphics API. With several easy to use compositing and alignment methods, as well as a naming feature which allows one to reference subsets of diagrams even after they are composed, this library inspired some of our core features.
Sequ(C, D)
C + D // note sequence
Para(C, E)
C | E // chord of notes
Sequ(Para(C, E), Para(D, F))
(C | E) + (D | F) // chord seq
Advantages: Purely Functional / Compositing / Identifiers / Documentation Disadvantages: Static Graphics / Haskell Only
Tie3 This Scala graphics library provides an extensive API for manipulating and composing graphics primitives. The concise form of this API inspired some of the aliases used in the Scales 3.0 API. Advantages: Extensive Shortcut API / Open Source Scala Library Disadvantages: Lack of Documentation / Relies Heavily on SVG / No Animation
FUTURE WORK Figure 2. A series of iterations of a Barnsley Fern. Upper-left is the 1st iteration. Upper-right is the 5th iteration. Lower-left is the 10th iteration. Lower-right is the 20th iteration.
This example demonstrates the versatility of the API by showing how arbitrary transformations and conversion from vector to raster graphics (Freeze feature) can be applied to generate complex fractals. The Barnsley Fern is notorious for its slow convergence. Using vector graphics alone, memory limitations would restrict iterations to less than 10.
FEATURES: Freeze (vector to raster conversion) / Low-Level Transforms / Memoization
FUNCTIONAL REACTIVE I/O
Advantages: Simple Interactivity Model / Classroom-Tested Disadvantages: Scheme/Racket Only
Scales 2.05
1 http://www.kogics.net/kojo 2 http://projects.haskell.org/diagrams/ 3 http://tie-illustrates.everything.cloudbees.net/ 4 Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shriram Krishnamurthi. A Functional I/O System or, Fun for Freshman Kids. In ICFP ‘09 Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, pp. 47-58. ACM, 2009. 5
The Scales 2.0 library can be viewed via the git history of the current version: https://github.com/DePauwREU2013/scales/tree/2.0
• • • •
integration of music into the reactive framework building more advanced components to work with the reactive library improving the music API by considering key signature support writing of getting started guides and tutorials to further accessibility gathering feedback from using the library in a classroom setting
The library is an open source project on GitHub. To explore the library and demos, or provide feedback on the project you can visit:
A framework developed specifically for educational purposes, this functional I/O system for DrRacket provides an approachable animations and interactivity model that has had success in Middle School through Undergraduate settings. In its earliest form, our `ReactivePanel` class was a direct implementation of this model.
Advantages: Multimedia Support / Open Source Scala Library Disadvantages: Limited Primitive Support / Undocumented / Verbose API
This project has a great potential for future work which includes:
•
Functional I/O System (Felleisen, et al.)4
This open source Scala library was a former DePauw University REU project. With support for basic graphics, animation, and music synthesis, this multimedia library provided a solid foundation on which to build.
implement a tasteful design of a domain-specific language (DSL) provide a consistent functional style throughout avoid and discourage the use of mutable data craft a unified language for handling graphics, animation, and music leverage abstraction to reduce boilerplate code
SCALES
DEMOS
https://github.com/DePauwREU2013/scales
https://github.com/DePauwREU2013/scalesdemo
ACKNOWLEDGEMENTS Figure 3. An animated analog clock which displays the user’s local time.
This examples highlights the reactive animation and interactivity functionality provided via the ReactivePanel object. With an adjustable frame rate and efficiently designed to refresh only on state transformations, this finite state machine infrastructure provides a powerful ability to bring graphics to life as animations. In addition to frame/ time-based animation, the ReactivePanel allows users to define state transitions in reaction to mouse and keyboard inputs. FEATURES: Functional Reactive Animation / User Interactivity / Efficient Rendering
We would like to thank the following people and organizations for their support in the successful completion of this project: Professor Brian Howard Science Research Fellows Program Computer Science Department National Science Foundation This project made possible by NSF REU Grant #CNS-1156893.