mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-20 04:24:45 +00:00
Prototyped Draw function. Implemented stand-in for Varptr$. Fixed hexrep permutation and alpha scale.
This commit is contained in:
parent
ef8dd31757
commit
f532d5c565
4 changed files with 262 additions and 5 deletions
|
@ -40,10 +40,10 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
|||
'_keyhit', '_loadimage', '_mousebutton', '_mouseinput', '_mousex', '_mousey', '_newimage', '_pi', '_printstring', '_printwidth',
|
||||
'_putimage', '_r2d', '_red', '_red32', '_resize', '_resizewidth', '_resizeheight', '_rgb', '_rgba', '_rgb32', '_rgba32', '_round',
|
||||
'_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', 'draw', 'exp',
|
||||
'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',
|
||||
'timer', 'ubound', 'ucase', 'val',
|
||||
'timer', 'ubound', 'ucase', 'val', 'varptr',
|
||||
// QBJS-specific
|
||||
'export', 'import']
|
||||
//'alert', 'confirm', 'domadd', 'domcontainer', 'domcreate', 'domevent','domget', 'domgetimage', 'domremove', 'export',
|
||||
|
|
259
qb.js
259
qb.js
|
@ -408,10 +408,10 @@ var QB = new function() {
|
|||
a: a,
|
||||
rgba: function() { return "rgba(" + this.r + "," + this.g + "," + this.b + "," + this.a + ")"; },
|
||||
toString: function() {
|
||||
var hexrep = ("00" + r.toString(16)).slice(-2) +
|
||||
var hexrep = ("00" + (255*a).toString(16)).slice(-2) +
|
||||
("00" + r.toString(16)).slice(-2) +
|
||||
("00" + g.toString(16)).slice(-2) +
|
||||
("00" + b.toString(16)).slice(-2) +
|
||||
("00" + a.toString(16)).slice(-2);
|
||||
("00" + b.toString(16)).slice(-2);
|
||||
return parseInt(hexrep, 16).toString();
|
||||
}
|
||||
}
|
||||
|
@ -625,6 +625,253 @@ var QB = new function() {
|
|||
return result;
|
||||
}
|
||||
|
||||
this.sub_Draw = function(t) {
|
||||
|
||||
var u;
|
||||
|
||||
u = t.replace("=","").toUpperCase();
|
||||
u = u.split(" ").join("").split("");
|
||||
|
||||
var d;
|
||||
var elem;
|
||||
var flag;
|
||||
d = u[0];
|
||||
if (!isNaN(String(d) * 1)) {
|
||||
flag = 0; // number
|
||||
} else if ((d >= 'A' && d <= 'Z') || (d >= 'a' && d <= 'z')) {
|
||||
flag = 1; // letter
|
||||
} else {
|
||||
flag = -1; // symbol
|
||||
}
|
||||
elem = d;
|
||||
|
||||
var v = [[]];
|
||||
v.shift();
|
||||
for (var i=1; i<u.length; i++) {
|
||||
d = u[i];
|
||||
if (!isNaN(String(d) * 1)) {
|
||||
if (flag == 0) {
|
||||
elem += d;
|
||||
} else {
|
||||
v.push([elem,flag]);
|
||||
elem = d;
|
||||
flag = 0;
|
||||
}
|
||||
} else if ((d >= 'A' && d <= 'Z') || (d >= 'a' && d <= 'z')) {
|
||||
v.push([elem,flag]);
|
||||
elem = d;
|
||||
flag = 1;
|
||||
} else {
|
||||
if (flag == -1) {
|
||||
elem += d;
|
||||
} else {
|
||||
v.push([elem,flag]);
|
||||
elem = d;
|
||||
flag = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
v.push([elem,flag]);
|
||||
|
||||
var cursS = 4;
|
||||
var cursA = -Math.PI/2;
|
||||
var tok;
|
||||
var tok1;
|
||||
var tok2;
|
||||
var cursReturn = false;
|
||||
var cursSkipdraw = false;
|
||||
var cursX0;
|
||||
var cursY0;
|
||||
var cursXt;
|
||||
var cursYt;
|
||||
var dx;
|
||||
var dy;
|
||||
var dlen;
|
||||
var tmp = [[]];
|
||||
var fac;
|
||||
|
||||
var screen = _images[_activeImage];
|
||||
var ctx = screen.ctx;
|
||||
var cursX = screen.lastX;
|
||||
var cursY = screen.lastY;
|
||||
ctx.strokeStyle = _fgColor.rgba();
|
||||
|
||||
var lines = [["U",0],["E",Math.PI/4],["R",Math.PI/2],["F",Math.PI*(3/4)],["D",Math.PI],["G",Math.PI*(5/4)],["L",Math.PI*(3/2)],["H",Math.PI*(7/4)]];
|
||||
|
||||
while (v.length) {
|
||||
tok = v.shift();
|
||||
|
||||
if (tok[1] == 1) {
|
||||
|
||||
if (tok[0] == "C") {
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok1 = v.shift();
|
||||
ctx.strokeStyle = _color(Math.floor(tok1[0])).rgba();
|
||||
}
|
||||
}
|
||||
|
||||
} else if (tok[0] == "S") {
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok1 = v.shift();
|
||||
cursS = tok1[0];
|
||||
}
|
||||
}
|
||||
|
||||
} else if (tok[0] == "N") {
|
||||
cursX0 = cursX;
|
||||
cursY0 = cursY;
|
||||
cursReturn = true;
|
||||
|
||||
} else if (tok[0] == "B") {
|
||||
cursSkipdraw = true;
|
||||
|
||||
} else if (tok[0] == "A") {
|
||||
tok1 = v.shift();
|
||||
if (tok1[1] == 0) {
|
||||
if (tok1[0] == 1) {
|
||||
cursA = -Math.PI;
|
||||
} else if (tok1[0] == 2) {
|
||||
cursA = -Math.PI*(3/2);
|
||||
} else if (tok1[0] == 3) {
|
||||
cursA = 0;
|
||||
}
|
||||
if (cursA > Math.PI*2) { cursA -= Math.PI*2; }
|
||||
if (cursA < -Math.PI*2) { cursA += Math.PI*2; }
|
||||
}
|
||||
|
||||
} else if (tok[0] == "T") {
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 1) {
|
||||
tok1 = v.shift();
|
||||
if (tok1[0] == "A") {
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok2 = v.shift();
|
||||
cursA = -Math.PI/2 - tok2[0]*Math.PI/180;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (tok[0] == "M") {
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == -1) {
|
||||
tok1 = v.shift();
|
||||
if (tok1[0] == "+") {
|
||||
fac = 1;
|
||||
} else if (tok1[0] == "-") {
|
||||
fac = -1;
|
||||
}
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok2 = v.shift();
|
||||
cursX = cursX + fac * tok2[0];
|
||||
}
|
||||
}
|
||||
} else if (tmp[1] == 0) {
|
||||
tok1 = v.shift();
|
||||
cursX = tok1[0];
|
||||
}
|
||||
}
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if ((tmp[1] == -1) && (tmp[0] == ",")) {
|
||||
tmp = v.shift();
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == -1) {
|
||||
tok1 = v.shift();
|
||||
if (tok1[0] == "+") {
|
||||
fac = 1;
|
||||
} else if (tok1[0] == "-") {
|
||||
fac = -1;
|
||||
}
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok2 = v.shift();
|
||||
cursX = cursY + fac * tok2[0];
|
||||
}
|
||||
}
|
||||
} else if (tmp[1] == 0) {
|
||||
tok1 = v.shift();
|
||||
cursY = tok1[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (tok[0] == "P") {
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok1 = v.shift();
|
||||
tok2 = tok1;
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if ((tmp[1] == -1) && (tmp[0] == ",")) {
|
||||
tmp = v.shift();
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok2 = v.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.sub_Paint(undefined, cursX, cursY, _color(Math.floor(tok1[0])), _color(Math.floor(tok2[0])));
|
||||
}
|
||||
}
|
||||
|
||||
} else { // "UERFDGLH"
|
||||
for (i=0 ; i<lines.length ; i++) {
|
||||
if (tok[0] == lines[i][0]) {
|
||||
if (v.length) {
|
||||
tmp = v[0];
|
||||
if (tmp[1] == 0) {
|
||||
tok1 = v.shift();
|
||||
dlen = tok1[0];
|
||||
} else {
|
||||
dlen = cursS/4;
|
||||
}
|
||||
}
|
||||
dx = dlen * Math.cos(cursA + lines[i][1]);
|
||||
dy = dlen * Math.sin(cursA + lines[i][1]);
|
||||
cursXt = cursX + dx;
|
||||
cursYt = cursY + dy;
|
||||
if (cursSkipdraw == false) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cursX, cursY);
|
||||
ctx.lineTo(cursXt, cursYt);
|
||||
ctx.stroke();
|
||||
} else {
|
||||
cursSkipdraw = false;
|
||||
}
|
||||
cursX = cursXt;
|
||||
cursY = cursYt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cursReturn == true) {
|
||||
cursX = cursX0;
|
||||
cursY = cursY0;
|
||||
cursReturn = false;
|
||||
}
|
||||
}
|
||||
screen.lastX = cursX;
|
||||
screen.lastY = cursY;
|
||||
};
|
||||
|
||||
this.func_Exp = function(value) {
|
||||
return Math.exp(value);
|
||||
};
|
||||
|
@ -1148,6 +1395,8 @@ var QB = new function() {
|
|||
}
|
||||
}
|
||||
_images[0] = { canvas: GX.canvas(), ctx: GX.ctx(), lastX: 0, lastY: 0 };
|
||||
_images[0].lastX = _images[0].canvas.width/2;
|
||||
_images[0].lastY = _images[0].canvas.height/2;
|
||||
|
||||
// initialize the graphics
|
||||
_fgColor = _color(7);
|
||||
|
@ -1251,6 +1500,10 @@ var QB = new function() {
|
|||
return ret;
|
||||
};
|
||||
|
||||
this.func_Varptr = function(value) {
|
||||
return String(value);
|
||||
};
|
||||
|
||||
|
||||
// QBJS-only methods
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
|
2
qb2js.js
2
qb2js.js
|
@ -2561,6 +2561,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION", "Cos", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Cvi", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Cvl", False);
|
||||
await sub_AddQBMethod( "SUB", "Draw", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Exp", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Fix", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Hex$", False);
|
||||
|
@ -2602,6 +2603,7 @@ if (QB.halted()) { return; }
|
|||
await sub_AddQBMethod( "FUNCTION", "UBound", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "UCase$", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Val", False);
|
||||
await sub_AddQBMethod( "FUNCTION", "Varptr", False);
|
||||
await sub_AddQBConst( "LOCAL");
|
||||
await sub_AddQBConst( "SESSION");
|
||||
await sub_AddSystemType( "FETCHRESPONSE", "ok:INTEGER,status:INTEGER,statusText:STRING,text:STRING");
|
||||
|
|
|
@ -2722,6 +2722,7 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "Cos", False
|
||||
AddQBMethod "FUNCTION", "Cvi", False
|
||||
AddQBMethod "FUNCTION", "Cvl", False
|
||||
AddQBMethod "SUB", "Draw", False
|
||||
AddQBMethod "FUNCTION", "Exp", False
|
||||
AddQBMethod "FUNCTION", "Fix", False
|
||||
AddQBMethod "FUNCTION", "Hex$", False
|
||||
|
@ -2763,6 +2764,7 @@ Sub InitQBMethods
|
|||
AddQBMethod "FUNCTION", "UBound", False
|
||||
AddQBMethod "FUNCTION", "UCase$", False
|
||||
AddQBMethod "FUNCTION", "Val", False
|
||||
AddQBMethod "FUNCTION", "Varptr", False
|
||||
|
||||
|
||||
' QBJS-only language features
|
||||
|
|
Loading…
Reference in a new issue