Commit 2134e4ab by Alexander Bazo

Fix bug in color generator

parent de596a27
...@@ -50,7 +50,7 @@ class ImageViewerRoom extends colyseus.Room { ...@@ -50,7 +50,7 @@ class ImageViewerRoom extends colyseus.Room {
if (message.type === "gaze") { if (message.type === "gaze") {
if (client.color === undefined) { if (client.color === undefined) {
client.color = Colors.createRandomColor(); client.color = Colors.createRandomColor();
Logger.log(`Assign clien color: ${client.color}`, "ImageViewer Room"); Logger.log(`Assign client color: ${client.color}`, "ImageViewer Room");
} }
message.data.color = client.color; message.data.color = client.color;
let point = GazePoint.fromClientData(message.data); let point = GazePoint.fromClientData(message.data);
......
...@@ -7,8 +7,11 @@ function createRandomColorChannel() { ...@@ -7,8 +7,11 @@ function createRandomColorChannel() {
} }
function componentToHex(c) { function componentToHex(c) {
var hex = c.toString(16); var hex = Number(c).toString(16);
return hex.length == 1 ? "0" + hex : hex; if (hex.length < 2) {
hex = "0" + hex;
}
return hex;
} }
function rgbToHex(r, g, b) { function rgbToHex(r, g, b) {
...@@ -21,7 +24,7 @@ class Colors { ...@@ -21,7 +24,7 @@ class Colors {
let r = createRandomColorChannel(), let r = createRandomColorChannel(),
g = createRandomColorChannel(), g = createRandomColorChannel(),
b = createRandomColorChannel(); b = createRandomColorChannel();
return rgbToHex(r,g,b); return rgbToHex(r, g, b);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment