Skip to content

Instantly share code, notes, and snippets.

@jimkang
Created March 8, 2018 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimkang/249498ada6e07c1acfb8452ed6db49b5 to your computer and use it in GitHub Desktop.
Save jimkang/249498ada6e07c1acfb8452ed6db49b5 to your computer and use it in GitHub Desktop.
In case I ever need it: Color tracker for secret click-detection mirror canvases
var hash = require('string-hash');
function TrackingColors() {
var idsForColors = {};
return {
getTrackingColorForId,
getIdForTrackingColor
};
function getTrackingColorForId(id) {
var colorString = '#' + hash(id).toString(16);
idsForColors[colorString] = id;
return colorString;
}
function getIdForTrackingColor(colorString) {
return idsForColors[colorString];
}
}
module.exports = TrackingColors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment