refacto ts + ajout de dessin simple + ajout pinceau

WIP lib graphique
This commit is contained in:
Marc
2022-02-08 13:35:49 +01:00
parent a3547ac244
commit 47e764132f
13 changed files with 255 additions and 66 deletions
+21 -3
View File
@@ -58,9 +58,9 @@ async function readImgFile(filepath) {
/**
* @param { number } x
* @param { number } y
* @param { import('@jimp/core').Bitmap } bitmap
* @param { import('@jimp/core').Bitmap | Pencil } bitmap
*/
function drawBitmap(x, y, bitmap) {
function drawBitmap(x, y, bitmap, handleTransparency = true) {
for(let dy = 0; dy < bitmap.height; dy++) {
let bitmapLineEnd = bitmap.width * screen.byteDepth * (dy + 1)
let bitmapLineStart = bitmap.width * screen.byteDepth * dy
@@ -94,7 +94,25 @@ function drawBitmap(x, y, bitmap) {
const line = bitmap.data.subarray(bitmapLineStart, bitmapLineEnd)
buffer.set(Array.from(line), dx * screen.byteDepth + screen.width * (dy + y) * screen.byteDepth)
const bufferPlacement = dx * screen.byteDepth + screen.width * (dy + y) * screen.byteDepth
if(handleTransparency) {
const currentLine = buffer.subarray(bufferPlacement, bufferPlacement + line.length)
for(let i=0; i < line.length; i += 4) {
const transparency = line.readUInt8(i+3) / 255
if(transparency < 1) {
/** @type { Uint8Array } */
const newLine = new Uint8Array(3)
for(let j=0; j < 3; j++) {
newLine[j] = (currentLine.readUInt8(j+i)*1-transparency + line.readUInt8(j+i)*transparency)
}
line.set(newLine, i)
}
}
}
buffer.set(Array.from(line), bufferPlacement)
}
}
-16
View File
@@ -1,16 +0,0 @@
{
"include": ["./**/*"],
"compilerOptions": {
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
// Generate d.ts files
"declaration": true,
"emitDeclarationOnly": false,
"noEmit": true,
"lib": [ "ES2016" ],
"target": "es2016",
"moduleResolution":"Node",
"noImplicitAny": true,
}
}