You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.1 KiB
60 lines
1.1 KiB
5 years ago
|
const clamp = (p, s, e) => {
|
||
|
s = s || 0;
|
||
|
e = e || p;
|
||
|
return p < s ? s : (p > e ? e : p);
|
||
|
};
|
||
|
|
||
|
const spectrum = (p) => {
|
||
|
return {
|
||
|
r: clamp(1.0 - (p*2), 0, 1),
|
||
|
g: p < 0.5 ? p / 0.5 : (p-0.5),
|
||
|
b: clamp(p, 0.5, 1),
|
||
|
|
||
|
toBytes: function() {
|
||
|
var bytes = {
|
||
|
r: floor(this.r * 255),
|
||
|
g: floor(this.g * 255),
|
||
|
b: floor(this.b * 255),
|
||
|
|
||
|
toString: function() {
|
||
|
return "#"+bytes.r.toString(16)+bytes.g.toString(16)+bytes.b.toString(16);
|
||
|
}
|
||
|
};
|
||
|
return bytes;
|
||
|
}
|
||
|
};
|
||
|
};
|
||
|
|
||
|
const genrgb = (r,g,b) =>{ return {r: r, g: g, b: b}; };
|
||
|
|
||
|
function ColouredBar(par, bars) {
|
||
|
const elem = document.createElement("div");
|
||
|
|
||
|
var str = "";
|
||
|
var pct = 0;
|
||
|
|
||
|
for(let i=0;i<bars.length;i++) {
|
||
|
const bar = bars[i];
|
||
|
pct += bar.frag;
|
||
|
str +=","+ bar.colour+" "+(pct*100)+"%"+ ((i<bars.length-1)? ", "+(pct*100)+"%":"");
|
||
|
}
|
||
|
|
||
|
elem.setAttribute("class", "filebar");
|
||
|
|
||
|
if(bars.length<1)
|
||
|
elem.style.background = "grey";
|
||
|
else
|
||
|
elem.style.background = 'linear-gradient(90deg '+str+')';
|
||
|
|
||
|
this.frags = bars;
|
||
|
this.element = elem;
|
||
|
this.parent = par;
|
||
|
par.appendChild(elem);
|
||
|
}
|
||
|
|
||
|
var BAR = ColouredBar.prototype;
|
||
|
|
||
|
BAR.remove = function() {
|
||
|
this.element.remove();
|
||
|
};
|