Canvas
eff CanvasSourceDrawing, as an effect.
Sketch and game code calls these operations directly, so drawing code reads the way it
would in Processing. What makes that safe is that the effect has two interpretations:
Canvas.runWithCollector turns the calls into data with no window, and the runtime's
handler paints them onto a real sketch. Rendering is therefore testable without a
display.
Operations
Fills the whole canvas with c, erasing the previous frame.
Draws an ellipse centred on (x, y).
Sets a translucent fill, with alpha from 0 (invisible) to 255 (opaque).
Exists so an overlay can dim what is behind it instead of hiding it -- the attract screen draws its title over a live game, and a solid band would cut the formation in half.
Draws a rectangle with its top-left corner at (x, y).
Draws s with its baseline starting at (x, y).
Definitions
Runs f and returns only the draw commands it produced.
Interprets Canvas by recording every drawing operation instead of performing it.
Pure: the accumulator lives in a region that is fully discharged here, so this needs
no IO and opens no window. This is what the rendering tests use.
The handle/runWith pair follows the stdlib's companion-module convention -- see
Logger.flix, which offers seven interpretations of one effect this way. Adding an
eighth interpretation of Canvas means adding a function here, not editing the
runtime.
Replays a list of draw commands through the Canvas effect.
This is the bridge from a pure render : world -> List[DrawCmd] to whichever
handler is currently installed.
def runWithCollector(dims: (Int32, Int32), f: Unit -> a \ ef): (a, List[DrawCmd]) \ ef - Canvas§ SourceRuns f, returning its result together with the draw commands it produced.
Interprets Canvas by discarding every drawing operation.
Deliberately not installed as a @DefaultHandler: with a default in place, a test
that forgot to choose an interpretation would compile and silently assert on a frame
that was never drawn. Leaving Canvas without one keeps that a type error.