Functions
degrees
degrees(radians) -> float
- radians
float
float
- Degrees.
radians
radians(degrees) -> float
- degrees
float
float
- Radians.
point
point(x, y) -> struct<context.Point>
- x
float
- y
float
distance
distance(p1, p2) -> float
- p1
struct<context.Point>
- p2
struct<context.Point>
float
interpolate
interpolate(p1, p2, t) -> struct<context.Point>
- p1
struct<context.Point>
- p2
struct<context.Point>
- t
float
struct<context.Point>
new
new(width, height) -> int<collection.CONTEXT>
- width
int
- height
int
new_image
new_image(id) -> int<collection.CONTEXT>
- id
int<collection.IMAGE>
int<collection.CONTEXT>
new_direct
new_direct(id) -> int<collection.CONTEXT>
Creates a new context directly on the image, this requires the image to use the RGBA color model. If not it will be converted to RGBA. This is also not thread safe, as modifying either the image or the context will affect the other, with no guarantee of the order of operations.
- id
int<collection.IMAGE>
int<collection.CONTEXT>
to_image
to_image(id, name, encoding, model?, copy?) -> int<collection.IMAGE>
- id
int<collection.CONTEXT>
- name
string
- encoding
int<image.Encoding>
- model
int<image.Model>
- copy
bool
- Set to true to copy the image, otherwise continuing to draw can affect the image.
int<collection.IMAGE>
to_mask
to_mask(id, name, encoding) -> int<collection.IMAGE>
- id
int<collection.CONTEXT>
- name
string
- encoding
int<image.Encoding>
int<collection.IMAGE>
- The returned image will use the 'image.MODEL_ALPHA' color model.
mask
mask(id, img)
The image will be copied and converted to 'image.MODEL_ALPHA'.
- id
int<collection.CONTEXT>
- img
int<collection.IMAGE>
size
size(id) -> int, int
@blocking
- id
int<collection.CONTEXT>
int
- The width of the context.int
- The height of the context.
font_height
font_height(id) -> float
@blocking
- id
int<collection.CONTEXT>
float
- The height of text rendered with the current font.
string_measure
string_measure(id, str) -> float, float
@blocking
- id
int<collection.CONTEXT>
- str
string
float
- The width of text rendered with the current font.float
- The height of text rendered with the current font.
string_measure_multiline
string_measure_multiline(id, str, spacing) -> float, float
@blocking
- id
int<collection.CONTEXT>
- str
string
- spacing
float
- The space between each line.
float
- The width of text rendered with the current font.float
- The height of text rendered with the current font.
current_point
current_point(id) -> float, float, bool
@blocking
- id
int<collection.CONTEXT>
float
- The x location of the current point.float
- The y location of the current point.bool
- If the current point has been set.
transform_point
transform_point(id, x, y) -> float, float
@blocking
Multiplies a point by the current matrix.
- id
int<collection.CONTEXT>
- x
float
- y
float
float
-> New x position.float
-> New y position.
clear
clear(id)
Fills the context with the current color.
- id
int<collection.CONTEXT>
clip
clip(id, preserve?)
Updates the clipping region by intersecting the current clipping region with the current path as it would be filled by fill().
- id
int<collection.CONTEXT>
- preserve
bool
- Set in order to keep the current path.
clip_reset
clip_reset(id)
Clears the clipping region.
- id
int<collection.CONTEXT>
path_clear
path_clear(id)
Removes all points from the current path.
- id
int<collection.CONTEXT>
path_close
path_close(id)
Adds a line segment from the current point to the initial point.
- id
int<collection.CONTEXT>
path_to
path_to(id, x, y)
Starts a new subpath starting at the given point.
- id
int<collection.CONTEXT>
- x
float
- y
float
subpath
subpath(id)
Starts a new subpath starting at the current point. No current point will be set after.
- id
int<collection.CONTEXT>
draw_cubic
draw_cubic(id, x1, y1, x2, y2, x3, y3)
Draws a cubic bezier curve to the path starting at the current point, if there isn't a current point, it moves to (x1, y1).
- id
int<collection.CONTEXT>
- x1
float
- y1
float
- x2
float
- y2
float
- x3
float
- y3
float
draw_quadratic
draw_quadratic(id, x1, y1, x2, y2)
Draws a quadratic bezier curve to the path starting at the current point, if there isn't a current point, it moves to (x1, y1).
- id
int<collection.CONTEXT>
- x1
float
- y1
float
- x2
float
- y2
float
draw_arc
draw_arc(id, x, y, r, angle1, angle2)
- id
int<collection.CONTEXT>
- x
float
- y
float
- r
float
- angle1
float
- angle2
float
draw_circle
draw_circle(id, x, y, r)
- id
int<collection.CONTEXT>
- x
float
- y
float
- r
float
draw_ellipse
draw_ellipse(id, x, y, rx, xy)
- id
int<collection.CONTEXT>
- x
float
- y
float
- rx
float
- ry
float
draw_elliptical_arc
draw_elliptical_arc(id, x, y, rx, ry, angle1, angle2)
- id
int<collection.CONTEXT>
- x
float
- y
float
- rx
float
- ry
float
- angle1
float
- angle2
float
draw_image
draw_image(id, img, x, y)
- id
int<collection.CONTEXT>
- img
int<collection.IMAGE>
- x
int
- y
int
draw_image_anchor
draw_image_anchor(id, img, x, y, ax, ay)
The anchor is a point between (0,0) and (1,1), so (0.5,0.5) is centered.
- id
int<collection.CONTEXT>
- img
int<collection.IMAGE>
- x
int
- y
int
- ax
float
- ay
float
draw_line
draw_line(id, x1, y1, x2, y2)
- id
int<collection.CONTEXT>
- x1
float
- y1
float
- x2
float
- y2
float
draw_line_to
draw_line_to(id, x, y)
Draws a line to the point, starting from the current point. If there is no current point, no line will be drawn and the current point will be set.
- id
int<collection.CONTEXT>
- x
float
- y
float
draw_point
draw_point(id, x, y, r)
Similar to draw_circle but ensures that a circle of the specified size is drawn regardless of the current transformation matrix. The position is still transformed, but not the shape of the point.
- id
int<collection.CONTEXT>
- x
float
- y
float
- r
float
draw_rect
draw_rect(id, x, y, width, height)
- id
int<collection.CONTEXT>
- x
float
- y
float
- width
float
- height
float
draw_rect_round
draw_rect_round(id, x, y, width, height, r)
- id
int<collection.CONTEXT>
- x
float
- y
float
- width
float
- height
float
- r
float
draw_polygon
draw_polygon(id, n, x, y, r, rotation)
- id
int<collection.CONTEXT>
- n
int
- The number of sides. - x
float
- y
float
- r
float
- rotation
float
draw_string
draw_string(id, str, x, y)
- id
int<collection.CONTEXT>
- str
string
- x
float
- y
float
draw_string_anchor
draw_string_anchor(id, str, x, y, ax, ay)
The anchor is a point between (0,0) and (1,1), so (0.5,0.5) is centered.
- id
int<collection.CONTEXT>
- str
string
- x
float
- y
float
- ax
float
- ay
float
draw_string_wrap
draw_string_wrap(id, str, x, y, ax, ay, width, spacing, align)
The anchor is a point between (0,0) and (1,1), so (0.5,0.5) is centered.
- id
int<collection.CONTEXT>
- str
string
- x
float
- y
float
- ax
float
- ay
float
- width
float
- spacing
float
- The spacing between each line. - align
int<context.Align>
fill
fill(id, preserve?)
Fills the current path with the current color. Closes open paths.
- id
int<collection.CONTEXT>
- preserve
bool
- Set in order to keep the current path.
fill_rule
fill_rule(id, rule)
- id
int<collection.CONTEXT>
- rule
int<context.FillRule>
stroke
stroke(id, preserve?)
Strokes the current path with the current color.
- id
int<collection.CONTEXT>
- preserve
bool
- Set in order to keep the current path.
identity
identity(id)
Resets the current transformation matrix to the identity matrix.
- id
int<collection.CONTEXT>
mask_invert
mask_invert(id)
Inverts the alpha values of the clipping mask.
- id
int<collection.CONTEXT>
invert_y
invert_y(id)
Flips the y axis so that Y=0 is at the bottom of the image.
- id
int<collection.CONTEXT>
push
push(id)
Push the current context state to the stack.
- id
int<collection.CONTEXT>
pop
pop(id)
Pop the current context state to the stack.
- id
int<collection.CONTEXT>
rotate
rotate(id, angle)
Rotates the transformation matrix around the origin.
- id
int<collection.CONTEXT>
- angle
float
rotate_about
rotate_about(id, angle, x, y)
Rotates the transformation matrix around the point.
- id
int<collection.CONTEXT>
- angle
float
- x
float
- y
float
scale
scale(id, x, y)
Scales the transformation matrix by a factor.
- id
int<collection.CONTEXT>
- x
float
- y
float
scale_about
scale_about(id, sx, sy, x, y)
Scales the transformation matrix by a factor (sx,sy) starting at the point (x,y).
- id
int<collection.CONTEXT>
- sx
float
- sy
float
- x
float
- y
float
color_hex
color_hex(id, hex)
Supports hex colors in the follow formats: #RGB #RRGGBB #RRGGBBAA. The leading # is optional.
- id
int<collection.CONTEXT>
- hex
string
color
color(id, color)
- id
int<collection.CONTEXT>
- color
struct<image.Color>
color_rgb
color_rgb(id, r, g, b)
Float values for r,g,b between 0 and 1.
- id
int<collection.CONTEXT>
- r
float
- g
float
- b
float
color_rgb255
color_rgb255(id, r, g, b)
Interger values for r,g,b between 0 and 255.
- id
int<collection.CONTEXT>
- r
int
- g
int
- b
int
color_rgba
color_rgba(id, r, g, b, a)
Float values for r,g,b,a between 0 and 1.
- id
int<collection.CONTEXT>
- r
float
- g
float
- b
float
- a
float
color_rgba255
color_rgba255(id, r, g, b, a)
Interger values for r,g,b,a between 0 and 255.
- id
int<collection.CONTEXT>
- r
int
- g
int
- b
int
- a
int
dash_set
dash_set(id, pattern)
Sets the dash pattern to use. Call with empty array to disable dashes.
- id
int<collection.CONTEXT>
- pattern
[]float
- Each float value is a dash with a length of the value.
dash_set_offset
dash_set_offset(id, offset)
The initial offset for the dash pattern.
- id
int<collection.CONTEXT>
- offset
float
line_cap
line_cap(id, cap)
- id
int<collection.CONTEXT>
- cap
int<context.LineCap>
line_join
line_join(id, join)
- id
int<collection.CONTEXT>
- join
int<context.LineJoin>
line_width
line_width(id, width)
- id
int<collection.CONTEXT>
- width
float
pixel_set
pixel_set(id, x, y)
Sets a pixel to the current color.
- id
int<collection.CONTEXT>
- x
int
- y
int
shear
shear(id, x, y)
Updates the current matrix with a shearing angle, at the origin.
- id
int<collection.CONTEXT>
- x
float
- y
float
shear_about
shear_about(id, sx, sy, x, y)
Updates the current matrix with a shearing angle (sx,sy), at the given point (x,y).
- id
int<collection.CONTEXT>
- sx
float
- sy
float
- x
float
- y
float
translate
translate(id, x, y)
Updates the current matrix with a translation.
- id
int<collection.CONTEXT>
- x
float
- y
float
word_wrap
word_wrap(id, str, width) -> []string
@blocking
- id
int<collection.CONTEXT>
- str
string
- width
float
[]string
- The original string split into line breaks at the set width.
matrix_new
matrix_new(xx, yx, xy, yy, x0, y0) -> struct<context.Matrix>
- xx
float
- yx
float
- xy
float
- yy
float
- x0
float
- y0
float
struct<context.Matrix>
matrix_identity
matrix_identity() -> struct<context.Matrix>
struct<context.Matrix>
matrix_rotate
matrix_rotate(angle) -> struct<context.Matrix>
- angle
float
struct<context.Matrix>
matrix_scale
matrix_scale(x, y) -> struct<context.Matrix>
- x
float
- y
float
struct<context.Matrix>
matrix_shear
matrix_shear(x, y) -> struct<context.Matrix>
- x
float
- y
float
struct<context.Matrix>
matrix_translate
matrix_translate(x, y) -> struct<context.Matrix>
- x
float
- y
float
struct<context.Matrix>
point_cubic_bezier
point_cubic_bezier(x0, y0, x1, y1, x2, y2, x3, y3) -> []struct<context.Point>
- x0
float
- y0
float
- x1
float
- y1
float
- x2
float
- y2
float
- x3
float
- y3
float
[]struct<context.Point>
point_quadratic_bezier
point_quadratic_bezier(x0, y0, x1, y1, x2, y2) -> []struct<context.Point>
- x0
float
- y0
float
- x1
float
- y1
float
- x2
float
- y2
float
[]struct<context.Point>
pattern_solid
pattern_solid(color) -> struct<context.PatternSolid>
- color
struct<image.Color>
struct<context.PatternSolid>
pattern_surface
pattern_surface(id, repeat_op) -> struct<context.PatternSurface>
Images are only grabbed when the pattern is set, not when this is called.
- id
int<collection.IMAGE>
- repeat_op
int<context.RepeatOp>
struct<context.PatternSurface>
pattern_surface_sync
pattern_surface_sync(id, repeat_op) -> struct<context.PatternSurfaceSync>
This does not wait for the image to be ready or idle, if the image is not loaded it will grab an empy image. This also means it is not thread safe, it is unknown what state the image will be in when grabbed. Images are also only grabbed when the pattern is set, not when this is called.
- id
int<collection.IMAGE>
- repeat_op
int<context.RepeatOp>
struct<context.PatternSurfaceSync>
pattern_custom
pattern_custom(fn) -> struct<context.PatternCustom>
- fn
function(x int, y int) -> struct<image.Color>
struct<context.PatternCustom>
gradient_linear
gradient_linear(x0, y0, x1, y1) -> struct<context.PatternGradientLinear>
- x0
float
- y0
float
- x1
float
- y1
float
struct<context.PatternGradientLinear>
gradient_radial
gradient_radial(x0, y0, r0, x1, y1, r1) -> struct<context.PatternGradientRadial>
- x0
float
- y0
float
- r0
float
- x1
float
- y1
float
- r1
float
struct<context.PatternGradientRadial>
fill_style
fill_style(id, pattern)
- id
int<collection.CONTEXT>
- pattern
struct<context.Pattern>
stroke_style
stroke_style(id, pattern)
- id
int<collection.CONTEXT>
- pattern
struct<context.Pattern>
font_load
font_load(path, points)
- path
string
- points
float
Constants
FillRule
FILLRULE_WINDING
FILLRULE_EVENODD
LineCap
LINECAP_ROUND
LINECAP_BUTT
LINECAP_SQUARE
LineJoin
LINEJOIN_ROUND
LINEJOIN_BEVEL
RepeatOp
REPEAT_BOTH
REPEAT_X
REPEAT_Y
REPEAT_NONE
Align
ALIGN_LEFT
ALIGN_CENTER
ALIGN_RIGHT
PatternType
PATTERN_SOLID
PATTERN_SURFACE
PATTERN_SURFACE_SYNC
PATTERN_GRADIENT_LINEAR
PATTERN_GRADIENT_RADIAL
PATTERN_CUSTOM
Structs
Point
- x
float
- y
float
Matrix
- xx
float
- yx
float
- xy
float
- yy
float
- x0
float
- y0
float
multiply
multiply(self, struct<context.Matrix>) -> self
rotate
rotate(self, angle float) -> self
scale
scale(self, x float, y float) -> self
shear
shear(self, x float, y float) -> self
translate
translate(self, x float, y float) -> self
transform_point
transform_point(x float, y float) -> float, float
transform_vector
transform_vector(x float, y float) -> float, float
PatternSolid
- type
string<context.PatternType>
- color
struct<image.Color>
PatternSurface
- type
string<context.PatternType>
- id
int<collection.IMAGE>
- repeatOp
int<context.RepeatOp>
PatternSurfaceSync
- type
string<context.PatternType>
- id
int<collection.IMAGE>
- repeatOp
int<context.RepeatOp>
PatternGradientLinear
- type
string<context.PatternType>
- x0
float
- y0
float
- x1
float
- y1
float
color_stop
color_stop(offset float, struct<image.Color>)
PatternGradientRadial
- type
string<context.PatternType>
- x0
float
- y0
float
- r0
float
- x1
float
- y1
float
- r1
float
color_stop
color_stop(offset float, struct<image.Color>)
PatternCustom
- type
string<context.PatternType>
- fn
function(x int, y int) -> struct<image.ColorRGBA>
Interfaces
Pattern
- type
string<context.PatternType>