MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / generateCharacterAtlas

Function generateCharacterAtlas

src/tools/texture-lab/renderer.js:37–59  ·  view source on GitHub ↗
(charset, cellSize = 16)

Source from the content-addressed store, hash-verified

35import { EFFECT_TYPES, BLEND_MODES, DITHER_METHODS, ASCII_PRESETS } from './types';
36
37function generateCharacterAtlas(charset, cellSize = 16) {
38 const canvas = document.createElement('canvas');
39 const charCount = charset.length;
40 canvas.width = cellSize * charCount;
41 canvas.height = cellSize;
42
43 const ctx = canvas.getContext('2d');
44 ctx.fillStyle = '#000000';
45 ctx.fillRect(0, 0, canvas.width, canvas.height);
46
47 ctx.fillStyle = '#ffffff';
48 ctx.font = `${cellSize * 0.9}px monospace`;
49 ctx.textAlign = 'center';
50 ctx.textBaseline = 'middle';
51
52 for (let i = 0; i < charCount; i++) {
53 const x = i * cellSize + cellSize / 2;
54 const y = cellSize / 2;
55 ctx.fillText(charset[i], x, y);
56 }
57
58 return canvas;
59}
60
61export class WebGLRenderer {
62 constructor(canvas) {

Callers 1

_updateCharacterAtlasMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected