class Sketch

Interface to an OpenGL-backed drawing context

Every custom UI made with jsui or JSPainter has access to a default Sketch object bound to the global variable "sketch". Use this object to render to the OpenGL-backed drawing context available to all UI objects. Often this is the only instance of the Sketch object that you will use. If you want to render sprites, have multiple layers of images, or create alpha channels, you can construct new instances of the Sketch object.

Constructors

new Sketch(width?: number, height?: number);

Create a new Sketch instance

ParameterTypeDescription
optional widthnumberwidth, leave undefined to use the default
optional heightnumberheight, leave undefined to use the default

Methods

beginstroke

Begin definition of a stroked path

beginstroke(stroke_style: "basic2d" | "line");
NameTypeDescription
stroke_style"basic2d" | "line"the stroke style to use

circle

Draw a circle or an arc

Draws a filled circle with radius specified by the radius argument at the current drawing position. If theta_start and theta_end are specified, then an arc will be drawn instead of a full circle. Affected by shapeorient, shapeslice, and shapeprim values.

circle(radius: number, theta_start?: number, theta_end?: number);
NameTypeDescription
radiusnumberradius of the circle
optional theta_startnumberstart angle in degrees
optional theta_endnumberend angle in degrees

copypixels

Copy pixels from one object to the current sketch

Copies pixels from the source object to the location specified by the destination_x and destination_y arguments. The initial x and y offset into the source and size of the rectangle copied can be speified by the source_x, source_y, width and height arguments. If these are not present, an x and y offset of zero and width and height equal to the source image is assumed. No scaling of pixels is supported. If blending is enabled in the destination sketch object, alpha blending will be performed and the current alpha color will also be applied globally. he copypixels method is much faster than obtaining the equivalent result using glbindtexture() to texture a plane, and is the recommended means of drawing images when scaling and rotation are not required.

copypixels(source_obj: Sketch | Image, destination_x: number, destination_y: number, source_x?: number, source_y?: number, width?: number, height?: number);
NameTypeDescription
source_objSketch | Imagethe source object to copy pixels from
destination_xnumberx coordinate of the destination
destination_ynumbery coordinate of the destination
optional source_xnumberx coordinate of the source
optional source_ynumbery coordinate of the source
optional widthnumberwidth
optional heightnumberheight

cube

Draw a cube

The cube will have width = 2 * scale_x, height = 2 * scale_y, and depth = 2 * scale_z, and will be centered at the current drawing position. By default, scale_y and scale_z will be equal to scale_x. Affected by shapeorient, shapeslice, and shapeprim values.

cube(scale_x: number, scale_y?: number, scale_z?: number);
NameTypeDescription
scale_xnumberhalf width
optional scale_ynumberhalf height
optional scale_znumberhalf depth

cylinder

Draw a cylinder or cylindrical arc

Draws a cylinder with top radius specified by the radius1 argument, bottom radius specified by the radius2 argument, length specified by the mag argument, and center point at the current drawing position. If the theta_start and theta_end arguments are specified, then a cylindrical wedge will be drawn instead of a full cylinder. Affected by shapeorient, shapeslice, and shapeprim values.

cylinder(radius1: number, radius2: number, mag: number, theta_start?: number, theta_end?: number);
NameTypeDescription
radius1numberradius of one end of the cylinder
radius2numberradius of the other end of the cylinder
magnumberheight of the cylinder
optional theta_startnumberstart angle in degrees
optional theta_endnumberend angle in degrees

default2d

Set the default graphics state for 2d rendering

The default2d method is a simple way to set the graphics state to default properties useful for 2D graphics. It is called everytime your object is resized if default2d() has been called more recently than default3d(). It is essentially equivalent to the following set of calls:

default2d();

Example

with (sketch) {
	glpolygonmode("front_and_back", "fill")
	glpointsize(1)
	gllinewidth(1)
	gldisable("depth_test")
	gldisable("fog")
	glcolor(0, 0, 0, 1)
	glshademodel("smooth")
	gldisable("lighting")
	gldisable("normalize")
	gldisable("texture")
	glmatrixmode("projection")
	glloadidentity()
	glortho(-aspect, aspect, -1, 1, -1, 100)
	glmatrixmode("modelview")
	glloadidentity()
	glulookat(0, 0, 2, 0, 0, 0, 0, 0, 1)
	glclearcolor(1, 1, 1, 1)
	glclear()
	glenable("blend")
	glblendfunc("src_alpha", "one_minus_src_alpha")
}

