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 reference to an image (i.e. a texture), not to be confused with the Picture type. To create an image, see the image functions in the canvas back-end.

pub type Image =
  @internal Image

A segment from a 2D path.

Unless you intend to author a new backend you should consider this type opaque and never use any of its constructors. Instead, make use the functions with the path_ prefix.

pub type PathSegment =
  @internal PathSegment

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 RotationDirection {
  Clockwise
  Counterclockwise
}

Constructors

  • Clockwise
  • Counterclockwise

Horizontal alignment for text. See text_align.

pub type TextAlign {
  TextAlignStart
  TextAlignEnd
  TextAlignLeft
  TextAlignRight
  TextAlignCenter
}

Constructors

  • TextAlignStart

    The text is aligned at the normal start of the line (left-aligned for left-to-right locales, right-aligned for right-to-left locales).

  • TextAlignEnd

    The text is aligned at the normal end of the line (right-aligned for left-to-right locales, left-aligned for right-to-left locales).

  • TextAlignLeft

    The text is left-aligned.

  • TextAlignRight

    The text is right-aligned.

  • TextAlignCenter

    The text is centered.

Vertical baseline for text. See text_baseline.

pub type TextBaseline {
  TextBaselineTop
  TextBaselineHanging
  TextBaselineMiddle
  TextBaselineAlphabetic
  TextBaselineIdeographic
  TextBaselineBottom
}

Constructors

  • TextBaselineTop

    The text baseline is the top of the em square.

  • TextBaselineHanging

    The text baseline is the hanging baseline. (Used by Tibetan and other Indic scripts.)

  • TextBaselineMiddle

    The text baseline is the middle of the em square.

  • TextBaselineAlphabetic

    The text baseline is the normal alphabetic baseline. Default value.

  • TextBaselineIdeographic

    The text baseline is the ideographic baseline; this is the bottom of the body of the characters, if the main body of characters protrudes beneath the alphabetic baseline. (Used by Chinese, Japanese, and Korean scripts.)

  • TextBaselineBottom

    The text baseline is the bottom of the bounding box. This differs from the ideographic baseline in that the ideographic baseline doesn’t consider descenders.

Writing direction for text. See text_direction.

pub type TextDirection {
  TextDirectionLtr
  TextDirectionRtl
  Inherit
}

Constructors

  • TextDirectionLtr

    Left to right

  • TextDirectionRtl

    Right to left

  • Inherit

    Inherited

pub type Vec2 =
  #(Float, Float)

Values

pub fn angle_deg(degrees: Float) -> Angle

Create an angle expressed in degrees

pub fn angle_rad(radians: Float) -> Angle

Create an angle expressed in radians

pub fn arc(
  radius: Float,
  start: Angle,
  end: Angle,
  direction: RotationDirection,
) -> Picture

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

pub fn blank() -> Picture

A blank picture

pub fn circle(radius: Float) -> 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(Picture)) -> Picture

Combine multiple pictures into one

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

Concatenate two pictures

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

Fill a picture with some given colour, see Colour.

pub fn font_family(picture: Picture, family: String) -> Picture

Set the font family used to render text inside the picture.

pub fn image(
  image: Image,
  width_px width_px: Int,
  height_px height_px: Int,
) -> Picture

Draw an image such as a PNG, JPEG or an SVG. See the canvas back-end for more details on how to load images.

pub fn image_scaling_pixelated(picture: Picture) -> Picture

Disable smooth image scaling, suitable for pixel art.

pub fn image_scaling_smooth(picture: Picture) -> Picture

Set image scaling to be smooth (this is the default behaviour)

pub fn path(
  start: #(Float, Float),
  segments: List(PathSegment),
) -> Picture

A path

pub fn path_arc_centre(
  centre centre: #(Float, Float),
  radius radius: Float,
  start_angle start_angle: Angle,
  end_angle end_angle: Angle,
  direction direction: RotationDirection,
) -> PathSegment

Arc in path, defined as centre and start/end angles

pub fn path_arc_corner(
  corner corner: #(Float, Float),
  end end: #(Float, Float),
  radius radius: Float,
) -> PathSegment

Arc in path, defined as corner point and end point

pub fn path_bezier(
  cp1 cp1: #(Float, Float),
  cp2 cp2: #(Float, Float),
  end end: #(Float, Float),
) -> PathSegment

Bezier curve in path

pub fn path_line(to: #(Float, Float)) -> PathSegment

Line to in path

pub fn path_move(to: #(Float, Float)) -> PathSegment

Move to in path

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

A rectangle with some given width and height

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

Rotate the picture in a clock-wise direction

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

Scale the picture uniformly in horizontal and vertical direction

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

Scale the picture in the horizontal direction

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

Scale the picture in the vertical direction

pub fn square(length: Float) -> Picture

A square

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

Set a solid stroke with some given colour and width

pub fn stroke_dashed(
  picture: Picture,
  colour: colour.Colour,
  width width: Float,
  dashes dashes: List(Float),
) -> Picture

Set a dashed stroke with some given colour and width

pub fn stroke_none(picture: Picture) -> Picture

Remove the stroke of the given picture

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

Text with some given font size

pub fn text_align(
  picture: Picture,
  alignment: TextAlign,
) -> Picture

Set the horizontal text alignment used to render text inside the picture.

pub fn text_baseline(
  picture: Picture,
  baseline: TextBaseline,
) -> Picture

Set the vertical text baseline used to render text inside the picture.

pub fn text_direction(
  picture: Picture,
  direction: TextDirection,
) -> Picture

Set the writing direction used to render text inside the picture.

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

Translate a picture in the horizontal direction

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

Translate a picture in horizontal and vertical direction

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

Translate a picture in the vertical direction

Search Document