Cauldron2D.Render (Cauldron2D v0.2.2)

Copy Markdown View Source

A frame drawn once from a list of operations.

Cauldron2D.Render.render({320, 200}, [
  {:raster, backdrop, {0, 0}},
  {:sprite, knight, %{position: {120.5, 88}, origin: {9, 28}, scale: {-1, 1}}}
], background: {20, 20, 40, 255})

Each operation is drawn by what its shape says it is:

  • {:sprite, picture, placement} — a picture placed as Cauldron2D.Blend.draw/6 takes a placement: position, origin, scale, angle, blend, alpha
  • {:raster, picture, {x, y}} — a picture drawn as it is, its top-left corner at {x, y}

A picture is a FrenchCurve.Raster or {width, height, rgba}. Operations draw in list order, each over what came before.

The frame is made once and drawn in bands of rows, each band drawn by one call that lays every operation over it in place: four bands by default, fewer where there are fewer schedulers. Where the C library is loaded the bands are drawn in C; where it is not, or with native: false, in Elixir, to the same pixels. The number of bands never changes the result.

Options:

  • :background — what the frame starts as: a colour {r, g, b, a}, or a picture the frame's size; default transparent
  • :format — :rgba (default) gives a FrenchCurve.Raster; :rgb gives the pixels as a binary of three bytes each, alpha dropped
  • :bands — how many bands to draw at once
  • :native — false draws in Elixir

Summary

Functions

The frame {width, height} pixels in size with operations drawn on it.

Types

operation()

@type operation() ::
  {:sprite, picture(), map()} | {:raster, picture(), {integer(), integer()}}

picture()

@type picture() :: FrenchCurve.Raster.t() | {pos_integer(), pos_integer(), binary()}

Functions

render(arg, operations, opts \\ [])

@spec render({pos_integer(), pos_integer()}, [operation()], keyword()) ::
  FrenchCurve.Raster.t() | binary()

The frame {width, height} pixels in size with operations drawn on it.