Skip to content

0G Drawing text to the canvas

Luis Murillo Baltodano edited this page Aug 30, 2020 · 5 revisions

Need an object like

txt {
    x Number                           // canvas x coord
    y Number                           // canvas y coord
    c CanvasColorString                // foreground color
    font CanvasRenderingContext2D.font // text style
    text String                         // text to show
}

More about CanvasRenderingContext2D.font

Use the render function

render(myTextObject).text()

Example

const myTextObject= {
    x: 73,
    y: 42,
    font: '10px monospace',
    color: '#44f',
    text: 'Hello, Canvas Preset'
}

preset(({size, render}) => {
    size()
    render(myTextObject).text()
}, '#canvasForText')
Clone this wiki locally