default3d

Set the default graphics state for 3d rendering

The default3d method is a simple way to set the graphics state to default properties useful for 3D graphics. It is called everytime the jsui object is resized if default3d() has been called more recently than default2d(). It is essentially equivalent to the following set of calls:

default3d();

Example

with (sketch) {
	glpolygonmode("front_and_back", "fill")
	glpointsize(1)
	gllinewidth(1)
	glenable("depth_test")
	glenable("fog")
	glcolor(0, 0, 0, 1)
	glshademodel("smooth")
	gllightmodel("two_side", "true")
	glenable("lighting")
	glenable("light0")
	glenable("normalize")
	gldisable("texture")
	glmatrixmode("projection")
	glloadidentity()
	gluperspective(default_lens_angle, aspect, 0.1, 100)
	glmatrixmode("modelview")
	glloadidentity()
	glulookat(0, 0, 2, 0, 0, 0, 0, 0, 1)
	glclearcolor(1, 1, 1, 1)
	glclear()
	glenable("blend")
	glblendfunc("src_alpha", "one_minus_src_alpha")
}

depthatpixel

Get the depth at a given pixel

Returns the depth value associated with the currently rendered pixel at a given absolute screen coordinate.

depthatpixel(x: number, y: number): number;
NameTypeDescription
xnumberscreen x coordinate
ynumberscreen y coordinate
Return Valuenumber

ellipse

Draw an ellipse or elliptical arc

Draws a filled ellipse with radii specified by the radius1 and radius2 arguments. If theta_start and theta_end are specified, then an arc will be drawn instead of a full ellipse. Affected by shapeorient, shapeslice, and shapeprim values.

ellipse(radius1: number, radius2: number, theta_start?: number, theta_end?: number);
NameTypeDescription
radius1numberradius of the first axis
radius2numberradius of the second axis
optional theta_startnumberstart angle in degrees
optional theta_endnumberend angle in degrees

endstroke

End definition of a path and render it

endstroke();

font

Set the current font

font(font_name: string);
NameTypeDescription
font_namestringname of the font

fontsize

Set the font size in points

fontsize(size: number);
NameTypeDescription
sizenumbersize of the font

framecircle

Draw a framed circle or arc

Draws a framed circle with radius specified by the radius argument at the current drawing position. If theta_start and theta_end are specified, then an arc will be drawn instead of a full circle. Affected by shapeorient, shapeslice, and shapeprim values.

framecircle(radius: number, theta_start?: number, theta_end?: number);
NameTypeDescription
radiusnumberradius of the circle
optional theta_startnumberstart angle in degrees
optional theta_endnumberend angle in degrees

frameellipse

Draw a framed ellipse or elliptical arc

Draws a framed ellipse with radii specified by the radius1 and radius2 arguments. If theta_start and theta_end are specified, then an arc will be drawn instead of a full ellipse. Affected by shapeorient, shapeslice, and shapeprim values.

frameellipse(radius1: number, radius2: number, theta_start?: number, theta_end?: number);
NameTypeDescription
radius1numberradius of the first axis
radius2numberradius of the second axis
optional theta_startnumberstart angle in degrees
optional theta_endnumberend angle in degrees

framequad

Draw a framed quadrilateral

After this method has been called, the drawing position is updated to the location specified by the x4, y4, and z4 arguments.

framequad(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, x3: number, y3: number, z3: number, x4: number, y4: number, z4: number);
NameTypeDescription
x1numberx coordinate of the first point
y1numbery coordinate of the first point
z1numberz coordinate of the first point
x2numberx coordinate of the second point
y2numbery coordinate of the second point
z2numberz coordinate of the second point
x3numberx coordinate of the third point
y3numbery coordinate of the third point
z3numberz coordinate of the third point
x4numberx coordinate of the fourth point
y4numbery coordinate of the fourth point
z4numberz coordinate of the fourth point

