redo colors again

This commit is contained in:
Stewart Allen 2020-11-11 08:07:02 -05:00
commit 071955ea7c
5 changed files with 54 additions and 33 deletions

View file

@ -221,6 +221,10 @@
return ret;
};
PRO.miter = function() {
// todo - to eliminate path sharps in renders
};
PRO.createConvexHull = function(points) {
function removeMiddle(a, b, c) {
let cross = (a.x - b.x) * (c.y - b.y) - (a.y - b.y) * (c.x - b.x);

View file

@ -166,7 +166,7 @@ KIRI.work = {
update(reply.progress, reply.message);
}
if (reply.done) {
done(reply.output, reply.speedColors);
done(reply.output, reply.maxSpeed);
}
});
},
@ -182,6 +182,12 @@ KIRI.work = {
});
},
colors : function(colors, max, done) {
send("colors", { colors, max }, function(reply) {
done(reply);
});
},
parse : function(args, progress, done) {
// have to do this client side because DOMParser is not in workers
if (args.type === 'svg') {

View file

@ -664,24 +664,30 @@
// UI.setMenu.style.display = andmenu ? 'none' : 'flex';
}
function updateSpeeds(speedColors) {
function updateSpeeds(maxSpeed) {
UI.speeds.style.display =
settings.mode !== 'SLA' &&
settings.mode !== 'LASER' &&
viewMode === VIEWS.PREVIEW &&
UI.showSpeeds.checked ? 'block' : '';
if (speedColors) {
const list = [];
Object.keys(speedColors).map(v => parseInt(v)).sort((a,b) => b-a).forEach(speed => {
const color = speedColors[speed];
const hex = color.toString(16).padStart(6,0);
const r = (color >> 16) & 0xff;
const g = (color >> 8) & 0xff;
const b = (color >> 0) & 0xff;
const style = `background-color:#${hex}`;
list.push(`<label style="${style}">${speed}</label>`);
if (maxSpeed) {
const colors = [];
for (let i=0; i<= maxSpeed; i += maxSpeed/20) {
colors.push(Math.round(Math.max(i,1)));
}
KIRI.client.colors(colors, maxSpeed, speedColors => {
const list = [];
Object.keys(speedColors).map(v => parseInt(v)).sort((a,b) => b-a).forEach(speed => {
const color = speedColors[speed];
const hex = color.toString(16).padStart(6,0);
const r = (color >> 16) & 0xff;
const g = (color >> 8) & 0xff;
const b = (color >> 0) & 0xff;
const style = `background-color:#${hex}`;
list.push(`<label style="${style}">${speed}</label>`);
});
UI.speedbar.innerHTML = list.join('');
});
UI.speedbar.innerHTML = list.join('');
}
}
@ -824,7 +830,7 @@
KIRI.client.prepare(settings, function(progress, message) {
API.show.progress(progress, message);
}, function (output, speedColors) {
}, function (output, maxSpeed) {
API.show.progress(0);
if (!isCam) setOpacity(0);
@ -844,7 +850,7 @@
SPACE.update();
updateSliderMax(true);
setVisibleLayer(-1, 0);
updateSpeeds(speedColors);
updateSpeeds(maxSpeed);
}
if (typeof(callback) === 'function') {

View file

@ -128,20 +128,11 @@ KIRI.worker = {
const print = current.print || {};
const maxSpeed = print.maxSpeed || undefined;
const thinColor = print.thinColor || false;
let speedColors = {};
if (maxSpeed) {
const FDM = KIRI.driver.FDM;
for (let i=0, sd=maxSpeed/19, so=0; i<20; i++) {
speedColors[Math.round(so)] = FDM.rateToColor(so, maxSpeed + 1, thinColor);
so += sd;
}
}
send.done({
done: true,
output: KIRI.codec.encode(layers),
speedColors
maxSpeed
});
},
@ -169,6 +160,15 @@ KIRI.worker = {
});
},
colors: function(data, send) {
const { colors, max } = data;
const colorMap = {};
colors.forEach(color => {
colorMap[color] = KIRI.driver.FDM.rateToColor(color, max);
});
send.done(colorMap);
},
parse: function(args, send) {
const { settings, code, type } = args;
const origin = settings.origin;

View file

@ -397,8 +397,8 @@
}
}
FDM.rateToColor = function(rate, max, ext) {
return hsv2rgb({h: rate/max, s:1, v:ext ? 0.7 : 0.8}, ext);
FDM.rateToColor = function(rate, max) {
return hsv2rgb({h: rate/max, s:1, v:0.85});
};
FDM.prepareRender = function(levels, update, options) {
@ -427,7 +427,7 @@
let current = null;
function color(point) {
return FDM.rateToColor(point.speed, maxspd, thin);
return FDM.rateToColor(point.speed, maxspd);
}
levels.forEach((level, index) => {
@ -508,9 +508,9 @@
}
// hsv values all = 0 to 1
function hsv2rgb(hsv, ext) {
function hsv2rgb(hsv) {
const { h, s, v } = hsv;
const ss = 1 / (ext ? 4 : 3);
const ss = 1 / 5;
const seg = Math.floor(h / ss);
const rem = h - (seg * ss);
const inc = (rem / ss);
@ -525,14 +525,19 @@
case 1:
rgb.r = dec;
rgb.g = 1;
rgb.b = inc;
rgb.b = 0;
break;
case 2:
rgb.r = inc;
rgb.r = 0;
rgb.g = dec;
rgb.b = 1;
rgb.b = inc;
break;
case 3:
rgb.r = inc;
rgb.g = 0;
rgb.b = 1;
break;
case 4:
rgb.r = dec;
rgb.g = 0;
rgb.b = dec;