Skip to content

Commit e985350

Browse files
committed
remove logging and floor values instead of 2hexing them
1 parent 4f9c799 commit e985350

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

elements/pfe-avatar/src/hslrgb.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,14 @@ export function hsl2rgb(_H, _S, _L) {
3939

4040
a = 2 * L - b;
4141

42-
R = 255 * h2rgb(a, b, H + 1 / 3);
43-
G = 255 * h2rgb(a, b, H);
44-
B = 255 * h2rgb(a, b, H - 1 / 3);
42+
R = Math.floor(255 * h2rgb(a, b, H + 1 / 3));
43+
G = Math.floor(255 * h2rgb(a, b, H));
44+
B = Math.floor(255 * h2rgb(a, b, H - 1 / 3));
4545
}
4646

4747
return [R, G, B];
4848
}
4949

50-
/**
51-
* Converts a decimal number into a hexadecimal number, left-padded to a given length.
52-
*/
53-
function toHex(d, len) {
54-
return ("0" + Math.round(d).toString(16)).slice(-len);
55-
}
56-
57-
/**
58-
* Converts an HSL color to a hexadecimal color.
59-
*/
60-
export function hsl2hex(_H, _S, _L) {
61-
return rgb2hex(hsl2rgb(_H, _S, _L));
62-
}
63-
64-
/**
65-
* Converts an RGB color to a hexadecimal color.
66-
*/
67-
export function rgb2hex(_R, _G, _B) {
68-
console.log(`converting ${_R}, ${_G}, ${_B} to hex`);
69-
const ret = "#" + [_R, _G, _B].map(c => toHex(c, 2)).join("");
70-
console.log(`done ${ret}`);
71-
return ret;
72-
}
73-
7450
/**
7551
* Convert an RGBcolor to HSL.
7652
*

elements/pfe-avatar/src/pfe-avatar.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PFElement from "../pfelement/pfelement.js";
22
import { hash } from "./djb-hash.js";
3-
import { hsl2rgb, rgb2hsl, rgb2hex } from "./hslrgb.js";
3+
import { hsl2rgb, rgb2hsl } from "./hslrgb.js";
44

55
class PfeAvatar extends PFElement {
66
static get tag() {
@@ -129,9 +129,7 @@ class PfeAvatar extends PFElement {
129129
);
130130
if (pattern) {
131131
pattern.shift();
132-
console.log("pattern", pattern);
133132
const color = pattern.map(c => parseInt(c, 16));
134-
console.log("color", color);
135133
this._registerColor(color);
136134
} else {
137135
this.log(`[pfe-avatar] invalid color ${colorCode}`);
@@ -144,16 +142,15 @@ class PfeAvatar extends PFElement {
144142

145143
static _registerColor(color) {
146144
PfeAvatar.colors.push({
147-
color1: rgb2hex(...color),
148-
color2: rgb2hex(...this._adjustColor(color))
145+
color1: `rgb(${color.join(",")})`,
146+
color2: `rgb(${this._adjustColor(color).join(",")})`
149147
});
150148
}
151149

152150
static _adjustColor(color) {
153151
const dark = 0.1;
154152
const l_adj = 0.1; // luminance adjustment
155153
const hsl = rgb2hsl(...color);
156-
console.log(`${color} -> ${hsl}`);
157154

158155
// if luminance is too dark already, then lighten the alternate color
159156
// instead of darkening it.

0 commit comments

Comments
 (0)