frametri

Draw a framed triangle

After this method has been called, the drawing position is updated to the location specified by the x3, y3, and z3 arguments.

frametri(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, x3: number, y3: number, z3: number);
NameTypeDescription
x1numberx coordinate of the first point
y1numbery coordinate of the first point
z1numberz coordinate of the first point
x2numberx coordinate of the second point
y2numbery coordinate of the second point
z2numberz coordinate of the second point
x3numberx coordinate of the third point
y3numbery coordinate of the third point
z3numberz coordinate of the third point

freepeer

Free the native C peer

Frees data from the native C peer (created when making a Sketch object), which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based JS allocated memory. Once called, the Sketch object is not available for any other use. It's not necessary to call this function, as the memory will be freed eventually, but you can call it whenever you're done with your Sketch object.

freepeer();

getpixel

Get the pixel data at a given point

Returns an array containing the pixel value at the specified location. This array is ordered RGBA, i.e. array element 0 is red, 1, green, 2, blue, 3 alpha. Color values are floating point numbers in the range 0.-1.

getpixel(x: number, y: number): [number, number, number, number];
NameTypeDescription
xnumberx coordinate
ynumbery coordinate
Return Value[number, number, number, number]

gettextinfo

Get the rendered size of text

Returns an array containing the width and height of the given string in absolute screen coordinates, taking into account the current font and fontsize.

gettextinfo(text: string): [number, number];
NameTypeDescription
textstringtext to measure
Return Value[number, number]

glbegin

Begin drawing using low level OpenGL functions

The low level OpenGL function calls (all beginning with gl) are thin wrappers around direct calls to the graphics engine. Typically, use these function calls between calls to Sketch.glbegin() and Sketch.glend(). For many of these functions, look up the documentation for the OpenGL function with the same (or very similar) name.

glbegin(prim_type: DrawingPrimitiveType);
NameTypeDescription
prim_typeDrawingPrimitiveTypethe drawing primitive to use

Example

var sx = 1.0;
var sy = 1.0;
var tx = 0.0;
var ty = 0.0;
function draw() {
	// refers to the global "sketch" object
 sketch.glclear();

	sketch.glcolor(1, 0, 0);
	sketch.glbegin("lines");

 // draw x axis
	glvertex(Math.min(tx + sx * -1, -1),  ty, 0);
	glvertex(Math.max(tx + sx * 1, 1),  ty, 0);

 // draw y axis
	glvertex(tx,  Math.min(ty + sy * -1, -1), 0);
	glvertex(tx,  Math.max(ty + sy * 1, 1), 0);
}

glbindtexture

Apply the given texture to subsequent drawing calls

Note: this method also calls glenable(texture)

glbindtexture(image: Image);
NameTypeDescription
imageImagethe image to use as a texture

glblendfunc

glblendfunc(src_func: string, dst_func: string);
NameTypeDescription
src_funcstringsource function
dst_funcstringdestination function

glclear

Clear the drawing context

glclear();

glclearcolor

Set the color to fill the context with using Sketch.glclear()

glclearcolor(red: number, green: number, blue: number, alpha: number = 1);
NameTypeDescription
rednumberred (0-1 range)
greennumbergreen (0-1 range)
bluenumberblue (0-1 range)
optional alphanumberalpha (0-1 range)

glclearcolor

glclearcolor(colors: number[]);
NameTypeDescription
colorsnumber[]

glcleardepth

Set the depth to fill the context with using Sketch.glclear()

glcleardepth(depth: number);
NameTypeDescription
depthnumberdepth (0-1 range)

glclipplane

glclipplane(plane: number, coeff1: number, coeff2: number, coeff3: number, coeff4: number);
NameTypeDescription
planenumber
coeff1number
coeff2number
coeff3number
coeff4number

glclipplane

glclipplane(planeValues: number[]);
NameTypeDescription
planeValuesnumber[]

glcolor

Set the color for subsequent drawing calls

glcolor(red: number, green: number, blue: number, alpha: number = 1);
NameTypeDescription
rednumberred (0-1 range)
greennumbergreen (0-1 range)
bluenumberblue (0-1 range)
optional alphanumberalpha (0-1 range)

