Skip to content

textmode.js / Textmodifier

Class: Textmodifier

The main textmode.js drawing context.

A Textmodifier manages a canvas, renderer, layers, fonts, media sources, input, animation, and the p5-style drawing API. When no canvas is supplied, it creates one; when a canvas is supplied, it renders into or over that element depending on the chosen options.

Properties

PropertyDescription
displayHeightPhysical screen height in pixels.
displayWidthPhysical screen width in pixels.
gamepadsCurrently connected gamepads as a compact readonly list.
lastKeyPressedLast key pressed, or null before any key press.
lastKeyReleasedLast key released, or null before any key release.
modifierStateCurrent modifier key state.
mouseCurrent mouse position in center-based grid coordinates.
mouseIsPressedWhether a mouse button is currently held down.
movedXHorizontal mouse movement accumulated since the previous rendered frame.
movedYVertical mouse movement accumulated since the previous rendered frame.
pmouseMouse position from the previous rendered frame.
pressedKeysKeys currently being held down.
touchesCurrently active touches in grid coordinates.
windowHeightCurrent browser window height in pixels.
windowWidthCurrent browser window width in pixels.

Accessors

AccessorDescription
canvasCanvas containing the rendered output.
conversionsAccess the conversion manager for this Textmodifier instance.
errorsBuilt-in fatal error layer controller.
filtersFilter manager for this Textmodifier instance.
fontFont or tileset used by the current drawing layer.
frameCountCurrent frame count.
gridGrid for the layer currently being drawn.
heightCanvas height in pixels.
isDisposedWhether this instance has been destroyed.
isRenderingFrameCheck if rendering is currently in progress for this frame.
layersLayer manager for this Textmodifier instance.
loadingBuilt-in loading layer controller.
millisMilliseconds since the sketch started running.
overlayOverlay source image for the target canvas or video, when overlay mode is enabled.
secsSeconds since the sketch started running.
widthCanvas width in pixels.

Methods

