mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-20 04:24:45 +00:00
Merge pull request #17 from WFBarnes/main
Implemented alternative trig functions (cosh, sinh, r2d, d2r), optimized Paint, introduced _strokeThickness constant.
This commit is contained in:
commit
c05c17b09e
7 changed files with 37 additions and 6 deletions
BIN
.vs/qbjs/v17/.suo
Normal file
BIN
.vs/qbjs/v17/.suo
Normal file
Binary file not shown.
BIN
.vs/slnx.sqlite
Normal file
BIN
.vs/slnx.sqlite
Normal file
Binary file not shown.
BIN
.vs/slnx.sqlite-journal
Normal file
BIN
.vs/slnx.sqlite-journal
Normal file
Binary file not shown.
|
@ -35,11 +35,11 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
||||||
// TODO: adjust for QB
|
// TODO: adjust for QB
|
||||||
var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];
|
var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];
|
||||||
|
|
||||||
var builtinFuncsWords = ['_alpha', '_alpha32', '_atan2', '_autodisplay', '_blue', '_blue32', '_continue', '_copyimage', '_delay', '_dest', '_dest',
|
var builtinFuncsWords = ['_alpha', '_alpha32', '_atan2', '_autodisplay', '_blue', '_blue32', '_continue', '_copyimage', '_cosh', '_d2r', '_delay', '_dest', '_dest',
|
||||||
'_display', '_fontwidth', '_freeimage', '_green', '_green32', '_height', '_instrrev', '_limit', '_keyclear', '_keydown',
|
'_display', '_fontwidth', '_freeimage', '_green', '_green32', '_height', '_instrrev', '_limit', '_keyclear', '_keydown',
|
||||||
'_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth',
|
'_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth',
|
||||||
'_putimage', '_red', '_red32', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
|
'_putimage', '_r2d', '_red', '_red32', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
|
||||||
'_screenexists', '_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol',
|
'_screenexists', '_sinh', '_sndclose', '_sndopen', '_sndplay', '_sndloop', '_sndpause', '_sndstop', '_sndvol',
|
||||||
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'exp',
|
'_title', '_trim', '_width', 'abs', 'asc', 'atn', 'chr', 'circle', 'cls', 'color', 'command', 'cos', 'cvi', 'cvl', 'exp',
|
||||||
'fix', 'hex', 'input', 'inkey', 'instr', 'int', 'lbound', 'left', 'lcase', 'len', 'line', 'locate', 'log', 'ltrim', 'mid', 'mki', 'mkl',
|
'fix', 'hex', 'input', 'inkey', 'instr', 'int', 'lbound', 'left', 'lcase', 'len', 'line', 'locate', 'log', 'ltrim', 'mid', 'mki', 'mkl',
|
||||||
'oct', 'paint', 'point', 'preset', 'print', 'pset', 'right', 'rtrim', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr', 'str', 'swap', 'tan',
|
'oct', 'paint', 'point', 'preset', 'print', 'pset', 'right', 'rtrim', 'rnd', 'screen', 'shared', 'sgn', 'sin', 'sleep', 'space', 'sqr', 'str', 'swap', 'tan',
|
||||||
|
|
29
qb.js
29
qb.js
|
@ -5,7 +5,7 @@ var QB = new function() {
|
||||||
this.LOCAL = Symbol("LOCAL");
|
this.LOCAL = Symbol("LOCAL");
|
||||||
this.SESSION = Symbol("SESSION");
|
this.SESSION = Symbol("SESSION");
|
||||||
|
|
||||||
|
var _strokeThickness = 2;
|
||||||
var _fgColor = null;
|
var _fgColor = null;
|
||||||
var _bgColor = null;
|
var _bgColor = null;
|
||||||
var _colormap = [];
|
var _colormap = [];
|
||||||
|
@ -163,6 +163,14 @@ var QB = new function() {
|
||||||
return destImageId;
|
return destImageId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.func__Cosh = function(x) {
|
||||||
|
return (Math.exp(x)+Math.exp(-x))/2;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.func__D2R = function(x) {
|
||||||
|
return x*Math.PI/180;
|
||||||
|
};
|
||||||
|
|
||||||
this.sub__Delay = async function(seconds) {
|
this.sub__Delay = async function(seconds) {
|
||||||
await GX.sleep(seconds*1000);
|
await GX.sleep(seconds*1000);
|
||||||
};
|
};
|
||||||
|
@ -409,6 +417,10 @@ var QB = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.func__R2D = function(x) {
|
||||||
|
return x*180/Math.PI;
|
||||||
|
};
|
||||||
|
|
||||||
this.func__Red = function(rgb, imageHandle) {
|
this.func__Red = function(rgb, imageHandle) {
|
||||||
// TODO: implement corresponding logic when an image handle is supplied (maybe)
|
// TODO: implement corresponding logic when an image handle is supplied (maybe)
|
||||||
return _color(rgb).r;
|
return _color(rgb).r;
|
||||||
|
@ -471,6 +483,10 @@ var QB = new function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.func__Sinh = function(x) {
|
||||||
|
return (Math.exp(x)-Math.exp(-x))/2;
|
||||||
|
};
|
||||||
|
|
||||||
this.sub__SndClose = function(sid) {
|
this.sub__SndClose = function(sid) {
|
||||||
GX.soundClose(sid);
|
GX.soundClose(sid);
|
||||||
};
|
};
|
||||||
|
@ -753,6 +769,7 @@ var QB = new function() {
|
||||||
screen.lastY = y;
|
screen.lastY = y;
|
||||||
|
|
||||||
var ctx = screen.ctx;
|
var ctx = screen.ctx;
|
||||||
|
ctx.lineWidth = _strokeThickness;
|
||||||
ctx.strokeStyle = color.rgba();
|
ctx.strokeStyle = color.rgba();
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
if (aspect == undefined) {
|
if (aspect == undefined) {
|
||||||
|
@ -801,6 +818,7 @@ var QB = new function() {
|
||||||
screen.lastY = ey;
|
screen.lastY = ey;
|
||||||
|
|
||||||
var ctx = screen.ctx;
|
var ctx = screen.ctx;
|
||||||
|
ctx.lineWidth = _strokeThickness;
|
||||||
|
|
||||||
if (style == "B") {
|
if (style == "B") {
|
||||||
ctx.strokeStyle = color.rgba();
|
ctx.strokeStyle = color.rgba();
|
||||||
|
@ -882,6 +900,10 @@ var QB = new function() {
|
||||||
y0 = screen.lastY + y0;
|
y0 = screen.lastY + y0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (borderColor == undefined) {
|
||||||
|
borderColor = fillColor;
|
||||||
|
}
|
||||||
|
|
||||||
var pixelStack = [[Math.floor(x0), Math.floor(y0)]];
|
var pixelStack = [[Math.floor(x0), Math.floor(y0)]];
|
||||||
|
|
||||||
while (pixelStack.length) {
|
while (pixelStack.length) {
|
||||||
|
@ -936,8 +958,9 @@ var QB = new function() {
|
||||||
var g = dat[p+1];
|
var g = dat[p+1];
|
||||||
var b = dat[p+2];
|
var b = dat[p+2];
|
||||||
//var a = dat[p+3];
|
//var a = dat[p+3];
|
||||||
if ((r == c1.r) && (g == c1.g) && (b == c1.b)) { return false; }
|
var thresh = 2;
|
||||||
if ((r == c2.r) && (g == c2.g) && (b == c2.b)) { return false; }
|
if ((Math.abs(r - c1.r) < thresh) && (Math.abs(g - c1.g) < thresh) && (Math.abs(b - c1.b) < thresh)) { return false; }
|
||||||
|
if ((Math.abs(r - c2.r) < thresh) && (Math.abs(g - c2.g) < thresh) && (Math.abs(b - c2.b) < thresh)) { return false; }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
qb2js.js
4
qb2js.js
|
@ -2500,6 +2500,8 @@ if (QB.halted()) { return; }
|
||||||
await sub_AddQBMethod( "FUNCTION", "_Blue", False);
|
await sub_AddQBMethod( "FUNCTION", "_Blue", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_Blue32", False);
|
await sub_AddQBMethod( "FUNCTION", "_Blue32", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_CopyImage", False);
|
await sub_AddQBMethod( "FUNCTION", "_CopyImage", False);
|
||||||
|
await sub_AddQBMethod( "FUNCTION", "_Cosh", False);
|
||||||
|
await sub_AddQBMethod( "FUNCTION", "_D2R", False);
|
||||||
await sub_AddQBMethod( "SUB", "_Delay", True);
|
await sub_AddQBMethod( "SUB", "_Delay", True);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_Dest", False);
|
await sub_AddQBMethod( "FUNCTION", "_Dest", False);
|
||||||
await sub_AddQBMethod( "SUB", "_Dest", False);
|
await sub_AddQBMethod( "SUB", "_Dest", False);
|
||||||
|
@ -2525,6 +2527,7 @@ if (QB.halted()) { return; }
|
||||||
await sub_AddQBMethod( "SUB", "_PrintString", False);
|
await sub_AddQBMethod( "SUB", "_PrintString", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_PrintWidth", False);
|
await sub_AddQBMethod( "FUNCTION", "_PrintWidth", False);
|
||||||
await sub_AddQBMethod( "SUB", "_PutImage", False);
|
await sub_AddQBMethod( "SUB", "_PutImage", False);
|
||||||
|
await sub_AddQBMethod( "FUNCTION", "_R2D", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_Red", False);
|
await sub_AddQBMethod( "FUNCTION", "_Red", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_Red32", False);
|
await sub_AddQBMethod( "FUNCTION", "_Red32", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_Resize", False);
|
await sub_AddQBMethod( "FUNCTION", "_Resize", False);
|
||||||
|
@ -2536,6 +2539,7 @@ if (QB.halted()) { return; }
|
||||||
await sub_AddQBMethod( "FUNCTION", "_RGBA32", False);
|
await sub_AddQBMethod( "FUNCTION", "_RGBA32", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_Round", False);
|
await sub_AddQBMethod( "FUNCTION", "_Round", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_ScreenExists", False);
|
await sub_AddQBMethod( "FUNCTION", "_ScreenExists", False);
|
||||||
|
await sub_AddQBMethod( "FUNCTION", "_Sinh", False);
|
||||||
await sub_AddQBMethod( "SUB", "_SndClose", False);
|
await sub_AddQBMethod( "SUB", "_SndClose", False);
|
||||||
await sub_AddQBMethod( "FUNCTION", "_SndOpen", False);
|
await sub_AddQBMethod( "FUNCTION", "_SndOpen", False);
|
||||||
await sub_AddQBMethod( "SUB", "_SndPlay", False);
|
await sub_AddQBMethod( "SUB", "_SndPlay", False);
|
||||||
|
|
|
@ -2658,6 +2658,8 @@ Sub InitQBMethods
|
||||||
AddQBMethod "FUNCTION", "_Blue", False
|
AddQBMethod "FUNCTION", "_Blue", False
|
||||||
AddQBMethod "FUNCTION", "_Blue32", False
|
AddQBMethod "FUNCTION", "_Blue32", False
|
||||||
AddQBMethod "FUNCTION", "_CopyImage", False
|
AddQBMethod "FUNCTION", "_CopyImage", False
|
||||||
|
AddQBMethod "FUNCTION", "_Cosh", False
|
||||||
|
AddQBMethod "FUNCTION", "_D2R", False
|
||||||
AddQBMethod "SUB", "_Delay", True
|
AddQBMethod "SUB", "_Delay", True
|
||||||
AddQBMethod "FUNCTION", "_Dest", False
|
AddQBMethod "FUNCTION", "_Dest", False
|
||||||
AddQBMethod "SUB", "_Dest", False
|
AddQBMethod "SUB", "_Dest", False
|
||||||
|
@ -2683,6 +2685,7 @@ Sub InitQBMethods
|
||||||
AddQBMethod "SUB", "_PrintString", False
|
AddQBMethod "SUB", "_PrintString", False
|
||||||
AddQBMethod "FUNCTION", "_PrintWidth", False
|
AddQBMethod "FUNCTION", "_PrintWidth", False
|
||||||
AddQBMethod "SUB", "_PutImage", False
|
AddQBMethod "SUB", "_PutImage", False
|
||||||
|
AddQBMethod "FUNCTION", "_R2D", False
|
||||||
AddQBMethod "FUNCTION", "_Red", False
|
AddQBMethod "FUNCTION", "_Red", False
|
||||||
AddQBMethod "FUNCTION", "_Red32", False
|
AddQBMethod "FUNCTION", "_Red32", False
|
||||||
AddQBMethod "FUNCTION", "_Resize", False
|
AddQBMethod "FUNCTION", "_Resize", False
|
||||||
|
@ -2694,6 +2697,7 @@ Sub InitQBMethods
|
||||||
AddQBMethod "FUNCTION", "_RGBA32", False
|
AddQBMethod "FUNCTION", "_RGBA32", False
|
||||||
AddQBMethod "FUNCTION", "_Round", False
|
AddQBMethod "FUNCTION", "_Round", False
|
||||||
AddQBMethod "FUNCTION", "_ScreenExists", False
|
AddQBMethod "FUNCTION", "_ScreenExists", False
|
||||||
|
AddQBMethod "FUNCTION", "_Sinh", False
|
||||||
AddQBMethod "SUB", "_SndClose", False
|
AddQBMethod "SUB", "_SndClose", False
|
||||||
AddQBMethod "FUNCTION", "_SndOpen", False
|
AddQBMethod "FUNCTION", "_SndOpen", False
|
||||||
AddQBMethod "SUB", "_SndPlay", False
|
AddQBMethod "SUB", "_SndPlay", False
|
||||||
|
|
Loading…
Reference in a new issue