glcolor

glcolor(colors: number[]);
NameTypeDescription
colorsnumber[]

glcolormask

glcolormask(red: number, green: number, blue: number, alpha: number = 1);
NameTypeDescription
rednumber
greennumber
bluenumber
optional alphanumber

glcolormask

glcolormask(colors: number[]);
NameTypeDescription
colorsnumber[]

glcolormaterial

glcolormaterial(face: number, mode: number);
NameTypeDescription
facenumber
modenumber

glcullface

glcullface(face: number);
NameTypeDescription
facenumber

gldepthmask

gldepthmask(onoff: number);
NameTypeDescription
onoffnumber

gldepthrange

gldepthrange(near: number, far: number);
NameTypeDescription
nearnumber
farnumber

gldisable

Disable a drawing capaility.

Usually "blend", "line_smooth", or "texture"

gldisable(capability: string);
NameTypeDescription
capabilitystringthe capability to disable

gldrawpixels

gldrawpixels(image: Image);
NameTypeDescription
imageImage

gledgeflag

gledgeflag(onoff: number);
NameTypeDescription
onoffnumber

glenable

Enable a drawing capaility.

Usually "blend", "line_smooth", or "texture"

glenable(capability: string);
NameTypeDescription
capabilitystringthe capability to enable

glend

glend();

glfinish

glfinish();

glflush

glflush();

glfog

glfog(parameter_name: string, ...values: number);
NameTypeDescription
parameter_namestring
valuesnumber

glfrustrum

glfrustrum(left: number, right: number, bottom: number, top: number, near: number, far: number);
NameTypeDescription
leftnumber
rightnumber
bottomnumber
topnumber
nearnumber
farnumber

glfrustrum

glfrustrum(frustrumValues: number[]);
NameTypeDescription
frustrumValuesnumber[]

glhint

glhint(target: string, mode: number);
NameTypeDescription
targetstring
modenumber

gllight

gllight(light: string, parameter_name: string, ...values: number);
NameTypeDescription
lightstring
parameter_namestring
valuesnumber

gllightmodel

gllightmodel(light: string, model: number);
NameTypeDescription
lightstring
modelnumber

gllinestipple

gllinestipple(factor: any, bit_pattern: any);
NameTypeDescription
factorany
bit_patternany

gllinewidth

gllinewidth(width: number);
NameTypeDescription
widthnumber

glloadidentity

Load the identity matrix

glloadidentity();

glloadmatrix

glloadmatrix(matrix_array: number[]);
NameTypeDescription
matrix_arraynumber[]

gllogicop

gllogicop(op: number);
NameTypeDescription
opnumber

glmaterial

glmaterial();

glmatrixmode

glmatrixmode(mode: string);
NameTypeDescription
modestring

glmultmatrix

glmultmatrix(matrix_array: number[]);
NameTypeDescription
matrix_arraynumber[]

glnormal

glnormal(x: number, y: number, z: number);
NameTypeDescription
xnumber
ynumber
znumber

glortho

glortho(left: number, right: number, bottom: number, top: number, near: number, far: number);
NameTypeDescription
leftnumber
rightnumber
bottomnumber
topnumber
nearnumber
farnumber

glortho

glortho(orthoValues: number[]);
NameTypeDescription
orthoValuesnumber[]

glpointsize

glpointsize(size: number);
NameTypeDescription
sizenumber

glpolygonmode

glpolygonmode(face: number, mode: number);
NameTypeDescription
facenumber
modenumber

glpolygonoffset

glpolygonoffset(factor: number, units: number);
NameTypeDescription
factornumber
unitsnumber

glpopattrib

glpopattrib();

glpopmatrix

glpopmatrix();

glpushattrib

glpushattrib();

glpushmatrix

glpushmatrix();

glrect

glrect(x1: number, y1: number, x2: number, y2: number);
NameTypeDescription
x1number
y1number
x2number
y2number

glrect

glrect(rectValues: number[]);
NameTypeDescription
rectValuesnumber[]

glrotate

glrotate(angle: number, x: number, y: number, z: number);
NameTypeDescription
anglenumber
xnumber
ynumber
znumber

glrotate

