refacto ts + ajout de dessin simple + ajout pinceau
WIP lib graphique
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// Faire une lib en relatif
|
||||
|
||||
// Faire une api a la xorg
|
||||
|
||||
// Faire une api de changement de resolution
|
||||
|
||||
// Faire des courbes de bézier
|
||||
|
||||
// Géré la transparence
|
||||
|
||||
// Objet de Forme => { stroke & fill }
|
||||
|
||||
// fonts
|
||||
@@ -0,0 +1,101 @@
|
||||
//@ts-check
|
||||
/**
|
||||
* DICKPICK is a image drawing library
|
||||
*/
|
||||
|
||||
const graphics = require('../../chibrax/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
|
||||
*/
|
||||
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 }
|
||||
*/
|
||||
function pencilFromBitmap(Bitmap, color) {
|
||||
return { ...Bitmap, color }
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { number } width
|
||||
* @param { number } height
|
||||
* @returns
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { drawRect, setPixel, pencilFromBitmap, createBitmap, drawCircle }
|
||||
@@ -1,3 +1,7 @@
|
||||
//@ts-check
|
||||
/**
|
||||
* @type {{ [key: string]: string[] }}
|
||||
*/
|
||||
const aliases = {
|
||||
ls: ["ls", "--color"]
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
//@ts-check
|
||||
/**
|
||||
* @type {{ [key: string]: string }}
|
||||
*/
|
||||
let environment = {
|
||||
path: ["/usr/bin", "/usr/sbin", "/usr/lib/sheebr", "/usr/local/bin", "/usr/local/sbin/"],
|
||||
path: ["/usr/bin", "/usr/sbin", "/usr/lib/sheebr", "/usr/local/bin", "/usr/local/sbin/"].join(':'),
|
||||
ls_color: JSON.stringify({
|
||||
di: [01, 34],
|
||||
ln: [01, 36],
|
||||
ex: [01, 32]
|
||||
di: [1, 34],
|
||||
ln: [1, 36],
|
||||
ex: [1, 32]
|
||||
}),
|
||||
node: "/usr/local/bin/node"
|
||||
}
|
||||
|
||||
@@ -1,54 +1,59 @@
|
||||
//@ts-check
|
||||
const { isAlpha } = require('./utils')
|
||||
|
||||
|
||||
class Lexer{
|
||||
constructor(source){
|
||||
this.tokens = [];
|
||||
this.current = 0;
|
||||
this.start = 0;
|
||||
this.source = source
|
||||
}
|
||||
/**
|
||||
* @param { string } source
|
||||
*/
|
||||
constructor(source){
|
||||
/** @type { string[] } */
|
||||
this.tokens = [];
|
||||
this.current = 0;
|
||||
this.start = 0;
|
||||
this.source = source
|
||||
}
|
||||
|
||||
scanTokens(){
|
||||
while(this.current < this.source.length){
|
||||
this.start = this.current
|
||||
this.scanToken()
|
||||
|
||||
}
|
||||
return this.tokens;
|
||||
}
|
||||
|
||||
scanToken(){
|
||||
|
||||
if(this.source[this.current] == "\""){
|
||||
this.string()
|
||||
}
|
||||
else{
|
||||
let content = ""
|
||||
while(this.source[this.current] != ' ' && this.source[this.current] != '\n' && this.current < this.source.length ){
|
||||
content += this.source[this.current];
|
||||
this.current++;
|
||||
|
||||
}
|
||||
this.tokens.push(content)
|
||||
}
|
||||
this.current++;
|
||||
scanTokens(){
|
||||
while(this.current < this.source.length){
|
||||
this.start = this.current
|
||||
this.scanToken()
|
||||
|
||||
}
|
||||
return this.tokens;
|
||||
}
|
||||
|
||||
string(){
|
||||
this.current++;
|
||||
scanToken(){
|
||||
|
||||
if(this.source[this.current] == "\""){
|
||||
this.string()
|
||||
}
|
||||
else{
|
||||
let content = ""
|
||||
while(this.source[this.current] != "\"" && this.current < this.source.length){
|
||||
while(this.source[this.current] != ' ' && this.source[this.current] != '\n' && this.current < this.source.length ){
|
||||
content += this.source[this.current];
|
||||
this.current++;
|
||||
|
||||
}
|
||||
this.tokens.push(content)
|
||||
}
|
||||
this.current++;
|
||||
|
||||
addToken(tokenType, value=""){
|
||||
this.tokens.push(Token(tokenType, value))
|
||||
}
|
||||
|
||||
string(){
|
||||
this.current++;
|
||||
let content = ""
|
||||
while(this.source[this.current] != "\"" && this.current < this.source.length){
|
||||
content += this.source[this.current];
|
||||
this.current++;
|
||||
}
|
||||
this.tokens.push(content)
|
||||
}
|
||||
|
||||
//addToken(tokenType, value=""){
|
||||
// this.tokens.push(Token(tokenType, value))
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ async function getline(str) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } str
|
||||
* @returns
|
||||
*/
|
||||
function isAlpha(str){
|
||||
return /^[a-zA-Z]*$/.test(str)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user