Rapid.js provides a set of geometry drawing functions for shapes that don’t require a pre-loaded image: filled rectangles, filled circles, multi-point lines with mitered joints, and arbitrary polygon meshes assembled from raw vertices. Unlike sprites, graphics geometry is uploaded to the GPU fresh each frame — making them best suited for dynamic or procedural shapes rather than large quantities of identical objects. All graphics functions share the sameDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Nightre/Rapid.js/llms.txt
Use this file to discover all available pages before exploring further.
ITransformOptions fields as drawSprite (x, y, rotation, scale, origin, offset, offsetX, offsetY, saveTransform). Refer to the Sprites guide for a full description of those fields.
drawRect
drawRect renders a filled axis-aligned rectangle. Pass a color for a solid fill, a texture to map an image onto the quad, or both to tint the texture.
IRectOptions
Width of the rectangle in logical pixels.
Height of the rectangle in logical pixels.
Fill color. Defaults to opaque white when a texture is provided, or renders as a white rectangle if neither color nor texture is set.
An optional texture applied to the rectangle quad. UVs span the full
[0, 1] range across the width and height.Examples
drawCircle
drawCircle renders a filled circle approximated by a fan of triangles radiating from the center.
ICircleOptions
Radius of the circle in logical pixels.
Fill color. Defaults to opaque white.
Number of triangle slices used to approximate the circle. Higher values give a smoother edge at the cost of more vertices. Defaults to
32.Example
The center vertex is always placed at the origin
(0, 0) in local space, so origin and offset interact with the circle the same way they do with sprites.drawLine
drawLine renders a polyline as a triangle strip with proper miter joints at every bend. Caps can optionally be rounded, and the path can be closed into a polygon outline.
ILineOptions
ILineOptions extends ILineRenderOptions from the line module and IDrawOptions.
The ordered list of
Vec2 vertices that define the path. At least two points are required.Stroke width in logical pixels. Defaults to
1.Line color. Defaults to opaque white.
When
true, the last point is connected back to the first, closing the loop. Defaults to false.When
true, semicircular caps are added at the start and end of an open line. Has no effect on closed paths. Defaults to false.An optional texture applied along the line. The UV mapping along the line axis is controlled by
textureMode.Controls how the texture is mapped along the line’s length.
LineTextureMode.STRETCH— stretches the texture once from start to end (default).LineTextureMode.REPEAT— tiles the texture based on the texture’s pixel width.
Example
Custom Polygons — the Vertex API
For full control over geometry you can drive theGraphicRegion directly using the low-level vertex API: startGraphic → addGraphicVertex / addRectVertex / addCircleVertex → endGraphic.
High-level: drawGraphic
drawGraphic is a convenience wrapper that accepts a points array and takes care of the start/end bookkeeping for you.
IGraphicOptions
Array of
Vec2 or {x, y} objects defining the vertices.A single color applied to all vertices, or a per-vertex color array (must have the same length as
points). Defaults to opaque white.A WebGL draw mode constant such as
gl.TRIANGLES, gl.TRIANGLE_FAN, or gl.TRIANGLE_STRIP. Defaults to gl.TRIANGLES.Optional per-vertex UV coordinates in the
[0, 1] range. Must have the same length as points. Defaults to (0, 0) for all vertices.An optional texture to sample using the
uv coordinates.Low-level: startGraphic / addGraphicVertex / endGraphic
For procedural geometry — particles, dynamic meshes, or shapes built at runtime — you can push vertices one by one betweenstartGraphic and endGraphic.
startGraphic(drawMode, texture?, customShader?, customMatrix?)
Enters the graphics region and begins a new primitive batch. Call this once before pushing vertices.
addGraphicVertex(x, y, u?, v?, color?)
Appends a single vertex. u and v are UV coordinates (default 0). color is a packed uint32 — use color.uint32 (or color.premultipliedUint32 when premultiplied alpha is enabled) to convert a Color instance, or pass 0xFFFFFFFF directly for opaque white.
endGraphic()
Closes the current batch and marks it ready for the GPU flush.
Shorthand vertex helpers
Two helpers produce common shapes without manual vertex arithmetic:addRectVertex(w, h, color?)
Pushes four vertices for a rectangle of size w × h. Intended for use inside a TRIANGLE_FAN batch (which needs exactly 4 vertices for a quad):
addCircleVertex(r, color?, segments?)
Pushes segments vertices (default 32) arranged around a circle of radius r. Intended for use inside a TRIANGLE_FAN batch together with a center vertex, exactly as drawCircle does internally:
TRIANGLE_FAN is the most efficient draw mode for convex polygons. Each new vertex shares an edge with the fan’s origin (first vertex) and the previous vertex, so an N-vertex fan draws N-2 triangles. Use TRIANGLES when you need non-convex shapes by supplying explicit triangle triplets.