Docs

createBitmap

Creates a Bitmap object from pixel data or a generator function.

Syntax

createBitmap(arrayOrFunction, width, height?)

Parameters

Return value

A Bitmap object.

Generator Function

When providing a function, it should have the signature:

function(byteIndex, x, y) -> number | array | Color

The function is called for each pixel and can return:

Examples

// Create a gradient using a generator function
createBitmap((i, x, y) => [x * 10, y * 10, 128, 255], 32, 32)


// Create from pixel array
let pixels = new Uint8Array([255, 0, 0, 255, 0, 255, 0, 255])
let bmp = createBitmap(pixels, 2, 1)
bmp.width
2
// Create a checkerboard pattern
let checkerboard = createBitmap((i, x, y) => {
  return ((x + y) % 2) * 255
}, 16, 16)
checkerboard.pixels[0]
255

See also