glrotate(rotateValues: number[]);
NameTypeDescription
rotateValuesnumber[]

glscale

glscale(x: number, y: number, z: number);
NameTypeDescription
xnumber
ynumber
znumber

glscale

glscale(scaleValues: number[]);
NameTypeDescription
scaleValuesnumber[]

glscissor

glscissor(x: number, y: number, width: number, height: number);
NameTypeDescription
xnumber
ynumber
widthnumber
heightnumber

glscissor

glscissor(scissorValues: number[]);
NameTypeDescription
scissorValuesnumber[]

glshademodel

glshademodel(mode: number);
NameTypeDescription
modenumber

gltexcoord

gltexcoord(s: number, t: number);
NameTypeDescription
snumber
tnumber

gltexenv

gltexenv(parameter_name: string, val1: number, val2: number, val3: number, val4: number);
NameTypeDescription
parameter_namestring
val1number
val2number
val3number
val4number

gltexgen

gltexgen(coord: number[], parameter_name: string, val1: number, val2: number, val3: number, val4: number);
NameTypeDescription
coordnumber[]
parameter_namestring
val1number
val2number
val3number
val4number

gltexparameter

gltexparameter(parameter_name: string, val1: number, val2: number, val3: number, val4: number);
NameTypeDescription
parameter_namestring
val1number
val2number
val3number
val4number

gltranslate

gltranslate(x: number, y: number, z: number);
NameTypeDescription
xnumber
ynumber
znumber

gltranslate

gltranslate(translateValues: number[]);
NameTypeDescription
translateValuesnumber[]

glulookat

glulookat(eye_x: number, eye_y: number, eye_z: number, center_x: number, center_y: number, center_z: number, up_x: number, up_y: number, up_z: number);
NameTypeDescription
eye_xnumber
eye_ynumber
eye_znumber
center_xnumber
center_ynumber
center_znumber
up_xnumber
up_ynumber
up_znumber

glulookat

glulookat(lookatValues: number[]);
NameTypeDescription
lookatValuesnumber[]

gluortho2d

gluortho2d(left: number, right: number, bottom: number, top: number);
NameTypeDescription
leftnumber
rightnumber
bottomnumber
topnumber

gluortho2d

gluortho2d(orthoValues: number[]);
NameTypeDescription
orthoValuesnumber[]

gluperspective

gluperspective(fovy: number, aspect: number, near: number, far: number);
NameTypeDescription
fovynumber
aspectnumber
nearnumber
farnumber

gluperspective

gluperspective(perspectiveValues: number[]);
NameTypeDescription
perspectiveValuesnumber[]

glvertex

glvertex(x: number, y: number, z: number);
NameTypeDescription
xnumber
ynumber
znumber

glvertex

glvertex(vertexValues: number[]);
NameTypeDescription
vertexValuesnumber[]

glviewport

glviewport(x: number, y: number, width: number, height: number);
NameTypeDescription
xnumber
ynumber
widthnumber
heightnumber

glviewport

glviewport(viewportValues: number[]);
NameTypeDescription
viewportValuesnumber[]

line

Draw a line relative to the current position

Draws a line from the current drawing position to the location specified by adding the delta x, y, and z arguments to the current position. After this method has been called, the drawing position is updated by an offset relative to the original drawing position.

line(dx: number, dy: number, dz: number);
NameTypeDescription
dxnumberx offset
dynumbery offset
dznumberz offset

linesegment

Draw a line segment

Draws a line from the location specified by the x1, y1, and z1 arguments to the location specified by the x2, y2, and z2 arguments. After this method has been called, the drawing position is updated to the location specified by the x2, y2, and z2 arguments.

linesegment(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number);
NameTypeDescription
x1numberx coordinate of the start point
y1numbery coordinate of the start point
z1numberz coordinate of the start point
x2numberx coordinate of the end point
y2numbery coordinate of the end point
z2numberz coordinate of the end point

lineto

Draw a line to the specified position

Draws a line from the current drawing position to the location specified by the x, y, and z arguments. After this method has been called, the drawing position is updated to the location specified by the x, y, and z arguments.

lineto(x: number, y: number, z: number);
NameTypeDescription
xnumberx coordinate
ynumbery coordinate
znumberz coordinate

