Simulation Instruments

Home›All functions›Canvas

Canvas

Simulation Instrument Studio 1

canvas_add

Simulation Instrument Studio 1

Overloads

canvas_add(x, y, width, height, draw_callback)

Creates a drawing surface. The callback runs whenever the canvas is painted.

Parameters

#NameTypeDescription
1xNumberThis is the most left point of the canvas.
2yNumberThis is the most top point of the canvas.
3widthNumberThe canvas width in pixels.
4heightNumberThe canvas height in pixels.
5draw_callbackFunction(Optional) This function will be called on a redraw of the canvas. It should contain the individual draw functions like _line_to, _arc, etc. The initial width and height of the canvas are provided to the callback function (from AM/).

Example

-- Horizon. The callback runs every time we ask for a redraw.
horizon = canvas_add(20, 20, 200, 200, function()
    _rect(0, 0, 200, 100)
    _fill("#3a82c4")
    _rect(0, 100, 200, 100)
    _fill("#6b4f2a")
end)

Example: a slip ball

slip = canvas_add(80, 170, 80, 24, function()
    _rect(0, 8, 80, 8)
    _fill("#2a3036")
    _circle(40, 12, 6)
    _fill("white")
end)
Photo slot: shots/canvas_add.png

canvas_draw

Simulation Instrument Studio 1

Overloads

canvas_draw(canvas_id, draw_callback)

Paints the canvas again, now.

Parameters

#NameTypeDescription
1canvas_idStringThe is the reference to the canvas. You can get this reference from the canvas_add function.
2draw_callbackFunctionOptional. This function will be called on a redraw of the canvas. It should contain the individual draw functions like _line_to, _rect, etc. The initial width and height of the canvas are provided to the callback function (from AM/).

Example

-- Pitch changed. Paint the horizon again.
canvas_draw(horizon)
Photo slot: shots/canvas_draw.png

_arc

Simulation Instrument Studio 1

Overloads

_arc(cx, cy, start_angle, end_angle, radius, direction)

Adds an arc to the current path.

Parameters

#NameTypeDescription
1cxNumberThis is the left pixel of the control point.
2cyNumberThis is the top pixel of the control point.
3start_angleNumberThe starting angle, in degrees (0 is at the 3 o'clock position of the arc's circle)
4end_angleNumberThe ending angle, in degrees
5radiusNumberRadius of the arc in pixels
6directionBoolean(Optional) true = clockwise, false = counterclockwise

Example

-- Drawn on the attitude canvas
_arc(20, 20)
Photo slot: shots/_arc.png

_arc_to

Simulation Instrument Studio 1

Overloads

_arc_to(cpx, cpy, x, y, radius)

Adds an arc from the pen to a point.

Parameters

#NameTypeDescription
1cpxNumberThis is the left pixel of the control point.
2cpyNumberThis is the top pixel of the control point.
3xNumberThis is the left pixel of the canvas where the end of your line should be.
4yNumberThis is the top pixel of the canvas where the end of your line should be.
5radiusNumberRadius of the arc in pixels

Example

-- Drawn on the attitude canvas
_arc_to(20, 20)
Photo slot: shots/_arc_to.png

_bezier_to

Simulation Instrument Studio 1

Overloads

_bezier_to(cp1x, cp1y, cp2x, cp2y, x, y)

Adds a cubic curve from the pen to a point.

Parameters

#NameTypeDescription
1cp1xNumberThis is the left pixel of the first control point.
2cp1yNumberThis is the top pixel of the first control point.
3cp2xNumberThis is the left pixel of the second control point.
4cp2yNumberThis is the top pixel of the second control point.
5xNumberThis is the left pixel of the canvas where the end of your line should be.
6yNumberThis is the top pixel of the canvas where the end of your line should be.

Example

-- Drawn on the attitude canvas
_bezier_to(20, 20)
Photo slot: shots/_bezier_to.png

_circle

Simulation Instrument Studio 1

Overloads

_circle(cx, cy, radius)

Adds a circle to the current path.

Parameters

#NameTypeDescription
1cxNumberLeft point of the center of the circle.
2cyNumberTop point of the center of the circle.
3radiusNumberRadius of the circle in pixels.

Example

-- A slip ball
_circle(100, 160, 8)
_fill("white")
Photo slot: shots/_circle.png

_ellipse

Simulation Instrument Studio 1

Overloads

_ellipse(cx, cy, radius_x, radius_y)

Adds an ellipse to the current path.

Parameters

#NameTypeDescription
1cxNumberLeft point of the center of the ellipse.
2cyNumberTop point of the center of the ellipse.
3radius_xNumberHorizontal radius of the ellipse in pixels.
4radius_yNumberVertical radius of the ellipse in pixels.

Example