MethodDescription
absCalculate the absolute value of a number.
acosCalculate the arc cosine of a value.
ambientLightAdd an ambient light using a grayscale value.
applyMatrixMultiply the current model transform by a custom 4x4 matrix.
arcDraw an arc with the current settings. Position is controlled via translate, push, and pop.
asinCalculate the arc sine of a value.
atanCalculate the arc tangent of a value.
atan2Calculate the angle from a vector's y and x components.
backgroundCurrent background color.
bezierCurveDraw a smooth cubic Bezier curve between two points. The curve thickness is controlled by the current lineWeight setting.
boxDraw a box mesh primitive.
cameraSet an explicit camera transform for subsequent draw calls.
ceilRound up to the closest integer.
cellColorCurrent cell background color.
charCurrent character string used for drawing.
charColorCurrent character color.
charRotationSet the character rotation for subsequent drawing, or get the current angle.
clampClamp a value between a minimum and maximum range.
clearClear the layer currently drawing to.
colorCreate a reusable color object from a grayscale value.
colorModeCurrent color interpretation mode.
coneDraw a cone mesh primitive.
constrainConstrain a value between a minimum and maximum range.
cosCalculate the cosine of an angle.
createCameraCreate and activate a camera initialized from the current render camera state.
createFilterShaderCreate a material shader from fragment shader source or a file path.
createFramebufferCreate a framebuffer for offscreen rendering.
createGlyphRampCreate a reusable glyph ramp from a character sequence.
createMaterialShaderCreate a material shader from fragment shader source or a file path.
createShaderCreate a shader from vertex and fragment source, or from file paths.
createTextureCreate a dynamic texture from an external canvas or video element.
createVectorCreate a mutable vector.
cursorSet the mouse cursor for the textmode canvas.
cylinderDraw a cylinder mesh primitive.
degreesConvert radians to degrees.
deltaTimeTime in milliseconds between the current frame and the previous frame.
destroyCompletely destroy this Textmodifier instance and free all associated resources.
distCalculate the Euclidean distance between two points.
doubleClickedRegister the single-callback handler for double-clicks.
doubleTapRegister a callback for double tap gestures.
drawSet the base layer draw callback.
easeApply an easing curve to a normalized amount.
ellipseDraw an ellipse with the current settings. Position is controlled via translate, push, and pop.
ellipsoidDraw an ellipsoid mesh primitive.
exitPointerLockExit pointer lock if the textmode canvas currently owns it.
expCalculate Euler's number raised to a value.
fillAlias for cellColor. Current fill (cell background) color.
filterApply a filter to the final composited output.
finalDrawSet the final post-processing callback for the composited output.
flipXToggle horizontal flipping for subsequent characters, or get the current state.
flipYToggle vertical flipping for subsequent characters, or get the current state.
floorRound down to the closest integer.
fontSizeSet or get the base layer font size.
fractCalculate the fractional part of a number.
frameRateSet the target frame rate, or get the current measured frame rate when called without arguments.
gamepadResolve a connected gamepad by its browser-assigned slot index.
gamepadAxisChangedRegister the single-callback handler for meaningful gamepad axis changes.
gamepadButtonPressedRegister the single-callback handler for gamepad button press events.
gamepadButtonReleasedRegister the single-callback handler for gamepad button release events.
gamepadConnectedRegister the single-callback handler for gamepad connection events.
gamepadDisconnectedRegister the single-callback handler for gamepad disconnection events.
imageDraw a framebuffer, image, video, or texture source to the currently bound framebuffer.
inputGridGet or set the grid used for mouse and touch coordinate mapping.
invertToggle character/cell color inversion, or get the current state.
isKeyPressedCheck whether a key is currently pressed.
isLoopingWhether the automatic render loop is currently running.
keyPressedRegister the single-callback handler for key press events.
keyReleasedRegister the single-callback handler for key release events.
keyTypedRegister the single-callback handler for printable character input.
lerpLinear interpolation between two values.
lightFalloffConfigure distance attenuation used by point lights.
lineDraw a line from (x1, y1) to (x2, y2).
lineWeightSet or get line thickness for subsequent line and curve drawing.
loadFontLoad a font and optionally set it as the base layer's active font.
loadImageLoad an image source that can be drawn with image.
loadTilesetLoad a tileset and optionally set it as the base layer's active glyph source.
loadVideoLoad a video source that can be drawn with image.
logCalculate the natural logarithm of a value.
longPressRegister a callback for long press gestures.
lookAtUpdate the look-at target and optional up vector for the active camera.
loopResume the rendering loop if it was stopped by noLoop.
mapRe-map a number from one range to another.
maxReturn the largest value in a sequence.
minReturn the smallest value in a sequence.
mouseClickedRegister the single-callback handler for mouse clicks.
mouseDraggedRegister the single-callback handler for mouse dragging.
mouseMovedRegister the single-callback handler for mouse movement.
mousePressedRegister the single-callback handler for mouse press events.
mouseReleasedRegister the single-callback handler for mouse release events.
mouseScrolledRegister the single-callback handler for mouse wheel scrolling.
noiseReturn deterministic multi-octave noise for a coordinate.
noiseDetailAdjust noise octaves and falloff.
noiseSeedReset the noise lookup table to a seed.
noLightsRemove all active lights (ambient and point) and reset light falloff to (1, 0, 0).
noLoopStop the automatic rendering loop.
normMap a number from a range to a normalized 0 to 1 range.
offRemove a previously registered input event listener.
onRegister an input event listener.
onceRegister an input event listener that removes itself after the first invocation.
orthoEnable orthographic projection for subsequent shape drawing.
perspectiveEnable perspective projection and optionally set projection parameters.
pinchRegister a callback for pinch gestures, receiving scale deltas.
pixelDensityGet the current pixel density for HiDPI rendering.
pointDraw one cell with the current settings.
pointLightAdd a point light using RGB components and explicit XYZ position.
popRestore the most recently saved rendering state from the state stack. Use with push to isolate style changes within a block.
postDrawSet the base layer post-draw callback.
powRaise a base value to an exponent.
printPrint a string of text onto the active drawing layer.
printAlignSets the text alignment rules for subsequent print calls.
pushSave the current rendering state to the state stack. Use with pop to isolate style changes within a block.
radiansConvert degrees to radians.
randomReturn a random number from 0 up to, but not including, 1.
randomGaussianReturn a normally distributed random number.
randomSeedReset the main sketch random generator to a seed.
randomStreamGet an independent deterministic random stream for a name.
rectDraw a rectangle with the current settings. Position is controlled via translate, push, and pop.
redrawRender a fixed number of frames on demand.
requestPointerLockRequest browser pointer lock for the textmode canvas.
resetCameraReset to the default auto camera behavior.
resetMatrixReset the current model transform to identity.
resetShaderReset the current shader to the default solid color shader.
resizeCanvasResize the canvas and adjust all related components accordingly.
rotateSet rotation for subsequent shape drawing.
rotateGestureRegister a callback for rotate gestures, receiving rotation deltas in degrees.
rotateXSet X-axis rotation for subsequent shape drawing, or get the current angle.
rotateYSet Y-axis rotation for subsequent shape drawing, or get the current angle.
rotateZSet Z-axis rotation for subsequent shape drawing, or get the current angle.
roundRound to the closest integer or decimal place.
scaleScale subsequent geometry in model space.
setCameraActivate a previously created camera object.
setUniformSet a uniform value on the current custom shader.
setUniformsSet multiple uniform values on the current custom shader.
setupSet the setup callback that runs once initialization is complete.
shaderSet a custom shader for subsequent drawing operations.
sinCalculate the sine of an angle.
sphereDraw a sphere mesh primitive.
sqSquare a number.
sqrtCalculate the square root of a number.
strokeAlias for charColor. Current stroke (character) color.
swipeRegister a callback for swipe gestures.
tanCalculate the tangent of an angle.
tapRegister a callback for tap gestures.
targetFrameRateSet or get the target frame rate limit.
torusDraw a torus mesh primitive.
touchCancelledRegister the single-callback handler for browser-cancelled touches.
touchEndedRegister the single-callback handler for touch end events.
touchMovedRegister the single-callback handler for touch movement.
touchStartedRegister the single-callback handler for touch start events.
translateTranslate subsequent shape drawing.
translateXCurrent accumulated X-axis translation.
translateYCurrent accumulated Y-axis translation.
translateZCurrent accumulated Z-axis translation.
triangleDraw a triangle with the current settings.
useTileColorsConfigure authored tileset color preservation on the base layer.
windowResizedSet the callback that runs after a window resize.