Created
March 8, 2018 20:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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