-- Drawn on the attitude canvas
_ellipse(20, 20)
Photo slot: shots/_ellipse.png

_fill

Simulation Instrument Studio 1

Overloads

_fill(color)
_fill(color, opacity)
_fill(r, g, b)
_fill(r, g, b, opacity)

Fills the queued path.

Parameters

#NameTypeDescription
1colorMultipleThe color of the line. Can be RGBA hex string ('#FF0000FF'), the name of the color ('red') or separate number (1, 0, 0, 1).

Example

_rect(0, 0, 200, 100)
_fill("#3a82c4")
Photo slot: shots/_fill.png

_fill_gradient_box

Simulation Instrument Studio 1

Overloads

_fill_gradient_box(x, y, width, height, corner, feather, color_inner, color_outer)

Fills the queued path with a box gradient.

Parameters

#NameTypeDescription
1xNumberX position of the box in pixels
2yNumberY position of the box in pixels.
3widthNumberWidth of the box in pixels.
4heightNumberHeight of the box in pixels
5cornerNumberCorner radius in pixels.
6featherNumberFeather, this determines the blurring effect.
7color_innerColorThe color at point 1. Can be RGBA hex string (
8color_outerColorThe color at point 2. Can be RGBA hex string (

Example

-- Drawn on the attitude canvas
_fill_gradient_box(20, 20)
Photo slot: shots/_fill_gradient_box.png

_fill_gradient_linear

Simulation Instrument Studio 1

Overloads

_fill_gradient_linear(x1, y1, x2, y2, color_1, color_2)

Fills the queued path with a linear gradient.

Parameters

#NameTypeDescription
1x1NumberX position of point 1 in pixels.
2y1NumberY position of point 1 in pixels.
3x2NumberX position of point 2 in pixels.
4y2NumberY position of point 2 in pixels.
5color_1ColorThe color at point 1. Can be RGBA hex string (
6color_2ColorThe color at point 2. Can be RGBA hex string (

Example

-- Drawn on the attitude canvas
_fill_gradient_linear(20, 20)
Photo slot: shots/_fill_gradient_linear.png

_fill_gradient_radial

Simulation Instrument Studio 1

Overloads

_fill_gradient_radial(x, y, radius_inner, radius_outer, color_inner, color_outer)

Fills the queued path with a radial gradient.

Parameters

#NameTypeDescription
1xNumberX position of the center of the circle
2yNumberY position of the center of the circle
3radius_innerNumberRadius of inner color
4radius_outerNumberRadius of outer color
5color_innerColorThe color at point 1. Can be RGBA hex string (
6color_outerColorThe color at point 2. Can be RGBA hex string (

Example

-- Drawn on the attitude canvas
_fill_gradient_radial(20, 20)
Photo slot: shots/_fill_gradient_radial.png

_fill_img

Simulation Instrument Studio 1

Overloads

_fill_img(file_name, x, y, width, height)
_fill_img(file_name, x, y, width, height, opacity)

Fills the queued path with an image.

Parameters

#NameTypeDescription
1file_nameStringFile name of the image within the resource folder. Only PNG files are supported.
2xNumberX offset in pixels
3yNumberY offset in pixels
4widthNumberThe width of the rendered image
5heightNumberThe height of the rendered image
6opacityNumber(Optional) The opacity in which the image should be drawn. Ranges from 0.0 (invisible) to 1.0 (completely visible).

Example

-- Drawn on the attitude canvas
_fill_img(20, 20)
Photo slot: shots/_fill_img.png

_hole

Simulation Instrument Studio 1

Overloads

_hole()

The next shape is a hole in the fill.

Example

-- Drawn on the attitude canvas
_hole(20, 20)
Photo slot: shots/_hole.png

_line_to

Simulation Instrument Studio 1

Overloads

_line_to(x, y)

Draws a line from the pen to a point.

Parameters

#NameTypeDescription
1xNumberThis is the left pixel of the canvas where the end of your line should be.
2yNumberThis is the top pixel of the canvas where the end of your line should be.

Example

_move_to(20, 100)
_line_to(180, 100)
_stroke("#f2f4f6", 1)
Photo slot: shots/_line_to.png

_move_to

Simulation Instrument Studio 1

Overloads

_move_to(x, y)

Moves the pen without drawing.

Parameters

#NameTypeDescription
1xNumberThis is the left pixel of the canvas where your pen go.
2yNumberThis is the top pixel of the canvas where your pen go.

Example

-- Start the horizon line
_move_to(0, 100)
Photo slot: shots/_move_to.png

_quad_to

Simulation Instrument Studio 1

Overloads

_quad_to(cp1, cp1y, cp2x, cp2y, x, y)

Adds a quadratic curve from the pen to a point.

Parameters

#NameTypeDescription
1cpxNumberThis is the left pixel of the control point.
2cpyNumberThis is the top pixel of the control point.
3xNumberThis is the left pixel of the canvas where the end of your line should be.
4yNumberThis is the top pixel of the canvas where the end of your line should be.

Example

-- Drawn on the attitude canvas
_quad_to(20, 20)
Photo slot: shots/_quad_to.png

_rect

Simulation Instrument Studio 1

Overloads

_rect(x, y, width, height)
_rect(x, y, width, height, all_corners)
_rect(x, y, width, height, top_left_corner, top_right_corner, bottom_left_corner, bottom_right_corner)

Adds a rectangle to the current path.

Parameters

#NameTypeDescription
1xNumberLeft point of the rectangle.
2yNumberTop point of the rectangle.
3widthNumberWidth of the rectangle.
4heigthNumberHeight of the rectangle.
5cornerNumber(Optional) Radius of arcs on every corner of the rectangle, use if you want rounded corners.
5top_left_cornerNumber(Optional) Radius of arcs on top left corner of the rectangle, use if you want rounded corners.
6top_right_cornerNumber(Optional) Radius of arcs on top right corner of the rectangle, use if you want rounded corners.
7bottom_left_cornerNumber(Optional) Radius of arcs on bottom left corner of the rectangle, use if you want rounded corners.
8bottom_right_cornerNumber(Optional) Radius of arcs on bottom right corner of the rectangle, use if you want rounded corners.

Example

-- Sky over brown, the attitude ground
_rect(0, 100, 200, 100)
_fill("#6b4f2a")
Photo slot: shots/_rect.png

_rotate

Simulation Instrument Studio 1

Overloads

_rotate(angle)
_rotate(angle, anchor_x, anchor_y)

Rotates later drawing, in canvas pixels.

Parameters

#NameTypeDescription
1angleNumberAngle of rotation in degrees.
2anchor_xNumber(Optional) Left point of the anchor point to rotate around
3anchor_yNumber(Optional) Top point of the anchor point to rotate around

Example

-- Drawn on the attitude canvas
_rotate(20, 20)
Photo slot: shots/_rotate.png

_scale

Simulation Instrument Studio 1

Overloads

_scale(x, y)

Scales later drawing.

Parameters

#NameTypeDescription
1xNumberX axle scaling
2yNumberY axle scaling

Example

-- Drawn on the attitude canvas
_scale(20, 20)
Photo slot: shots/_scale.png

_solid

Simulation Instrument Studio 1

Overloads

_solid()

The next shape is solid, not a hole.

Example

-- Drawn on the attitude canvas
_solid(20, 20)
Photo slot: shots/_solid.png

_stroke

Simulation Instrument Studio 1

Overloads

_stroke(color_name, line_width)
_stroke(color_name, opacity, line_width)
_stroke(color_hex, line_width)
_stroke(r, g, b, line_width)
_stroke(r, g, b, a, line_width)

Strokes the queued path.

Parameters

#NameTypeDescription
1colorMultipleThe color of the line. Can be RGBA hex string (
2line_widthNumberThe width of the line in pixels.

Example

-- Lubber line
_move_to(100, 10)
_line_to(100, 28)
_stroke("white", 2)
Photo slot: shots/_stroke.png

_translate

Simulation Instrument Studio 1

Overloads

_translate(x, y)

Moves later drawing.

Parameters

#NameTypeDescription
1xNumberX position
2yNumberY position

Example

-- Drawn on the attitude canvas
_translate(20, 20)
Photo slot: shots/_translate.png

_triangle

Simulation Instrument Studio 1

Overloads

_triangle(x1, y1, x2, y2, x3, y3)

Adds a triangle to the current path.

Parameters

#NameTypeDescription
1x1NumberLeft point of the first corner of the triangle
2y1NumberTop point of the first corner of the triangle
3x2NumberLeft point of the second corner of the triangle
4y2NumberTop point of the second corner of the triangle
5x3NumberLeft point of the third corner of the triangle
6y3NumberTop point of the third corner of the triangle

Example

-- Drawn on the attitude canvas
_triangle(20, 20)
Photo slot: shots/_triangle.png

_txt

Simulation Instrument Studio 1

Overloads

_txt(text, style, x, y)
_txt(text, style, x, y, opacity)

Draws text on the canvas.

Parameters

#NameTypeDescription
1txtStringThis is the txt being shown
2styleStringThe style to use. See txt_add for style arguments.
3xNumberThis is the most left point of the canvas where your text should be shown.
4yNumberThis is the most top point of the canvas where your text should be shown.
5opacityNumber(Optional) The opacity in which the text should be drawn. Ranges from 0.0 (invisible) to 1.0 (completely visible).

Example

_txt("ALT", "size:12; color:white;", 8, 8)
Photo slot: shots/_txt.png