tracer bugfix

This commit is contained in:
nrhck 2018-12-27 12:40:30 +01:00
parent a806fabf5c
commit b252c6b56e
7 changed files with 92 additions and 82 deletions

View file

@ -546,31 +546,35 @@
// Store Reference To The Canvas & Set Context
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var lastpoint = { x: 0, y: 0, color: 0};
var lastpoint = { x: 0, y: 0, color: 0};
ctx.clearRect(0,0,400,400);
ctx.save
// Todo : laser point will have black points to go from a polyline to another. Need to discard those black points.
function draw() {
// Clear Canvas At The Start Of Every Frame
ctx.clearRect(0,0,400,400);
ctx.restore
if (pl2.length > 0)
{
// Begin a new path
// 0.7 reduces max coordinates in a more browser compatible resolution.
ctx.beginPath();
ctx.moveTo(pl2[0]*0.7, pl2[1]*0.7);
//ctx.clearRect(0,0,400,400);
ctx.moveTo(pl2[0]*0.5, pl2[1]*0.5);
lastpoint.color = pl2[2];
// Draw n Lines
for (var i = 0; i < pl2.length/3; i++)
{
// New point has the same color -> add a new line to new point
// New point has the same color -> add a new line to the new point
if (pl2[2+(i*3)] === lastpoint.color)
{
ctx.lineTo(pl2[i*3]*0.7, pl2[1+(i*3)]*0.7);
ctx.lineTo(pl2[i*3]*0.5, pl2[1+(i*3)]*0.5);
}
// New point has different color -> stroke with previous color
@ -578,16 +582,24 @@
{
ctx.strokeStyle = "#"+(lastpoint.color + Math.pow(16, 6)).toString(16).slice(-6);
ctx.stroke();
//ctx.closePath()
ctx.restore
ctx.beginPath();
ctx.moveTo(pl2[i*3]*0.7, pl2[1+(i*3)]*0.7);
//ctx.clearRect(0,0,400,400);
ctx.moveTo(pl2[i*3]*0.5, pl2[1+(i*3)]*0.5);
}
// Last point -> stroke with current color
if (i === (pl2.length/3)-1 )
{
ctx.moveTo(pl2[i*3]*0.7, pl2[1+(i*3)]*0.7);
ctx.moveTo(pl2[i*3]*0.5, pl2[1+(i*3)]*0.5);
ctx.strokeStyle = "#"+((pl2[2+(i*3)]) + Math.pow(16, 6)).toString(16).slice(-6);
ctx.stroke();
//ctx.closePath()
ctx.restore
//ctx.clearRect(0,0,400,400);
}
// store point for comparison

View file

@ -22,7 +22,9 @@
var lastpoint = { x: 0, y: 0, color: 0};
// 2 different shapes, one blue one green.
var LJ = "/plframe [(350, 330, 65280), (370, 270, 65280), (430, 270, 65280), (410, 330, 65280), (350, 330, 65280),(300, 300, 255), (350, 250, 255), (400, 250, 255), (400, 300, 255), (300, 300, 255)]";
// var LJ = "/plframe [(350, 330, 65280), (370, 270, 65280), (430, 270, 65280), (410, 330, 65280), (350, 330, 65280),(300, 300, 255), (350, 250, 255), (400, 250, 255), (400, 300, 255), (300, 300, 255)]";
var LJ = "/plframe [(186.66666666666669, 86.66666666666669, 0), (613.3333333333333, 86.66666666666669, 16777215), (613.3333333333333, 513.3333333333333, 16777215), (186.66666666666669, 513.3333333333333, 16777215), (613.3333333333333, 86.66666666666669, 16777215), (480.0, 220.0, 16777215), (480.0, 380.0, 16777215), (613.3333333333333, 513.3333333333333, 16777215), (480.0, 220.0, 16777215), (320.0, 220.0, 16777215), (320.0, 380.0, 16777215), (480.0, 380.0, 16777215), (320.0, 220.0, 16777215), (186.66666666666669, 86.66666666666669, 16777215), (186.66666666666669, 513.3333333333333, 16777215), (320.0, 380.0, 16777215), (186.66666666666669, 86.66666666666669, 16777215), (320.0, 220.0, 16777215), (480.0, 220.0, 16777215), (613.3333333333333, 86.66666666666669, 16777215), (186.66666666666669, 513.3333333333333, 16777215), (613.3333333333333, 513.3333333333333, 16777215), (480.0, 380.0, 16777215), (320.0, 380.0, 16777215), (-73.4959349593496, 86.66666666666669, 0), (353.1707317073171, 86.66666666666669, 16711680), (353.1707317073171, 513.3333333333333, 16711680), (-73.4959349593496, 513.3333333333333, 16711680), (353.1707317073171, 86.66666666666669, 16711680), (582.5641025641025, 220.0, 16711680), (582.5641025641025, 380.0, 16711680), (353.1707317073171, 513.3333333333333, 16711680), (582.5641025641025, 220.0, 16711680), (422.5641025641026, 220.0, 16711680), (422.5641025641026, 380.0, 16711680), (582.5641025641025, 380.0, 16711680), (422.5641025641026, 220.0, 16711680), (-73.4959349593496, 86.66666666666669, 16711680), (-73.4959349593496, 513.3333333333333, 16711680), (422.5641025641026, 380.0, 16711680), (-73.4959349593496, 86.66666666666669, 16711680), (422.5641025641026, 220.0, 16711680), (582.5641025641025, 220.0, 16711680), (353.1707317073171, 86.66666666666669, 16711680), (-73.4959349593496, 513.3333333333333, 16711680), (353.1707317073171, 513.3333333333333, 16711680), (582.5641025641025, 380.0, 16711680), (422.5641025641026, 380.0, 16711680), (446.8292682926829, 86.66666666666669, 0), (873.4959349593496, 86.66666666666669, 255), (873.4959349593496, 513.3333333333333, 255), (446.8292682926829, 513.3333333333333, 255), (873.4959349593496, 86.66666666666669, 255), (377.4358974358974, 220.0, 255), (377.4358974358974, 380.0, 255), (873.4959349593496, 513.3333333333333, 255), (377.4358974358974, 220.0, 255), (217.43589743589746, 220.0, 255), (217.43589743589746, 380.0, 255), (377.4358974358974, 380.0, 255), (217.43589743589746, 220.0, 255), (446.8292682926829, 86.66666666666669, 255), (446.8292682926829, 513.3333333333333, 255), (217.43589743589746, 380.0, 255), (446.8292682926829, 86.66666666666669, 255), (217.43589743589746, 220.0, 255), (377.4358974358974, 220.0, 255), (873.4959349593496, 86.66666666666669, 255), (446.8292682926829, 513.3333333333333, 255), (873.4959349593496, 513.3333333333333, 255), (377.4358974358974, 380.0, 255), (217.43589743589746, 380.0, 255)]";
var pl ="";
var pl2 = new Array();