setColor(color) — set pen color (red, #FF00FF, etc.) drawCircle(x, y, r) — filled circle at (x,y) radius r drawRect(x, y, w, h) — filled rectangle at (x,y) size w×h drawLine(x1, y1, x2, y2) — line from (x1,y1) to (x2,y2) drawEllipse(x, y, radiusx, radiusy) — draws an ellipse at (x, y) drawTri(x1, y1, x2, y2, x3, y3) — draws a triangle at (x1, y1, x2, y2, x3, y3) strokeCircle(x, y, r) — outlines a circle at (x,y) radius r drawQuad(x1, y1, x2, y2, x3, y3, x4, y4) — draw a quad with all points given strokeTri(x1, y1, x2, y2, x3, y3) — outlines a triangle at (x1, y1, x2, y2, x3, y3) strokeRect(x, y, w, h) — outlines a rectangle at (x,y) size w×h strokeEllipse(x, y, rx, ry) — outlines an ellipse at x and y, with an x radius and y radius. drawText("Text", x, y) — draws said Text at (x, y) setFont("size 'font name'") — example: setFont("16px 'Arial'") setLineWidth(width) — sets the line width for all the stroke shapes and the line. clear() — clear canvas
print("text") — print text to console
for var = start to end { ... } — loop inclusive while condition { ... } - repeats only while condition is met loop { ... } — loop a section of code forever wait(ms) — waits a certain amount of milliseconds
VarName = expression — assign variable (supports math, functions, etc.) myArray = [1, 2, 3] — create an array print(myArray[0]) — access array index myArray[1] = 42 — assign value to index
function myFunc(a, b) { // code block using a and b } myFunc(5, 10) — call function with arguments Supports arrays, variables, math expressions in arguments
These are tested but not debugged.
random(min, max) — random float between min and max randInt(min, max) — random integer between min and max (inclusive) clamp(val, min, max) — restricts val to be between min and max lerp(a, b, t) — linear interpolate from a to b by t (0 ≤ t ≤ 1)
mouseX() — returns current mouse X position mouseY() — returns current mouse Y position mouseIsDown() — true if any mouse button is held mouseWasPressed() — true only on the frame a mouse button was pressed
// comment — single-line comment
Math.sin, Math.cos, Math.tan, Math.asin, Math.acos, Math.atan, Math.atan2, Math.sqrt, Math.abs, Math.floor, Math.ceil, Math.round, Math.PI, Math.E, Math.pow, Math.exp, Math.log, Math.max, Math.min,