Skip to main content

API Reference

Complete reference for all Klint functions, organized by category.

Drawing Functions

Basic Shapes

FunctionDescriptionParameters
K.circle(x, y, radius, radius2?)Draw a circle or ellipsex, y: center position
radius: circle radius
radius2: optional y-radius for ellipse
K.rectangle(x, y, width, height)Draw a rectanglex, y: top-left position
width, height: dimensions
K.roundedRectangle(x, y, width, height, radius)Draw a rounded rectanglex, y: top-left position
width, height: dimensions
radius: corner radius
K.line(x1, y1, x2, y2)Draw a linex1, y1: start point
x2, y2: end point
K.point(x, y)Draw a pointx, y: position
K.polygon(x, y, sides, radius)Draw a regular polygonx, y: center position
sides: number of sides
radius: radius
K.disk(x, y, radius, startAngle?, endAngle?, closed?)Draw a circle or arc with optional sector closingx, y: center
radius: radius
startAngle, endAngle: radians
closed: connect to center

Paths and Vertices

FunctionDescriptionParameters
K.beginShape()Start a new shapeNone
K.endShape(close?)End the current shapeclose: close the path
K.vertex(x, y)Add a vertexx, y: position
K.bezierVertex(cp1x, cp1y, cp2x, cp2y, x, y)Add a bezier curveControl points and end point
K.quadraticVertex(cpx, cpy, x, y)Add a quadratic curveControl point and end point
K.arcVertex(x, y, radius, startAngle, endAngle, ccw?)Add an arc to pathCenter, radius, and angles
K.beginContour()Start a hole in shapeNone
K.endContour()End the holeNone

Styling Functions

Colors and Stroke

FunctionDescriptionParameters
K.fillColor(color)Set fill colorCSS color string or RGB values
K.strokeColor(color)Set stroke colorCSS color string or RGB values
K.strokeWidth(width)Set stroke widthWidth in pixels
K.strokeCap(cap)Set line cap style'butt', 'round', 'square'
K.strokeJoin(join)Set line join style'miter', 'round', 'bevel'
K.noFill()Disable fillNone
K.noStroke()Disable strokeNone
K.opacity(alpha)Set global opacity0-1
K.blend(mode)Set blend modeBlend mode string

Gradients

FunctionDescriptionParameters
K.gradient(x1, y1, x2, y2)Create linear gradientStart and end points
K.radialGradient(x1, y1, r1, x2, y2, r2)Create radial gradientTwo circles
K.conicGradient(angle, x, y)Create conic gradientStart angle and center
K.addColorStop(offset, color)Add gradient color stop0-1 offset and color

Transform Functions

FunctionDescriptionParameters
K.translate(x, y)Move originx, y: translation
K.rotate(angle)Rotate canvasAngle in radians
K.scale(x, y?)Scale canvasx scale, optional y scale
K.push()Save transform stateNone
K.pop()Restore transform stateNone
K.screenToWorld(x, y)Convert screen coords to world coordsScreen x, y (e.g. mouseX/Y). Call after transforms
K.worldToScreen(x, y)Convert world coords to screen coordsWorld x, y. Call after transforms
K.getVisibleBounds()Get visible area in world coordsNone. Call after transforms

Text Functions

FunctionDescriptionParameters
K.text(text, x, y, maxWidth?)Draw textText string and position
K.textSize(size)Set font sizeSize in pixels
K.textFont(font)Set font familyFont string
K.textAlign(horizontal, vertical?)Set text alignment'left', 'center', 'right'
'top', 'middle', 'bottom'
K.textBaseline(baseline)Set text baseline'alphabetic', 'top', 'middle', etc.
K.measureText(text)Measure text dimensionsText string

Image Functions

FunctionDescriptionParameters
K.image(img, x, y, width?, height?)Draw an imageImage and position
K.createOffscreen(width, height)Create offscreen canvasDimensions
K.loadImage(url)Load an imageURL string
K.getImageData(x, y, width, height)Get pixel dataRectangle bounds
K.putImageData(data, x, y)Put pixel dataImageData and position

Canvas Control

FunctionDescriptionParameters
K.background(color)Clear canvas with colorCSS color string
K.clear()Clear canvasNone
K.reset()Reset all transformsNone
K.save()Save canvas stateNone
K.restore()Restore canvas stateNone

Utility Functions

Math Utilities

FunctionDescriptionParameters
K.distance(x1, y1, x2, y2)Distance between pointsTwo points
K.angle(x1, y1, x2, y2)Angle between pointsTwo points
K.lerp(start, end, amount)Linear interpolationStart, end, amount (0-1)
K.map(value, start1, end1, start2, end2)Map value between rangesValue and two ranges
K.constrain(value, min, max)Constrain value to rangeValue and min/max
K.random(min?, max?)Random numberOptional range
K.noise(x, y?, z?)Perlin noise1D, 2D, or 3D position

Time and Animation

PropertyDescriptionType
K.timeTime since start (ms)number
K.frameFrame countnumber
K.deltaTimeTime since last frame (ms)number
K.fpsCurrent frame ratenumber

Canvas Properties

PropertyDescriptionType
K.widthCanvas widthnumber
K.heightCanvas heightnumber
K.pixelDensityDevice pixel rationumber

Klint Elements

Color Element

  • Color.rgb(r, g, b, a?) - Create from RGB
  • Color.hsl(h, s, l, a?) - Create from HSL
  • Color.hex(hex) - Create from hex string

Vector Element

  • Vector.create(x, y) - Create 2D vector
  • Vector.add(v1, v2) - Add vectors
  • Vector.sub(v1, v2) - Subtract vectors
  • Vector.mult(v, scalar) - Multiply by scalar
  • Vector.normalize(v) - Normalize vector
  • Vector.magnitude(v) - Get magnitude

Time Element

  • Time.now() - Current timestamp
  • Time.delta() - Delta time
  • Time.fps() - Current FPS

Easing Functions

  • Easing.linear(t) - Linear (no easing)
  • Easing.easeInQuad(t) - Quadratic ease in
  • Easing.easeOutQuad(t) - Quadratic ease out
  • Easing.easeInOutQuad(t) - Quadratic ease in/out
  • And many more...

Next Steps