721c919c7b
Changes: - kernel 6.0.2 - Broken init scripts - Switch to bun for better peroformance an easier ffi - Removed grup - Efi support without graphics (at least graphics werent tested) - Suppression de toutes les dépendance non libc - new splash - broken audio - typescript support - ls rewritten to be more reliable
99 lines
2.1 KiB
JavaScript
99 lines
2.1 KiB
JavaScript
//@ts-check
|
|
/**
|
|
* DICKPICK is a image drawing library
|
|
*/
|
|
|
|
import * as graphics from '../../core/graphics'
|
|
|
|
/**
|
|
* @param { number } x
|
|
* @param { number } y
|
|
* @param { number } dx length on the x axis
|
|
* @param { number } dy length on the y axis
|
|
* @param { string } color
|
|
*/
|
|
export function drawRect(x, y, dx, dy, color) {
|
|
const bitmap = {
|
|
data: Buffer.alloc(dx*dy*4, Buffer.from(graphics.parseHexColor(color))),
|
|
width: dx,
|
|
height: dy
|
|
}
|
|
|
|
graphics.drawBitmap(x,y, bitmap)
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param { import('@jimp/core').Bitmap } Bitmap
|
|
* @param { number[] } color
|
|
* @returns { Pencil }
|
|
*/
|
|
export function pencilFromBitmap(Bitmap, color) {
|
|
return { ...Bitmap, color }
|
|
}
|
|
|
|
/**
|
|
* @param { number } width
|
|
* @param { number } height
|
|
* @returns
|
|
*/
|
|
export function createBitmap(width, height) {
|
|
const data = Buffer.alloc(width * height * 4, Buffer.from([0, 0, 0, 0]));
|
|
return { width, height, data }
|
|
}
|
|
|
|
/**
|
|
* @param { Pencil } pencil
|
|
* @param { number } x
|
|
* @param { number } y
|
|
*/
|
|
export function setPixel(pencil, x, y) {
|
|
pencil.data.set(pencil.color, y*pencil.width*4 + x*4)
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
* @param { number } x
|
|
* @param { number } y
|
|
* @param { number } xc
|
|
* @param { number } yc
|
|
* @param { Pencil } pencil
|
|
*/
|
|
export function symetrie8Axes(xc, yc, x, y, pencil) {
|
|
setPixel(pencil, x+xc, y+yc)
|
|
setPixel(pencil, x+xc,-y+yc)
|
|
setPixel(pencil, -x+xc,-y+yc)
|
|
setPixel(pencil, -x+xc,y+yc)
|
|
setPixel(pencil, y+xc,x+yc)
|
|
setPixel(pencil, y+xc,-x+yc)
|
|
setPixel(pencil, -y+xc,-x+yc)
|
|
setPixel(pencil, -y+xc,x+yc,)
|
|
}
|
|
|
|
/**
|
|
* BresenhamCircle
|
|
* @param { Pencil } pencil
|
|
* @param { number } xc
|
|
* @param { number } yc
|
|
* @param { number } r
|
|
*/
|
|
export function drawCircle(pencil, xc, yc, r) {
|
|
let x = 0
|
|
let y = r
|
|
let d = 3 - (2 * r);
|
|
symetrie8Axes(xc, yc, x, y, pencil);
|
|
|
|
while(x <= y) {
|
|
if(d <= 0) {
|
|
d = d + (4 * x) + 6;
|
|
}
|
|
else {
|
|
d = d + (4 * x) - (4 * y) + 10;
|
|
y = y - 1;
|
|
}
|
|
x = x + 1;
|
|
symetrie8Axes(xc, yc, x, y, pencil);
|
|
}
|
|
}
|