xxxxxxxxxx
48
function setup() {
pixelDensity(1)
createCanvas(960, 540)
background(0)
}
function draw() {
loadPixels()
// bit field data
let logo = 105684975
// text position
const offsetX = 128
const offsetY = 128
let ox = offsetX + offsetY * width
// some constants
const blockWidth = 64
const blockHeight = 64
const glyphWidth = 64 * 4
const glyphHeight = 64 * 3
// iterate until there is no glyph
while (logo > 0) {
// iterate whole glyph on screen
for (let i = 0; i < glyphWidth * glyphHeight; i += 1) {
const x = i & 255
const y = i >> 8
const bi = x >> 6
const bbi = bi + (y >> 6) * 3 // bit field bit index
const br = ((logo >> bbi) & 0x1) * 255 // get glyph bit from given index
if (bi < 3) { // spacing
const index = (ox + x + y * width) * 4
pixels[index + 0] = br
pixels[index + 1] = br
pixels[index + 2] = br
}
}
// go to the next glyph
logo >>= 9
ox += glyphWidth
}
updatePixels()
}