paint

This module contains the main Picture type as well as the function you can use to construct, modify and combine pictures.

Types

An angle in clock-wise direction. See: angle_rad and angle_deg.

pub type Angle =
  @internal Angle

A rexport of the Colour type from gleam_community/colour. Paint also includes the functions colour_hex and colour_rgb to easily construct Colours, but feel free to import the gleam_community/colour module and use the many utility that are provided from there.

pub type Colour =
  colour.Colour

A 2D picture. This is the type which this entire library revolves around.

Unless you intend to author a new backend you should consider this type opaque and never use any of its constructors. Instead, make use of the many utility functions defined in this module (circle, combine, fill, etc.)

pub type Picture =
  @internal Picture
pub type Vec2 =
  #(Float, Float)

Values

pub fn angle_deg(degrees: Float) -> @internal Angle

Create an angle expressed in degrees

pub fn angle_rad(radians: Float) -> @internal Angle

Create an angle expressed in radians

pub fn arc(
  radius: Float,
  start: @internal Angle,
  end: @internal Angle,
) -> @internal Picture

An arc with some radius going from some starting angle to some other angle in clock-wise direction

pub fn blank() -> @internal Picture

A blank image

pub fn circle(radius: Float) -> @internal Picture

A circle with some given radius

pub fn colour_hex(string: String) -> colour.Colour

A utility around colour.from_rgb_hex_string (from gleam_community/colour) that panics on an invalid hex code.

pub fn colour_rgb(
  red: Int,
  green: Int,
  blue: Int,
) -> colour.Colour

A utility around colour.from_rgb255 (from gleam_community/colour) that panics if the values are outside of the allowed range.

pub fn combine(
  pictures: List(@internal Picture),
) -> @internal Picture

Combine multiple pictures into one

pub fn concat(
  picture: @internal Picture,
  another_picture: @internal Picture,
) -> @internal Picture

Concatenate two pictures

pub fn fill(
  picture: @internal Picture,
  colour: colour.Colour,
) -> @internal Picture

Fill a picture with some given colour, see Colour.

pub fn just(
  picture: @internal Picture,
) -> fn(a) -> @internal Picture

Utility function that is useful for cases where you are no interested in the canvas configuration. For example,

canvas.display(just(circle(30.0)), "#my_canvas")
// instead of...
canvas.display(fn(_config) { circle(30.0) }, "#my_canvas")
pub fn lines(points: List(#(Float, Float))) -> @internal Picture

Lines (same as a polygon but not a closed shape)

pub fn polygon(
  points: List(#(Float, Float)),
) -> @internal Picture

A polygon consisting of a list of 2d points

pub fn rectangle(
  width: Float,
  height: Float,
) -> @internal Picture

A rectangle with some given width and height

pub fn rotate(
  picture: @internal Picture,
  angle: @internal Angle,
) -> @internal Picture

Rotate the picture in a clock-wise direction

pub fn scale_uniform(
  picture: @internal Picture,
  factor: Float,
) -> @internal Picture

Scale the picture uniformly in horizontal and vertical direction

pub fn scale_x(
  picture: @internal Picture,
  factor: Float,
) -> @internal Picture

Scale the picture in the horizontal direction

pub fn scale_y(
  picture: @internal Picture,
  factor: Float,
) -> @internal Picture

Scale the picture in the vertical direction

pub fn square(length: Float) -> @internal Picture

A square

pub fn stroke(
  picture: @internal Picture,
  colour: colour.Colour,
  width width: Float,
) -> @internal Picture

Set a solid stroke with some given colour and width

pub fn stroke_none(
  picture: @internal Picture,
) -> @internal Picture

Remove the stroke of the given picture

pub fn text(text: String, px font_size: Int) -> @internal Picture

Text with some given font size

pub fn translate_x(
  picture: @internal Picture,
  x: Float,
) -> @internal Picture

Translate a picture in the horizontal direction

pub fn translate_xy(
  picture: @internal Picture,
  x: Float,
  y: Float,
) -> @internal Picture

Translate a picture in horizontal and vertical direction

pub fn translate_y(
  picture: @internal Picture,
  y: Float,
) -> @internal Picture

Translate a picture in the vertical direction

Search Document