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 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
Values
pub fn arc(radius: Float, start: Angle, end: Angle) -> Picture
An arc with some radius going from some starting angle to some other angle in clock-wise direction
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 fill(picture: Picture, colour: colour.Colour) -> Picture
Fill a picture with some given colour, see Colour.
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 lines(points: List(#(Float, Float))) -> Picture
Lines (same as a polygon but not a closed shape)
pub fn polygon(points: List(#(Float, Float))) -> Picture
A polygon consisting of a list of 2d points
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 stroke(
picture: Picture,
colour: colour.Colour,
width width: Float,
) -> Picture
Set a solid stroke with some given colour and width
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