The batch mode for this graphics context. It can be 'auto', 'batch', or 'no-batch'.
Optional
Advanced
customCustom shader to apply to the graphics when rendering.
Static
defaultThe default fill style to use when none is provided.
Static
defaultThe default stroke style to use when none is provided.
The bounds of the graphic shape.
The current fill style of the graphics context. This can be a color, gradient, pattern, or a more complex style defined by a FillStyle object.
The current stroke style of the graphics context. Similar to fill styles, stroke styles can encompass colors, gradients, patterns, or more detailed configurations via a StrokeStyle object.
Adds an arc to the current path, which is centered at (x, y) with the specified radius, starting and ending angles, and direction.
The x-coordinate of the arc's center.
The y-coordinate of the arc's center.
The arc's radius.
The starting angle, in radians.
The ending angle, in radians.
Optional
counterclockwise: boolean(Optional) Specifies whether the arc is drawn counterclockwise (true) or clockwise (false). Defaults to false.
The instance of the current GraphicsContext for method chaining.
Adds an arc to the current path with the given control points and radius, connected to the previous point by a straight line if necessary.
The x-coordinate of the first control point.
The y-coordinate of the first control point.
The x-coordinate of the second control point.
The y-coordinate of the second control point.
The arc's radius.
The instance of the current GraphicsContext for method chaining.
Adds an SVG-style arc to the path, allowing for elliptical arcs based on the SVG spec.
The x-radius of the ellipse.
The y-radius of the ellipse.
The rotation of the ellipse's x-axis relative to the x-axis of the coordinate system, in degrees.
Determines if the arc should be greater than or less than 180 degrees.
Determines if the arc should be swept in a positive angle direction.
The x-coordinate of the arc's end point.
The y-coordinate of the arc's end point.
The instance of the current object for chaining.
Resets the current path. Any previous path and its commands are discarded and a new path is started. This is typically called before beginning a new shape or series of drawing commands.
The instance of the current GraphicsContext for method chaining.
Adds a cubic Bezier curve to the path. It requires three points: the first two are control points and the third one is the end point. The starting point is the last point in the current path.
The x-coordinate of the first control point.
The y-coordinate of the first control point.
The x-coordinate of the second control point.
The y-coordinate of the second control point.
The x-coordinate of the end point.
The y-coordinate of the end point.
Optional
smoothness: numberOptional parameter to adjust the smoothness of the curve.
The instance of the current object for chaining.
Draw Rectangle with chamfer corners. These are angled corners.
Upper left corner of rect
Upper right corner of rect
Width of rect
Height of rect
non-zero real number, size of corner cutout
Optional
transform: MatrixDraws a circle shape. This method adds a new circle path to the current drawing.
The x-coordinate of the center of the circle.
The y-coordinate of the center of the circle.
The radius of the circle.
The instance of the current object for chaining.
Clears all drawing commands from the graphics context, effectively resetting it. This includes clearing the path, and optionally resetting transformations to the identity matrix.
The instance of the current GraphicsContext for method chaining.
Creates a new GraphicsContext object that is a clone of this instance, copying all properties, including the current drawing state, transformations, styles, and instructions.
A new GraphicsContext instance with the same properties and state as this one.
Closes the current path by drawing a straight line back to the start. If the shape is already closed or there are no points in the path, this method does nothing.
The instance of the current object for chaining.
Check to see if a point is contained within this geometry.
Point to check if it's contained.
true
if the point is contained within geometry.
Applies a cutout to the last drawn shape. This is used to create holes or complex shapes by subtracting a path from the previously drawn path. If a hole is not completely in a shape, it will fail to cut correctly!
The instance of the current GraphicsContext for method chaining.
Destroys the GraphicsData object.
Options parameter. A boolean will act as if all options have been set to that value
Draws an ellipse at the specified location and with the given x and y radii. An optional transformation can be applied, allowing for rotation, scaling, and translation.
The x-coordinate of the center of the ellipse.
The y-coordinate of the center of the ellipse.
The horizontal radius of the ellipse.
The vertical radius of the ellipse.
The instance of the current object for chaining.
Fills the current or given path with the current fill style. This method can optionally take a color and alpha for a simple fill, or a more complex FillInput object for advanced fills.
Optional
style: FillInput(Optional) The style to fill the path with. Can be a color, gradient, pattern, or a complex style object. If omitted, uses the current fill style.
The instance of the current GraphicsContext for method chaining.
Draw Rectangle with fillet corners. This is much like rounded rectangle however it support negative numbers as well for the corner radius.
Upper left corner of rect
Upper right corner of rect
Width of rect
Height of rect
accept negative or positive values
Returns the current transformation matrix of the graphics context.
The current transformation matrix.
Connects the current point to a new point with a straight line. This method updates the current path.
The x-coordinate of the new point to connect to.
The y-coordinate of the new point to connect to.
The instance of the current object for chaining.
Sets the starting point for a new sub-path. Any subsequent drawing commands are considered part of this path.
The x-coordinate for the starting point.
The y-coordinate for the starting point.
The instance of the current object for chaining.
Adds another GraphicsPath
to this path, optionally applying a transformation.
The GraphicsPath
to add.
The instance of the current object for chaining.
Draws a polygon shape by specifying a sequence of points. This method allows for the creation of complex polygons, which can be both open and closed. An optional transformation can be applied, enabling the polygon to be scaled, rotated, or translated as needed.
An array of numbers, or an array of PointData objects eg [{x,y}, {x,y}, {x,y}] representing the x and y coordinates, of the polygon's vertices, in sequence.
Optional
close: booleanA boolean indicating whether to close the polygon path. True by default.
Adds a quadratic curve to the path. It requires two points: the control point and the end point. The starting point is the last point in the current path.
The x-coordinate of the control point.
The y-coordinate of the control point.
The x-coordinate of the end point.
The y-coordinate of the end point.
Optional
smoothness: numberOptional parameter to adjust the smoothness of the curve.
The instance of the current object for chaining.
Draws a rectangle shape. This method adds a new rectangle path to the current drawing.
The x-coordinate of the top-left corner of the rectangle.
The y-coordinate of the top-left corner of the rectangle.
The width of the rectangle.
The height of the rectangle.
The instance of the current object for chaining.
Draws a regular polygon with a specified number of sides. All sides and angles are equal.
The x-coordinate of the center of the polygon.
The y-coordinate of the center of the polygon.
The radius of the circumscribed circle of the polygon.
The number of sides of the polygon. Must be 3 or more.
The rotation angle of the polygon, in radians. Zero by default.
Optional
transform: MatrixAn optional Matrix
object to apply a transformation to the polygon.
The instance of the current object for chaining.
Resets the current transformation matrix to the identity matrix, effectively removing any transformations (rotation, scaling, translation) previously applied.
The instance of the current GraphicsContext for method chaining.
Restores the most recently saved graphics state by popping the top of the graphics state stack. This includes transformations, fill styles, and stroke styles.
Applies a rotation transformation to the graphics context around the current origin.
The angle of rotation in radians.
The instance of the current GraphicsContext for method chaining.
Draws a polygon with rounded corners.
Similar to regularPoly
but with the ability to round the corners of the polygon.
The x-coordinate of the center of the polygon.
The y-coordinate of the center of the polygon.
The radius of the circumscribed circle of the polygon.
The number of sides of the polygon. Must be 3 or more.
The radius of the rounding of the corners.
Optional
rotation: numberThe rotation angle of the polygon, in radians. Zero by default.
The instance of the current object for chaining.
Draws a rectangle with rounded corners. The corner radius can be specified to determine how rounded the corners should be. An optional transformation can be applied, which allows for rotation, scaling, and translation of the rectangle.
The x-coordinate of the top-left corner of the rectangle.
The y-coordinate of the top-left corner of the rectangle.
The width of the rectangle.
The height of the rectangle.
Optional
radius: numberThe radius of the rectangle's corners. If not specified, corners will be sharp.
The instance of the current object for chaining.
Draws a shape with rounded corners. This function supports custom radius for each corner of the shape. Optionally, corners can be rounded using a quadratic curve instead of an arc, providing a different aesthetic.
An array of RoundedPoint
representing the corners of the shape to draw.
A minimum of 3 points is required.
The default radius for the corners.
This radius is applied to all corners unless overridden in points
.
Optional
useQuadratic: booleanIf set to true, rounded corners are drawn using a quadraticCurve method instead of an arc method. Defaults to false.
Optional
smoothness: numberSpecifies the smoothness of the curve when useQuadratic
is true.
Higher values make the curve smoother.
The instance of the current object for chaining.
Saves the current graphics state, including transformations, fill styles, and stroke styles, onto a stack.
Applies a scaling transformation to the graphics context, scaling drawings by x horizontally and by y vertically.
The scale factor in the horizontal direction.
(Optional) The scale factor in the vertical direction. If not specified, the x value is used for both directions.
The instance of the current GraphicsContext for method chaining.
Sets the current fill style of the graphics context. The fill style can be a color, gradient, pattern, or a more complex style defined by a FillStyle object.
The fill style to apply. This can be a simple color, a gradient or pattern object, or a FillStyle or ConvertedFillStyle object.
The instance of the current GraphicsContext for method chaining.
Sets the current stroke style of the graphics context. Similar to fill styles, stroke styles can encompass colors, gradients, patterns, or more detailed configurations via a StrokeStyle object.
The stroke style to apply. Can be defined as a color, a gradient or pattern, or a StrokeStyle or ConvertedStrokeStyle object.
The instance of the current GraphicsContext for method chaining.
Sets the current transformation matrix of the graphics context to the specified matrix or values. This replaces the current transformation matrix.
The matrix to set as the current transformation matrix.
The instance of the current GraphicsContext for method chaining.
Sets the current transformation matrix of the graphics context to the specified matrix or values. This replaces the current transformation matrix.
The value for the a property of the matrix, or a Matrix object to use directly.
The value for the b property of the matrix.
The value for the c property of the matrix.
The value for the d property of the matrix.
The value for the tx (translate x) property of the matrix.
The value for the ty (translate y) property of the matrix.
The instance of the current GraphicsContext for method chaining.
Draws a star shape centered at a specified location. This method allows for the creation of stars with a variable number of points, outer radius, optional inner radius, and rotation. The star is drawn as a closed polygon with alternating outer and inner vertices to create the star's points. An optional transformation can be applied to scale, rotate, or translate the star as needed.
The x-coordinate of the center of the star.
The y-coordinate of the center of the star.
The number of points of the star.
The outer radius of the star (distance from the center to the outer points).
Optional. The inner radius of the star
(distance from the center to the inner points between the outer points).
If not provided, defaults to half of the radius
.
Optional. The rotation of the star in radians, where 0 is aligned with the y-axis. Defaults to 0, meaning one point is directly upward.
The instance of the current object for chaining further drawing commands.
Strokes the current path with the current stroke style. This method can take an optional FillInput parameter to define the stroke's appearance, including its color, width, and other properties.
Optional
style: StrokeInput(Optional) The stroke style to apply. Can be defined as a simple color or a more complex style object. If omitted, uses the current stroke style.
The instance of the current GraphicsContext for method chaining.
Parses and renders an SVG string into the graphics context. This allows for complex shapes and paths defined in SVG format to be drawn within the graphics context.
The SVG string to be parsed and rendered.
Adds a texture to the graphics context. This method supports multiple overloads for specifying the texture. If only a texture is provided, it uses the texture's width and height for drawing.
The Texture object to use.
The instance of the current GraphicsContext for method chaining.
Adds a texture to the graphics context. This method supports multiple overloads for specifying the texture, tint, and dimensions. If only a texture is provided, it uses the texture's width and height for drawing. Additional parameters allow for specifying a tint color, and custom dimensions for the texture drawing area.
The Texture object to use.
Optional
tint: ColorSource(Optional) A ColorSource to tint the texture. If not provided, defaults to white (0xFFFFFF).
Optional
dx: number(Optional) The x-coordinate in the destination canvas at which to place the top-left corner of the source image.
Optional
dy: number(Optional) The y-coordinate in the destination canvas at which to place the top-left corner of the source image.
Optional
dw: number(Optional) The width of the rectangle within the source image to draw onto the destination canvas. If not provided, uses the texture's frame width.
Optional
dh: number(Optional) The height of the rectangle within the source image to draw onto the destination canvas. If not provided, uses the texture's frame height.
The instance of the current GraphicsContext for method chaining.
Applies the specified transformation matrix to the current graphics context by multiplying the current matrix with the specified matrix.
The matrix to apply to the current transformation.
The instance of the current GraphicsContext for method chaining.
Applies the specified transformation matrix to the current graphics context by multiplying the current matrix with the specified matrix.
The value for the a property of the matrix, or a Matrix object to use directly.
The value for the b property of the matrix.
The value for the c property of the matrix.
The value for the d property of the matrix.
The value for the tx (translate x) property of the matrix.
The value for the ty (translate y) property of the matrix.
The instance of the current GraphicsContext for method chaining.
Applies a translation transformation to the graphics context, moving the origin by the specified amounts.
The amount to translate in the horizontal direction.
(Optional) The amount to translate in the vertical direction. If not specified, the x value is used for both directions.
The instance of the current GraphicsContext for method chaining.
The GraphicsContext class allows for the creation of lightweight objects that contain instructions for drawing shapes and paths. It is used internally by the Graphics class to draw shapes and paths, and can be used directly and shared between Graphics objects,
This sharing of a
GraphicsContext
means that the intensive task of converting graphics instructions into GPU-ready geometry is done once, and the results are reused, much like sprites reusing textures.