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
+29 -20
View File
@@ -1,27 +1,36 @@
//@ts-check
const graphics = require('../../chibrax/graphics')
const shapes = require('../lib/shapes')
const path = require('path')
graphics.clear()
drawChibrax()
const bitmap = shapes.createBitmap(400, 400)
const pencil = shapes.pencilFromBitmap(bitmap, [0,255, 0,255])
shapes.drawCircle(pencil, 200, 200, 190)
graphics.drawBitmap(0, 0, pencil)
graphics.flip()
function drawChibrax() {
//LA LETTRE C
for(let i = 0; i < 100; i++) {
for(let j = 0; j < 10; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 0; i < 20; i++) {
for(let j = 10; j < 110; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 0; i < 100; i++) {
for(let j = 110; j < 120; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
@@ -29,106 +38,106 @@ function drawChibrax() {
//LA LETTRE H
for(let i = 110; i < 130; i++) {
for(let j = 0; j < 100; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 110; i < 210; i++) {
for(let j = 50; j < 60; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 210; i < 230; i++) {
for(let j = 0; j < 100; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
//LA LETTRE I
for(let i = 240; i < 260; i++) {
for(let j = 0; j < 100; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
//LA LETTRE B
for(let i = 270; i < 280; i++) {
for(let j = 0; j < 100; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 380; i < 390; i++) {
for(let j = 0; j < 100; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 270; i < 390; i++) {
for(let j = 0; j < 10; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 270; i < 390; i++) {
for(let j = 50; j < 60; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 270; i < 390; i++) {
for(let j = 90; j < 100; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
//LA LETTRE R
for(let i = 400; i < 410; i++) {
for(let j = 0; j < 100; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 510; i < 520; i++) {
for(let j = 0; j < 100; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 400; i < 520; i++) {
for(let j = 0; j < 10; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 400; i < 520; i++) {
for(let j = 50; j < 60; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
//LA LETTRE E
for(let i = 530; i < 630; i++) {
for(let j = 0; j < 10; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 530; i < 550; i++) {
for(let j = 10; j < 110; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 530; i < 630; i++) {
for(let j = 50; j < 60; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
for(let i = 530; i < 630; i++) {
for(let j = 110; j < 120; j++) {
graphics.setPixel(i,j, [0,0,255,0])
graphics.setPixel(i,j, [0,0,255, 255])
}
}
+20 -3
View File
@@ -7,6 +7,10 @@ let aliases = require("../lib/sheebr/aliases")
let { spawn } = require('child_process')
//utiliser ce code au lieux de execSync permet d'afficher le stdout au fur et a mesure ce qui fait qu'on a les logs quand une application throw une erreur
/**
* @param { string } cmd
* @param { import('child_process').SpawnOptionsWithoutStdio } [option]
*/
async function spawnAndWait(cmd, option) {
const child = spawn(cmd, option)
@@ -36,6 +40,10 @@ async function start(){
}
}
/**
* @param { string } input
* @returns
*/
async function evaluate(input){
let lexer = new Lexer(input)
let args = lexer.scanTokens()
@@ -70,12 +78,13 @@ async function evaluate(input){
}
/**
* @param {string[]} args
*/
async function evaluateProgram(args){
let found = false;
for(let path of environment.path){
for(let path of environment.path.split(':')){
let tobreak = false;
const files = fs.readdirSync(path);
if(files.includes(`${args[0]}.js`)){
@@ -95,6 +104,10 @@ async function evaluateProgram(args){
}
}
/**
* @param {string[]} args
* @returns
*/
function evaluateEnvironmentVariables(args){
let newArgs = []
for(let arg of args){
@@ -111,6 +124,10 @@ function evaluateEnvironmentVariables(args){
return newArgs;
}
/**
* @param { string[] } args
* @returns
*/
function evaluateAliases(args){
if(args[0] in aliases){
return aliases[args[0]].concat(args.slice(1))