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_implementation.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_implementation.Picture
Functions
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
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
A utility around colour.from_rgb255
(from gleam_community/colour
) that panics if the values are outside of the allowed range.
pub fn concat(
picture: Picture,
another_picture: Picture,
) -> Picture
Concatenate two pictures
pub fn fill(picture: Picture, colour: Colour) -> Picture
Fill a picture with some given colour, see Colour
.
pub fn just(picture: Picture) -> fn(a) -> 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))) -> 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,
width width: Float,
) -> Picture
Set a solid stroke with some given colour and width
pub fn stroke_none(picture: Picture) -> Picture
Remove the stroke of the given 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