Cosmic Docs

Theme
cs.graphics

Graphics

Provides a cross platform API to draw lines, shapes, text, images, and other graphics onto a window or buffer. By default, the coordinate system assumes the origin is at the top-left corner (0, 0). Positive x values go right and positive y values go down. Angle units like radians and degrees start at 0 and positive values go clockwise. The backend uses OpenGL 3 on desktop and Canvas/WebGL for web. Support for WebGPU is planned. Currently, the API is focused on 2D graphics, but there are plans to add 3D graphics utilities.

cs.graphics.hsvToRgb hue: number, sat: number, val: number ) Color

Converts HSV to RGB. Hue is in degrees [0,100] and saturation/value are [0,1].

This provides an interface to the underlying graphics handle. It has a similar API to Web Canvas.

Returns the FontId of "Bitstream Vera Sans" the default font embedded into the runtime.

cs.graphics.ContextfillColor color: Color )

Sets the current fill color for painting shapes.

Returns the current fill color.

cs.graphics.ContextstrokeColor color: Color )

Sets the current stroke color for painting shape outlines.

Returns the current stroke color.

cs.graphics.ContextlineWidth width: number )

Sets the current line width for painting shape outlines.

Returns the current line width.

cs.graphics.ContextaddTtfFont path: string ) number

Path can be absolute or relative to the cwd.

cs.graphics.ContextnewImage path: string ) Image

Path can be absolute or relative to the cwd.

cs.graphics.Contextrect x: number, y: number, width: number, height: number )

Paints a rectangle with the current fill color.

cs.graphics.ContextrectOutline x: number, y: number, width: number, height: number )

Paints a rectangle outline with the current stroke color.

cs.graphics.ContextroundRect x: number, y: number, width: number, height: number, radius: number )

Paints a round rectangle with the current fill color.

cs.graphics.ContextroundRectOutline x: number, y: number, width: number, height: number, radius: number )

Paints a round rectangle outline with the current stroke color.

cs.graphics.Contexttranslate x: number, y: number )

Shifts the origin x units to the right and y units down.

cs.graphics.Contextscale x: number, y: number )

Scales from the origin x units horizontally and y units vertically. Negative value flips the axis. Value of 1 does nothing.

cs.graphics.Contextrotate rad: number )

Rotates the origin by radians clockwise.

cs.graphics.ContextrotateDeg deg: number )

Rotates the origin by degrees clockwise.

Resets the current transform to identity.

Saves the current graphics state by pushing onto a stack.

Restores the graphics state on top of the stack.

cs.graphics.ContextgetViewTransform (  ) runtime.api_graphics.cs_graphics.Transform

Given logical 2D coordinates, return the interpolation to screen coordinates with the current transform.

cs.graphics.Contextfont fontId: number, size: number )

Sets the current font and font size.

cs.graphics.ContextfontSize size: number )

Sets the current font size.

cs.graphics.ContexttextAlign align: runtime.api_graphics.cs_graphics.TextAlign )

Sets the current text align.

cs.graphics.ContexttextBaseline baseline: runtime.api_graphics.cs_graphics.TextBaseline )

Sets the current text baseline.

cs.graphics.Contexttext x: number, y: number, text: string )

Paints text with the current fill color.

cs.graphics.ContextcircleSector x: number, y: number, radius: number, startRad: number, sweepRad: number )

Paints a circle sector in radians with the current fill color.

cs.graphics.ContextcircleSectorDeg x: number, y: number, radius: number, startDeg: number, sweepDeg: number )

Paints a circle sector in degrees with the current fill color.

cs.graphics.ContextcircleArc x: number, y: number, radius: number, startRad: number, sweepRad: number )

Paints a circle arc in radians with the current stroke color.

cs.graphics.ContextcircleArcDeg x: number, y: number, radius: number, startDeg: number, sweepDeg: number )

Paints a circle arc in degrees with the current stroke color.

cs.graphics.Contextcircle x: number, y: number, radius: number )

Paints a circle with the current fill color.

cs.graphics.ContextcircleOutline x: number, y: number, radius: number )

Paints a circle outline with the current stroke color.

cs.graphics.Contextellipse x: number, y: number, hRadius: number, vRadius: number )

Paints a ellipse with the current fill color.

cs.graphics.ContextellipseOutline x: number, y: number, hRadius: number, vRadius: number )

Paints a ellipse outline with the current stroke color.

cs.graphics.ContextellipseSector x: number, y: number, hRadius: number, vRadius: number, startRad: number, sweepRad: number )

Paints a ellipse sector in radians with the current fill color.

cs.graphics.ContextellipseSectorDeg x: number, y: number, hRadius: number, vRadius: number, startDeg: number, sweepDeg: number )

Paints a ellipse sector in degrees with the current fill color.

cs.graphics.ContextellipseArc x: number, y: number, hRadius: number, vRadius: number, startRad: number, sweepRad: number )

Paints a ellipse arc in radians with the current stroke color.

cs.graphics.ContextellipseArcDeg x: number, y: number, hRadius: number, vRadius: number, startDeg: number, sweepDeg: number )

Paints a ellipse arc in degrees with the current stroke color.

cs.graphics.Contextpoint x: number, y: number )

Paints a point with the current stroke color.

cs.graphics.Contextline x1: number, y1: number, x2: number, y2: number )

Paints a line with the current stroke color.

cs.graphics.ContextcubicBezierCurve x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number )

Paints a cubic bezier curve with the current stroke color.

cs.graphics.ContextquadraticBezierCurve x1: number, y1: number, cx: number, cy: number, x2: number, y2: number )

Paints a quadratic bezier curve with the current stroke color.

cs.graphics.Contexttriangle x1: number, y1: number, x2: number, y2: number, x3: number, y3: number )

Paints a triangle with the current fill color.

Paints a convex polygon with the current fill color.

cs.graphics.Contextpolygon pts: Array )

Paints any polygon with the current fill color.

Paints any polygon outline with the current stroke color.

cs.graphics.ContextcompileSvgContent content: string ) object

Compiles svg content string into a draw list handle.

cs.graphics.ContextsvgContent content: string )

Paints svg content in UTF-8.

cs.graphics.ContextexecuteDrawList handle: runtime.adapter.Handle(runtime.runtime.WeakHandleTag.DrawCommandList) )

Executes a draw list handle.

cs.graphics.ContextimageSized x: number, y: number, width: number, height: number, image: Image )

Paints an image.

cs.graphics.Transform object
mat: Array

cs.graphics.Transforminterpolate : number, : number ) .stdx.math.math.Vec2

cs.graphics.Color object
r: number
g: number
b: number
a: number

cs.graphics.ColorwithAlpha alpha: number ) Color