To use Doodle, add the following to your
libraryDependencies += "org.creativescala" %% "doodle" % "0.10.1"
ScalaDoc covers Doodle’s APIs.
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.all._ // Render to a window using Java2D (must be running in the JVM) import doodle.java2d._ // Need the Cats Effect runtime to run everything import cats.effect.unsafe.implicits.global chessboard.draw()
This creates the picture shown below.
The Scala Plugin of IntelliJ still has an open bug which cannot resolve implicits correctly. The above example might give you an Error warning in Line XX. You can ignore this warning, or fix it using
chessboard.draw[Algebra, Drawing, Frame, Canvas](). Please use any text editor and Metals to get a better experience using Doodle.
Using the Image library is the easiest way to get started drawing with Doodle.
Using the tagless final algebras allows access to features that are specific to a backend.
Understanding core concepts in Doodle will help make sense of the library.
TODO: layout, bounding boxes, and origins; paths; styles; debug
The main packages of Doodle are:
- core, which provides common utilities such as
- animation and interaction
- interactive exploration