Doodle

Doodle is a library for 2D graphics. It runs in both the JVM, rendering via Java2D, and the web browser using SVG.

Doodle provides a simple to use DSL, called Image. This DSL is in turn built on tagless final algebras. The tagless final algebras allow Doodle to support features that are not available across all backends (addressing the so-called expression problem). Doodle also provides libraries for animation and other utilties.

Getting Started

To use Doodle, add to your build.sbt

libraryDependencies += "org.creativescala" %% "doodle" % "0.9.2"

ScalaDoc

ScalaDoc is here

Quick Example

The following example creates a Chessboard, by first creating a 2x2 board, then a 4x4 board from the 2x2 board, and finally the complete 8x8 board from the 4x4 board.

// The "Image" DSL is the easiest way to create images
import doodle.image._
// Colors and other useful stuff
import doodle.core._

val blackSquare = Image.rectangle(30, 30).fillColor(Color.black)
val redSquare = Image.rectangle(30, 30).fillColor(Color.red)

// A chessboard, broken into steps showing the recursive construction
val twoByTwo =
  (redSquare.beside(blackSquare))
    .above(blackSquare.beside(redSquare))

val fourByFour =
  (twoByTwo.beside(twoByTwo))
    .above(twoByTwo.beside(twoByTwo))

val chessboard =
  (fourByFour.beside(fourByFour))
    .above(fourByFour.beside(fourByFour))

To draw these Images call the draw method like so

// Extension methods
import doodle.image.syntax._
// Render to a window using Java2D (must be running in the JVM)
import doodle.java2d._

chessboard.draw()

Library Overview

The main packages of Doodle are:

The source code for this page can be found here.