Creates a Bitmap object from pixel data or a generator function.
createBitmap(arrayOrFunction, width, height?)
arrayOrFunction
Either a Uint8Array or array containing RGBA pixel data, or a function that generates pixels.
width
The width of the bitmap in pixels.
height optional
The height of the bitmap in pixels. If not specified, defaults to width (square bitmap).
A Bitmap object.
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:
[r, g, b, a] for RGBA valuesColor object// 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