DatumHueEnterprise v0.0.24datumhue.com
Contents

Draw shapes and text

Draw shapes and text on a canvas that keeps them: create each shape once, then move, recolor and group it while your app runs.

Make a canvas and show it

draw.new creates a canvas, a surface for shapes measured in canvas pixels. A canvas shows nothing until you place it in your UI with DrawCanvas:mount. You can mount one canvas in several places.

The origin is the center of the canvas, and Y points up. A shape's pos counts canvas pixels from the center: vec2(-100, 50) is left of the center and above it. Coordinates and units compares this with the UI and with images.

This program draws a hill at dusk with the sun half behind it, a house that drifts back and forth, and a caption in two colors:

scene.lualua
local color = datumhue.color
local vec2 = datumhue.math.vec2
local vec3 = datumhue.math.vec3

local canvas = datumhue.draw.new({
    width = 480,
    height = 320,
    background = color("#2d353b"),
})
canvas:mount({ width = 480, height = 320 })

canvas:ellipse({
    pos = vec2(0, -170),
    rx = 320,
    ry = 120,
    color = color("#a7c080"),
})

-- Drawn after the hill, but z = -1 puts the sun behind it.
canvas:circle({
    pos = vec3(140, -62, -1),
    radius = 50,
    color = color("#dbbc7f"),
})

-- A house of three shapes that move as one.
local walls = canvas:rect({
    pos = vec2(-40, -60),
    width = 80,
    height = 60,
    color = color("#e67e80"),
})
local roof = canvas:polygon({
    points = { vec2(-52, 0), vec2(52, 0), vec2(0, 44) },
    color = color("#d699b6"),
})
local door = canvas:rect({
    pos = vec2(-10, -60),
    width = 20,
    height = 34,
    color = color("#475258"),
})
local house = canvas:group({ walls, roof, door })
house:animate({
    pos = vec2(-140, 0),
    duration = 2,
    easing = "sine_in_out",
    looping = true,
})

canvas:text({
    pos = vec2(-220, 140),
    text = "Home, ",
    font_size = 28,
    color = color("#d3c6aa"),
    spans = {
        { text = "sweet", color = color("#7fbbb3") },
        { text = " home" },
    },
})

In this example: datumhue.color datumhue.math.vec2 datumhue.math.vec3 datumhue.draw.new DrawCanvas:mount DrawCanvas:ellipse DrawCanvas:circle DrawCanvas:rect DrawCanvas:polygon DrawCanvas:group DrawPrimitive:animate DrawCanvas:text

Change a shape instead of redrawing it

Each constructor, such as DrawCanvas:circle or DrawCanvas:polygon, returns a DrawPrimitive. The shape stays on the canvas, frame after frame, until you call DrawPrimitive:remove. You never clear and redraw a canvas each frame.

To change a shape, change its handle: assign DrawPrimitive.pos, DrawPrimitive.rotation or DrawPrimitive.opacity, pass new values to DrawPrimitive:update, or tween them with DrawPrimitive:animate, as the house does.

Put one shape in front of another

Shapes you create without a z stack in creation order: each new shape draws on top of the ones before it. Give pos a vec3 to set the depth yourself. An explicit z wins over creation order, and a larger z draws in front. The sun is created after the hill, but its z of -1 puts it behind.

Move shapes together

DrawCanvas:group gathers shapes into a group, itself a DrawPrimitive. Moving, hiding or fading the group moves, hides or fades every shape in it, and removing it removes them all. Groups nest. DrawPrimitive.parent names the group a shape belongs to; assign it to move the shape into another group.

Draw text

DrawCanvas:text draws text from its top-left corner. Its spans add runs with their own color, size, weight or face after the main text, as the caption's "sweet" shows. draw.measure_text tells you how large text will be before you draw it, to center it or fit it in a box, and max_width wraps long lines.

Blend shapes

Shapes blend with ordinary transparency: a lower opacity, or a color with alpha, lets what is behind show through. For additive glow, multiply or screen, draw into an image instead, where Picture:blit takes a blend mode (Pixel art and sprites), or give the shape a shader as its material (Shaders).

Draw shapes or draw pixels

DatumHue has two ways to draw in 2D. Pick the one that matches how you think about the picture:

Draw canvasImage and picture
You work withshapes you create once and changecommands you record and replay onto pixels
Origin and Ycenter, Y uptop-left corner, Y down
Each framechange the shapes that moverebuild the picture and apply it
Use it formoving objects, diagrams, physicspixel art, retro framebuffers, painting

The two meet: DrawCanvas:image draws a whole image on a canvas, and DrawCanvas:sprite draws one cell of a sprite sheet.

See also

Reference used on this page: datumhue.color datumhue.math.vec2 datumhue.math.vec3 datumhue.draw.new DrawCanvas:mount DrawCanvas:ellipse DrawCanvas:circle DrawCanvas:rect DrawCanvas:polygon DrawCanvas:group DrawPrimitive:animate DrawCanvas:text datumhue.image.new datumhue.scene.new DrawPrimitive:remove DrawPrimitive.pos DrawPrimitive.rotation DrawPrimitive.opacity DrawPrimitive:update DrawPrimitive.parent datumhue.draw.measure_text Picture:blit DrawCanvas:image DrawCanvas:sprite

datumhue.com

(c) 2026 Shuusei AB. Quote excerpts of this manual, with attribution to DatumHue, in your own documentation, tutorials, course materials, reviews, and other writing or video. Republishing it in whole or in substantial part needs written permission: support@datumhue.com.

Victor Mono is licensed under the SIL Open Font License 1.1
Copyright (c) 2024, Rune Bjørnerås (https://github.com/rubjo)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Try

    ↑↓ selectEnter openTab filter

    Settings

    Theme
    Text
    Print

    Keyboard shortcuts

    / or Ctrl KSearch
    ↑ ↓ EnterPick a result
    TabNext result filter
    j kNext or previous entry
    [ ]Previous or next page
    yCopy a link to the current entry
    ?These shortcuts
    EscClose

    On this page