Java2D Backend

The Java2D backend draws Doodle pictures using Java 2D, the graphic library that ships with the JVM.

Usage

Firstly, import the Doodle core and syntax, the Java2D definitions, and the default Cats Effect runtime.

import cats.effect.unsafe.implicits.global
import doodle.core.*
import doodle.java2d.*
import doodle.syntax.all.*

Now you can draw Pictures like so:

Picture.circle(100).draw()

The drawing will appear in a window on the screen.

You can define a Frame to have more control over the appearance of the window in which a Picture is drawn. The Frame allows you to specify, for example, the title for the window, the background color, or the size of the window. Here's an example:

val frame =
  Frame.default
    .withSize(600, 600)
    .withCenterAtOrigin
    .withBackground(Color.midnightBlue)
    .withTitle("Oodles of Doodles!")

This sets:

We can drawn to a frame using the drawWithFrame syntax.

Picture.circle(100).drawWithFrame(frame)

Canvas

The Java2D Canvas offers several features that are useful for interactive programs. It provides the following streams of events:

Also available are

To create a Canvas you call the canvas() method on a Frame. The returns a Resource that will produce the canvas when used. Here's a small example:

frame
  .canvas()
  .use { canvas =>
    // Do stuff here
    // This example just closes the canvas
    canvas.close()
  }

`

SVG Backend→