mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-23 05:26:15 -04:00
Build 29035725
This commit is contained in:
parent
a1bf54af71
commit
819197031f
64 changed files with 3494 additions and 6921 deletions
46
src/levelIcon.ts
Normal file
46
src/levelIcon.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
let levelIconHTMLCanvas = document.createElement("canvas");
|
||||
|
||||
const levelIconHTMLCanvasCtx =
|
||||
process.env.NODE_ENV !== "test" &&
|
||||
(levelIconHTMLCanvas.getContext("2d", {
|
||||
antialias: false,
|
||||
alpha: true,
|
||||
}) as CanvasRenderingContext2D);
|
||||
|
||||
export function levelIconHTML(
|
||||
bricks: string[],
|
||||
levelSize: number,
|
||||
color: string,
|
||||
) {
|
||||
const size = 40;
|
||||
const c = levelIconHTMLCanvas;
|
||||
const ctx = levelIconHTMLCanvasCtx;
|
||||
|
||||
if (!ctx) return "";
|
||||
c.width = size;
|
||||
c.height = size;
|
||||
|
||||
if (color) {
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillRect(0, 0, size, size);
|
||||
} else {
|
||||
ctx.clearRect(0, 0, size, size);
|
||||
}
|
||||
const pxSize = size / levelSize;
|
||||
for (let x = 0; x < levelSize; x++) {
|
||||
for (let y = 0; y < levelSize; y++) {
|
||||
const c = bricks[y * levelSize + x];
|
||||
if (c) {
|
||||
ctx.fillStyle = c;
|
||||
ctx.fillRect(
|
||||
Math.floor(pxSize * x),
|
||||
Math.floor(pxSize * y),
|
||||
Math.ceil(pxSize),
|
||||
Math.ceil(pxSize),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return `<img alt="" width="${size}" height="${size}" src="${c.toDataURL()}"/>`;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue