mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-20 04:24:45 +00:00
Prototyped styled lines.
This commit is contained in:
parent
fdfbf2816f
commit
9334724b2d
3 changed files with 102 additions and 16 deletions
86
qb.js
86
qb.js
|
@ -1204,7 +1204,7 @@ var QB = new function() {
|
|||
|
||||
this.sub_Line = function(sstep, sx, sy, estep, ex, ey, color, style, pattern) {
|
||||
var screen = _images[_activeImage];
|
||||
var ctx = screen.ctx;
|
||||
//var ctx = screen.ctx;
|
||||
_images[_activeImage].dirty = true;
|
||||
|
||||
if (color == undefined) {
|
||||
|
@ -1254,16 +1254,25 @@ var QB = new function() {
|
|||
screen.lastX = ex;
|
||||
screen.lastY = ey;
|
||||
|
||||
if (pattern != undefined) {
|
||||
if (typeof pattern == "number") {
|
||||
var value = pattern;
|
||||
//ptn = ("0000000000000000" + (value >>> 0).toString(2)).slice(-16);
|
||||
}
|
||||
}
|
||||
|
||||
if (pattern == undefined) {
|
||||
var ctx = screen.ctx;
|
||||
ctx.lineWidth = _strokeLineThickness;
|
||||
if (style == "B") {
|
||||
ctx.strokeStyle = color.rgba();
|
||||
ctx.beginPath();
|
||||
ctx.strokeRect(sx, sy, ex-sx, ey-sy)
|
||||
ctx.strokeRect(sx, sy, ex-sx, ey-sy);
|
||||
}
|
||||
else if (style == "BF") {
|
||||
ctx.fillStyle = color.rgba();
|
||||
ctx.beginPath();
|
||||
ctx.fillRect(sx, sy, ex-sx, ey-sy)
|
||||
ctx.fillRect(sx, sy, ex-sx, ey-sy);
|
||||
}
|
||||
else {
|
||||
ctx.strokeStyle = color.rgba();
|
||||
|
@ -1272,9 +1281,80 @@ var QB = new function() {
|
|||
ctx.lineTo(ex, ey);
|
||||
ctx.stroke();
|
||||
}
|
||||
} else {
|
||||
var ctx = screen.ctx;
|
||||
ctx.lineWidth = _strokeLineThickness;
|
||||
ctx.fillStyle = color.rgba();
|
||||
ctx.beginPath();
|
||||
var zeroDummy;
|
||||
if (style == "B") {
|
||||
zeroDummy = lineStyle(sx, sy, ex, sy, value);
|
||||
zeroDummy = lineStyle(ex, sy, ex, ey, value);
|
||||
zeroDummy = lineStyle(ex, ey, sx, ey, value);
|
||||
zeroDummy = lineStyle(sx, ey, sx, sy, value);
|
||||
} else {
|
||||
zeroDummy = lineStyle(sx, sy, ex, ey, value);
|
||||
}
|
||||
}
|
||||
|
||||
_strokeDrawColor = _color(color);
|
||||
};
|
||||
|
||||
function lineStyle(x1, y1, x2, y2, sty) {
|
||||
var screen = _images[_activeImage];
|
||||
var ctx = screen.ctx;
|
||||
var lx = Math.abs(x2 - x1);
|
||||
var ly = Math.abs(y2 - y1);
|
||||
var slope;
|
||||
var mi;
|
||||
var xtmp = x1;
|
||||
var ytmp = y1;
|
||||
var ptn = sty;
|
||||
if (lx > ly) {
|
||||
var y1f = y1;
|
||||
if (lx) { slope = (y1 - y2) / lx; }
|
||||
if (x1 < x2) { mi = 1; } else { mi = -1; }
|
||||
lx += 1;
|
||||
while (lx -= 1) {
|
||||
if (y1f < 0) {ytmp = y1f - 0.5; } else { ytmp = y1f + 0.5; }
|
||||
ptn = bitTread(ptn, 1);
|
||||
if (bitTest(ptn, 0) == true) { ctx.fillRect(xtmp, ytmp, 1, 1); }
|
||||
xtmp += mi;
|
||||
y1f -= slope;
|
||||
}
|
||||
} else {
|
||||
var x1f = x1;
|
||||
if (ly) { slope = (x1 - x2) / ly; }
|
||||
if (y1 < y2) { mi = 1; } else { mi = -1; }
|
||||
ly += 1;
|
||||
while (ly -= 1) {
|
||||
if (x1f < 0) {xtmp = x1f - 0.5; } else { xtmp = x1f + 0.5; }
|
||||
ptn = bitTread(ptn, 1);
|
||||
if (bitTest(ptn, 0) == true) { ctx.fillRect(xtmp, ytmp, 1, 1); }
|
||||
ytmp += mi;
|
||||
x1f += slope;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function bitTread(num, cnt) { // Bitwise treadmill left.
|
||||
var val = (num << cnt) | (num >>> (32 - cnt));
|
||||
if (~~bitTest(num, 15) == 1) {
|
||||
return bitSet(val, 0);
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
function bitTest(num, bit) { // true or false
|
||||
return ((num>>bit) % 2 != 0)
|
||||
}
|
||||
|
||||
function bitSet(num, bit) {
|
||||
return num | 1<<bit;
|
||||
}
|
||||
|
||||
this.sub_LineInput = async function(values, preventNewline, addQuestionPrompt, prompt) {
|
||||
await QB.sub_Input(values, preventNewline, addQuestionPrompt, prompt);
|
||||
}
|
||||
|
|
3
qb2js.js
3
qb2js.js
|
@ -618,6 +618,8 @@ var ConvertLine = null;
|
|||
theRest = (await func_Replace( theRest, " Bf", " " +(QB.func_Chr( 34)) +"BF" +(QB.func_Chr( 34))));
|
||||
theRest = (await func_Replace( theRest, " B", " " +(QB.func_Chr( 34)) +"B" +(QB.func_Chr( 34))));
|
||||
theRest = (await func_Replace( theRest, " b", " " +(QB.func_Chr( 34)) +"B" +(QB.func_Chr( 34))));
|
||||
theRest = (await func_Replace( theRest, " T", " " +(QB.func_Chr( 34)) +"T" +(QB.func_Chr( 34))));
|
||||
theRest = (await func_Replace( theRest, " t", " " +(QB.func_Chr( 34)) +"T" +(QB.func_Chr( 34))));
|
||||
ConvertLine = sstep +", " + startCord +", " + estep +", " + endCord +", " + theRest;
|
||||
return ConvertLine;
|
||||
}
|
||||
|
@ -775,6 +777,7 @@ var ConvertRandomize = null;
|
|||
if (((QB.func_UCase( (QB.func__Trim( (QB.func_Left( args, 5)))))) == "USING") ) {
|
||||
uusing = "true";
|
||||
theseed = (QB.func__Trim( (QB.func_Right( args, (QB.func_Len( args)) - 5))));
|
||||
theseed = (await func_ConvertExpression( theseed));
|
||||
}
|
||||
}
|
||||
ConvertRandomize = (await func_CallMethod( m)) +"(" + uusing +", " + theseed +")";
|
||||
|
|
|
@ -716,6 +716,8 @@ Function ConvertLine$ (args As String)
|
|||
theRest = Replace(theRest, " Bf", " " + Chr$(34) + "BF" + Chr$(34))
|
||||
theRest = Replace(theRest, " B", " " + Chr$(34) + "B" + Chr$(34))
|
||||
theRest = Replace(theRest, " b", " " + Chr$(34) + "B" + Chr$(34))
|
||||
theRest = Replace(theRest, " T", " " + Chr$(34) + "T" + Chr$(34))
|
||||
theRest = Replace(theRest, " t", " " + Chr$(34) + "T" + Chr$(34))
|
||||
|
||||
ConvertLine = sstep + ", " + startCord + ", " + estep + ", " + endCord + ", " + theRest
|
||||
End Function
|
||||
|
@ -850,6 +852,7 @@ Function ConvertRandomize$ (m As Method, args As String)
|
|||
If (UCase$(_Trim$(Left$(args, 5))) = "USING") Then
|
||||
uusing = "true"
|
||||
theseed = _Trim$(Right$(args, Len(args) - 5))
|
||||
theseed = ConvertExpression(theseed)
|
||||
End If
|
||||
End If
|
||||
ConvertRandomize = CallMethod(m) + "(" + uusing + ", " + theseed + ")"
|
||||
|
|
Loading…
Reference in a new issue