FrenchCurve.Draw (FrenchCurve v0.1.3)

Copy Markdown View Source

Rasterises lines, rectangles and circles into a FrenchCurve.Raster.

Every function takes a raster as its first argument and returns a new one, so calls compose in a pipeline. Coordinates are integer pixels, {0, 0} at the top left, and may fall outside the raster: the parts that land inside are drawn and the rest is clipped. Colours are {r, g, b, a} byte tuples written opaquely, with no blending against what is already there.

FrenchCurve.Raster.new(40, 20)
|> FrenchCurve.Draw.rect({0, 0}, {39, 19}, {80, 80, 80, 255})
|> FrenchCurve.Draw.fill_circle({20, 10}, 6, {255, 0, 0, 255})

Summary

Functions

Draws a one-pixel-wide circle outline of radius pixels around the centre {cx, cy}.

Fills a disc of radius pixels around the centre {cx, cy}.

Fills every pixel of the rectangle spanned by two opposite corners, edges included.

Draws a one-pixel-wide line between the two endpoints, both inclusive.

Draws a connected run of line segments through points in order.

Draws the four edges of the rectangle spanned by two opposite corners.

Types

coord()

@type coord() :: {integer(), integer()}

Functions

circle(raster, arg, radius, color)

Draws a one-pixel-wide circle outline of radius pixels around the centre {cx, cy}.

radius must be a non-negative integer. The interior is untouched.

fill_circle(raster, arg, radius, color)

Fills a disc of radius pixels around the centre {cx, cy}.

radius must be a non-negative integer.

fill_rect(raster, arg1, arg2, color)

Fills every pixel of the rectangle spanned by two opposite corners, edges included.

Both corners are inclusive and may be given in any order.

line(raster, arg1, arg2, color)

Draws a one-pixel-wide line between the two endpoints, both inclusive.

Handles any direction, including purely horizontal, vertical and single-point lines.

polyline(raster, list, color)

Draws a connected run of line segments through points in order.

A single point plots that pixel and an empty list leaves the raster unchanged. Points are not closed back to the first one; pass the first point again to close the shape.

rect(raster, arg1, arg2, color)

Draws the four edges of the rectangle spanned by two opposite corners.

Both corners are inclusive and may be given in any order. The interior is untouched.