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
| Property | Description |
|---|---|
| displayHeight | Physical screen height in pixels. |
| displayWidth | Physical screen width in pixels. |
| gamepads | Currently connected gamepads as a compact readonly list. |
| lastKeyPressed | Last key pressed, or null before any key press. |
| lastKeyReleased | Last key released, or null before any key release. |
| modifierState | Current modifier key state. |
| mouse | Current mouse position in center-based grid coordinates. |
| mouseIsPressed | Whether a mouse button is currently held down. |
| movedX | Horizontal mouse movement accumulated since the previous rendered frame. |
| movedY | Vertical mouse movement accumulated since the previous rendered frame. |
| pmouse | Mouse position from the previous rendered frame. |
| pressedKeys | Keys currently being held down. |
| touches | Currently active touches in grid coordinates. |
| windowHeight | Current browser window height in pixels. |
| windowWidth | Current browser window width in pixels. |
Accessors
| Accessor | Description |
|---|---|
| canvas | Canvas containing the rendered output. |
| conversions | Access the conversion manager for this Textmodifier instance. |
| errors | Built-in fatal error layer controller. |
| filters | Filter manager for this Textmodifier instance. |
| font | Font or tileset used by the current drawing layer. |
| frameCount | Current frame count. |
| grid | Grid for the layer currently being drawn. |
| height | Canvas height in pixels. |
| isDisposed | Whether this instance has been destroyed. |
| isRenderingFrame | Check if rendering is currently in progress for this frame. |
| layers | Layer manager for this Textmodifier instance. |
| loading | Built-in loading layer controller. |
| millis | Milliseconds since the sketch started running. |
| overlay | Overlay source image for the target canvas or video, when overlay mode is enabled. |
| secs | Seconds since the sketch started running. |
| width | Canvas width in pixels. |
Methods
| Method | Description |
|---|---|
| abs | Calculate the absolute value of a number. |
| acos | Calculate the arc cosine of a value. |
| ambientLight | Add an ambient light using a grayscale value. |
| applyMatrix | Multiply the current model transform by a custom 4x4 matrix. |
| arc | Draw an arc with the current settings. Position is controlled via translate, push, and pop. |
| asin | Calculate the arc sine of a value. |
| atan | Calculate the arc tangent of a value. |
| atan2 | Calculate the angle from a vector's y and x components. |
| background | Current background color. |
| bezierCurve | Draw a smooth cubic Bezier curve between two points. The curve thickness is controlled by the current lineWeight setting. |
| box | Draw a box mesh primitive. |
| camera | Set an explicit camera transform for subsequent draw calls. |
| ceil | Round up to the closest integer. |
| cellColor | Current cell background color. |
| char | Current character string used for drawing. |
| charColor | Current character color. |
| charRotation | Set the character rotation for subsequent drawing, or get the current angle. |
| clamp | Clamp a value between a minimum and maximum range. |
| clear | Clear the layer currently drawing to. |
| color | Create a reusable color object from a grayscale value. |
| colorMode | Current color interpretation mode. |
| cone | Draw a cone mesh primitive. |
| constrain | Constrain a value between a minimum and maximum range. |
| cos | Calculate the cosine of an angle. |
| createCamera | Create and activate a camera initialized from the current render camera state. |
| Create a material shader from fragment shader source or a file path. | |
| createFramebuffer | Create a framebuffer for offscreen rendering. |
| createGlyphRamp | Create a reusable glyph ramp from a character sequence. |
| createMaterialShader | Create a material shader from fragment shader source or a file path. |
| createShader | Create a shader from vertex and fragment source, or from file paths. |
| createTexture | Create a dynamic texture from an external canvas or video element. |
| createVector | Create a mutable vector. |
| cursor | Set the mouse cursor for the textmode canvas. |
| cylinder | Draw a cylinder mesh primitive. |
| degrees | Convert radians to degrees. |
| deltaTime | Time in milliseconds between the current frame and the previous frame. |
| destroy | Completely destroy this Textmodifier instance and free all associated resources. |
| dist | Calculate the Euclidean distance between two points. |
| doubleClicked | Register the single-callback handler for double-clicks. |
| doubleTap | Register a callback for double tap gestures. |
| draw | Set the base layer draw callback. |
| ease | Apply an easing curve to a normalized amount. |
| ellipse | Draw an ellipse with the current settings. Position is controlled via translate, push, and pop. |
| ellipsoid | Draw an ellipsoid mesh primitive. |
| exitPointerLock | Exit pointer lock if the textmode canvas currently owns it. |
| exp | Calculate Euler's number raised to a value. |
| fill | Alias for cellColor. Current fill (cell background) color. |
| filter | Apply a filter to the final composited output. |
| finalDraw | Set the final post-processing callback for the composited output. |
| flipX | Toggle horizontal flipping for subsequent characters, or get the current state. |
| flipY | Toggle vertical flipping for subsequent characters, or get the current state. |
| floor | Round down to the closest integer. |
| fontSize | Set or get the base layer font size. |
| fract | Calculate the fractional part of a number. |
| frameRate | Set the target frame rate, or get the current measured frame rate when called without arguments. |
| gamepad | Resolve a connected gamepad by its browser-assigned slot index. |
| gamepadAxisChanged | Register the single-callback handler for meaningful gamepad axis changes. |
| gamepadButtonPressed | Register the single-callback handler for gamepad button press events. |
| gamepadButtonReleased | Register the single-callback handler for gamepad button release events. |
| gamepadConnected | Register the single-callback handler for gamepad connection events. |
| gamepadDisconnected | Register the single-callback handler for gamepad disconnection events. |
| image | Draw a framebuffer, image, video, or texture source to the currently bound framebuffer. |
| inputGrid | Get or set the grid used for mouse and touch coordinate mapping. |
| invert | Toggle character/cell color inversion, or get the current state. |
| isKeyPressed | Check whether a key is currently pressed. |
| isLooping | Whether the automatic render loop is currently running. |
| keyPressed | Register the single-callback handler for key press events. |
| keyReleased | Register the single-callback handler for key release events. |
| keyTyped | Register the single-callback handler for printable character input. |
| lerp | Linear interpolation between two values. |
| lightFalloff | Configure distance attenuation used by point lights. |
| line | Draw a line from (x1, y1) to (x2, y2). |
| lineWeight | Set or get line thickness for subsequent line and curve drawing. |
| loadFont | Load a font and optionally set it as the base layer's active font. |
| loadImage | Load an image source that can be drawn with image. |
| loadTileset | Load a tileset and optionally set it as the base layer's active glyph source. |
| loadVideo | Load a video source that can be drawn with image. |
| log | Calculate the natural logarithm of a value. |
| longPress | Register a callback for long press gestures. |
| lookAt | Update the look-at target and optional up vector for the active camera. |
| loop | Resume the rendering loop if it was stopped by noLoop. |
| map | Re-map a number from one range to another. |
| max | Return the largest value in a sequence. |
| min | Return the smallest value in a sequence. |
| mouseClicked | Register the single-callback handler for mouse clicks. |
| mouseDragged | Register the single-callback handler for mouse dragging. |
| mouseMoved | Register the single-callback handler for mouse movement. |
| mousePressed | Register the single-callback handler for mouse press events. |
| mouseReleased | Register the single-callback handler for mouse release events. |
| mouseScrolled | Register the single-callback handler for mouse wheel scrolling. |
| noise | Return deterministic multi-octave noise for a coordinate. |
| noiseDetail | Adjust noise octaves and falloff. |
| noiseSeed | Reset the noise lookup table to a seed. |
| noLights | Remove all active lights (ambient and point) and reset light falloff to (1, 0, 0). |
| noLoop | Stop the automatic rendering loop. |
| norm | Map a number from a range to a normalized 0 to 1 range. |
| off | Remove a previously registered input event listener. |
| on | Register an input event listener. |
| once | Register an input event listener that removes itself after the first invocation. |
| ortho | Enable orthographic projection for subsequent shape drawing. |
| perspective | Enable perspective projection and optionally set projection parameters. |
| pinch | Register a callback for pinch gestures, receiving scale deltas. |
| pixelDensity | Get the current pixel density for HiDPI rendering. |
| point | Draw one cell with the current settings. |
| pointLight | Add a point light using RGB components and explicit XYZ position. |
| pop | Restore the most recently saved rendering state from the state stack. Use with push to isolate style changes within a block. |
| postDraw | Set the base layer post-draw callback. |
| pow | Raise a base value to an exponent. |
| Print a string of text onto the active drawing layer. | |
| printAlign | Sets the text alignment rules for subsequent print calls. |
| push | Save the current rendering state to the state stack. Use with pop to isolate style changes within a block. |
| radians | Convert degrees to radians. |
| random | Return a random number from 0 up to, but not including, 1. |
| randomGaussian | Return a normally distributed random number. |
| randomSeed | Reset the main sketch random generator to a seed. |
| randomStream | Get an independent deterministic random stream for a name. |
| rect | Draw a rectangle with the current settings. Position is controlled via translate, push, and pop. |
| redraw | Render a fixed number of frames on demand. |
| requestPointerLock | Request browser pointer lock for the textmode canvas. |
| resetCamera | Reset to the default auto camera behavior. |
| resetMatrix | Reset the current model transform to identity. |
| resetShader | Reset the current shader to the default solid color shader. |
| resizeCanvas | Resize the canvas and adjust all related components accordingly. |
| rotate | Set rotation for subsequent shape drawing. |
| rotateGesture | Register a callback for rotate gestures, receiving rotation deltas in degrees. |
| rotateX | Set X-axis rotation for subsequent shape drawing, or get the current angle. |
| rotateY | Set Y-axis rotation for subsequent shape drawing, or get the current angle. |
| rotateZ | Set Z-axis rotation for subsequent shape drawing, or get the current angle. |
| round | Round to the closest integer or decimal place. |
| scale | Scale subsequent geometry in model space. |
| setCamera | Activate a previously created camera object. |
| setUniform | Set a uniform value on the current custom shader. |
| setUniforms | Set multiple uniform values on the current custom shader. |
| setup | Set the setup callback that runs once initialization is complete. |
| shader | Set a custom shader for subsequent drawing operations. |
| sin | Calculate the sine of an angle. |
| sphere | Draw a sphere mesh primitive. |
| sq | Square a number. |
| sqrt | Calculate the square root of a number. |
| stroke | Alias for charColor. Current stroke (character) color. |
| swipe | Register a callback for swipe gestures. |
| tan | Calculate the tangent of an angle. |
| tap | Register a callback for tap gestures. |
| targetFrameRate | Set or get the target frame rate limit. |
| torus | Draw a torus mesh primitive. |
| touchCancelled | Register the single-callback handler for browser-cancelled touches. |
| touchEnded | Register the single-callback handler for touch end events. |
| touchMoved | Register the single-callback handler for touch movement. |
| touchStarted | Register the single-callback handler for touch start events. |
| translate | Translate subsequent shape drawing. |
| translateX | Current accumulated X-axis translation. |
| translateY | Current accumulated Y-axis translation. |
| translateZ | Current accumulated Z-axis translation. |
| triangle | Draw a triangle with the current settings. |
| useTileColors | Configure authored tileset color preservation on the base layer. |
| windowResized | Set the callback that runs after a window resize. |