move

Move the drawing position relatively

Moves the drawing position to the location specified by the sum of the current drawing position and the delta x, y, and z arguments.

move(dx: number, dy: number, dz: number);
NameTypeDescription
dxnumberx offset
dynumbery offset
dznumberz offset

moveto

Move the current drawing position

Moves the drawing position to the location specified by the x, y, and z arguments.

moveto(x: number, y: number, z: number);
NameTypeDescription
xnumberx coordinate
ynumbery coordinate
znumberz coordinate

ortho3d

Set the default graphics state for rendering with orthographic projection

The orth3d method is a simple way to set the graphics state to default properties useful for 3D graphics, using an orthographic projection (i.e. object scale is not affected by distance from the camera). It is called every time the jsui object is resized if ortho3d() has been called more recently than default2d(), or default3d(). It is essentially equivalent to the following set of calls:

ortho3d();

Example

with (sketch) {
	glpolygonmode("front_and_back", "fill")
	glpointsize(1)
	gllinewidth(1)
	glenable("depth_test")
	glenable("fog")
	glcolor(0, 0, 0, 1)
	glshademodel("smooth")
	gllightmodel("two_side", "true")
	glenable("lighting")
	glenable("light0")
	glenable("normalize")
	gldisable("texture")
	glmatrixmode("projection")
	glloadidentity()
	glortho(-aspect, aspect, -1, 1, -1, 100)
	glmatrixmode("modelview")
	glloadidentity()
	glulookat(0, 0, 2, 0, 0, 0, 0, 0, 1)
	glclearcolor(1, 1, 1, 1)
	glclear()
	glenable("blend")
	glblendfunc("src_alpha", "one_minus_src_alpha")
}

plane

Draw a plane

Draws a plane with top width = 2 * scale_x1, left height = 2 * scale_y1, bottom width = 2 * scale_x2, right height = 2 * scale_y2, and center point at the current drawing position. If scale_y1 is not specified, it will assume the same value as scale_x1. If scale_x2 and scale_y2 are not specified, they will assume the same values as scale_x1 and scale_y1 respectively. Affected by shapeorient, shapeslice, and shapeprim values.

plane(scale_x1: number, scale_y1?: number, scale_x2?: number, scale_y2?: number);
NameTypeDescription
scale_x1numberhalf top width
optional scale_y1numberhalf left height
optional scale_x2numberhalf bottom width
optional scale_y2numberhalf right height

point

Draw a point

Draws a point at the location specified by the x, y, and z arguments. After this method has been called, the drawing position is updated to the specified location.

point(x: number, y: number, z: number);
NameTypeDescription
xnumberx coordinate
ynumbery coordinate
znumberz coordinate

quad

Draw a filled quadrilateral

After this method has been called, the drawing position is updated to the location specified by the x4, y4, and z4 arguments.

quad(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, x3: number, y3: number, z3: number, x4: number, y4: number, z4: number);
NameTypeDescription
x1numberx coordinate of the first point
y1numbery coordinate of the first point
z1numberz coordinate of the first point
x2numberx coordinate of the second point
y2numbery coordinate of the second point
z2numberz coordinate of the second point
x3numberx coordinate of the third point
y3numbery coordinate of the third point
z3numberz coordinate of the third point
x4numberx coordinate of the fourth point
y4numbery coordinate of the fourth point
z4numberz coordinate of the fourth point

roundedplane

Draw a plane with rounded corners

Draws a rounded plane with width = 2 * scale_x, height = 2 * scale_y, and center point at the current drawing position. The radius of the rounded portion of the plane is determined by the round_amount argument. If scale_y is not specified, it will assume the same value as scale_x. Affected by shapeorient, shapeslice, and shapeprim values.

roundedplane(round_amount: number, scale_x1: number, scale_y1?: number);
NameTypeDescription
round_amountnumberradius of the rounded corners
scale_x1numberhalf width
optional scale_y1numberhalf height

screentoworld

Return the world coordinate for a point on screen

Returns an array containing the x, y, and z world coordinates associated with a given screen pixel using the same the depth from the camera as 0, 0, 0. Optionally a third depth arg may be specified, which may be useful for hit detection and other applications. The depth value is typically specified in the range 0.-1. where 0 is the near clipping plane, and 1. is the far clipping plane. The worldtoscreen method can be used to determine the depth value of a given world coordinate, and the Sketch.depthatpixel() method can be used to determine the depth value associated with the currently rendered pixel at a given absolute screen coordinate.

screentoworld(x: number, y: number, depth?: number): [number, number, number];
NameTypeDescription
xnumberscreen x coordinate
ynumberscreen y coordinate
optional depthnumberrange from 0 (near clipping plane) to 1 (far clipping plane)
Return Value[number, number, number]

setpixel

Set the pixel value at a given location

Sets the pixel value at the specified location. Color values are floating point numbers in the range 0.-1.

setpixel(x: number, y: number, red: number, green: number, blue: number, alpha: number);
NameTypeDescription
xnumberx
ynumbery
rednumberred
greennumbergreen
bluenumberblue
alphanumberalpha

shapeorient

Set rotation for shape drawing calls

Sets the rotation in x, y, and z for future shape drawing calls.

shapeorient(rotation_x: number, rotation_y: number, rotation_z: number);
NameTypeDescription
rotation_xnumberx rotation in degrees
rotation_ynumbery rotation in degrees
rotation_znumberz rotation in degrees

shapeprim

Set the drawing primitive shape

Sets the OpenGL drawing primitive to use within any of the "shape" drawing methods.

shapeprim(draw_prim: DrawingPrimitiveType);
NameTypeDescription
draw_primDrawingPrimitiveTypethe drawing primitive to use

shapeslice

Set the number of slices to use when rendering shapes

Increasing the slice_a and slice_b arguments will increase the quality at which the shape is rendered, while decreasing these values will improve performance.

shapeslice(slice_a: number, slice_b: number);
NameTypeDescription
slice_anumbernumber of slices to use
slice_bnumbernumber of slices to use

sphere

Draw a sphere

Draws a sphere with the given radius, centered at the current drawing position. If the theta1_start, theta1_end, theta2_start, and theta2_end arguments are specified, then a section will be drawn instead of a full sphere. Affected by shapeorient, shapeslice, and shapeprim values.

sphere(radius: number, theta1_start?: number, theta1_end?: number, theta2_start?: number, theta2_end?: number);
NameTypeDescription
radiusnumberradius of the sphere
optional theta1_startnumberstart angle in degrees (0 - 360)
optional theta1_endnumberend angle in degrees (0 - 360)
optional theta2_startnumberstart angle in degrees (0 - 360)
optional theta2_endnumberend angle in degrees (0 - 360)

strokeparam

Set the value for a given stroke param. Depending on the parameter, may apply to each point, or to the path as a whole. See Basic2dStrokeStyleParameterNames and LineStrokeStyleParameterNames.

strokeparam(parameter_name: Basic2dStrokeStyleParameterNames.alpha, value: number);
NameTypeDescription
parameter_nameBasic2dStrokeStyleParameterNames.alpha
valuenumber

strokeparam

strokeparam(parameter_name: LineStrokeStyleParameterNames.order, order: number = 3);
NameTypeDescription
parameter_nameLineStrokeStyleParameterNames.order
optional ordernumber

strokeparam

strokeparam(parameter_name: LineStrokeStyleParameterNames.slices, slice_count: number = 20);
NameTypeDescription
parameter_nameLineStrokeStyleParameterNames.slices
optional slice_countnumber

strokeparam

strokeparam(parameter_name: Basic2dStrokeStyleParameterNames.color, red: number, green: number, blue: number, alpha: number);
NameTypeDescription
parameter_nameBasic2dStrokeStyleParameterNames.color
rednumber
greennumber
bluenumber
alphanumber

strokeparam

strokeparam(parameter_name: Basic2dStrokeStyleParameterNames.order, order: number = 3);
NameTypeDescription
parameter_nameBasic2dStrokeStyleParameterNames.order
optional ordernumber

strokeparam

strokeparam(parameter_name: Basic2dStrokeStyleParameterNames.outcolor, red: number, green: number, blue: number, alpha: number);
NameTypeDescription
parameter_nameBasic2dStrokeStyleParameterNames.outcolor
rednumber
greennumber
bluenumber
alphanumber

strokeparam

strokeparam(parameter_name: Basic2dStrokeStyleParameterNames.outline, active: 0 | 1);
NameTypeDescription
parameter_nameBasic2dStrokeStyleParameterNames.outline
active0 | 1

strokeparam

strokeparam(parameter_name: Basic2dStrokeStyleParameterNames.scale, width: number);
NameTypeDescription
parameter_nameBasic2dStrokeStyleParameterNames.scale
widthnumber

strokeparam

strokeparam(parameter_name: Basic2dStrokeStyleParameterNames.slices, slice_count: number = 20);
NameTypeDescription
parameter_nameBasic2dStrokeStyleParameterNames.slices
optional slice_countnumber

strokeparam

strokeparam(parameter_name: LineStrokeStyleParameterNames.alpha, value: number);
NameTypeDescription
parameter_nameLineStrokeStyleParameterNames.alpha
valuenumber

strokeparam

strokeparam(parameter_name: LineStrokeStyleParameterNames.color, red: number, green: number, blue: number, alpha: number);
NameTypeDescription
parameter_nameLineStrokeStyleParameterNames.color
rednumber
greennumber
bluenumber
alphanumber

strokepoint

Add an anchor point to the current path

Some stroke styles such as "basic2d" will ignore the z coordinate.

strokepoint(x: number, y: number, z: number);
NameTypeDescription
xnumberx
ynumbery
znumberz

text

Draw the given text

Draws the text specified by the string argument at the current drawing position, taking into account the current font, fontsize, and text alignment. Text is strictly 2D, and does not take into account any world transformations. After calling the text method, if the x axis text alignment is set to "left", the current drawing position will be updated to reflect the world position associated with the end of the string. If the x axis text alignment is set to "right", the current drawing position will be updated to reflect the world position associated with the end of the string. If the x axis text alignment is set to "center", the current drawing position will remain unchanged.

text(text: string);
NameTypeDescription
textstringtext to draw

textalign

Set the text alignment in x and y

Sets the alignment of text to be drawn with respect to the current drawing position. Default alignment is "left" and "bottom".

textalign(align_x: "left" | "center" | "right", align_y: "top" | "center" | "bottom");
NameTypeDescription
align_x"left" | "center" | "right"horizontal alignment
align_y"top" | "center" | "bottom"vertical alignment

torus

Draw a torus

Draw a torus centered at the current drawing position. If theta1_start, theta1_end, theta2_start, and theta2_end are specified, then a section will be drawn instead of a full torus. Affected by shapeorient, shapeslice, and shapeprim values.

torus(major_radius: number, minor_radius: number, theta1_start?: number, theta1_end?: number, theta2_start?: number, theta2_end?: number);
NameTypeDescription
major_radiusnumbermajor radius
minor_radiusnumberminor radius
optional theta1_startnumberstart angle in degrees (0 - 360)
optional theta1_endnumberend angle in degrees (0 - 360)
optional theta2_startnumberstart angle in degrees (0 - 360)
optional theta2_endnumberend angle in degrees (0 - 360)

tri

Draw a filled triangle

After this method has been called, the drawing position is updated to the location specified by the x3, y3, and z3 arguments.

tri(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, x3: number, y3: number, z3: number);
NameTypeDescription
x1numberx coordinate of the first point
y1numbery coordinate of the first point
z1numberz coordinate of the first point
x2numberx coordinate of the second point
y2numbery coordinate of the second point
z2numberz coordinate of the second point
x3numberx coordinate of the third point
y3numbery coordinate of the third point
z3numberz coordinate of the third point

worldtoscreen

Returns the screen coordinate for a given world coordinate

Returns an array containing the x, y, and depth screen coordinates associated with a given world coordinate. The depth value is typically specified in the range 0.-1. where 0 is the near clipping plane, and 1. is the far clipping plane.

worldtoscreen(x: number, y: number, z: number): [number, number, number];
NameTypeDescription
xnumberworld x coordinate
ynumberworld y coordinate
znumberworld z coordinate
Return Value[number, number, number]