Skip to content

Instantly share code, notes, and snippets.

@clone1018
Created May 18, 2014 03:17
Show Gist options
  • Save clone1018/e6082c1fc753cc6a8d93 to your computer and use it in GitHub Desktop.
Save clone1018/e6082c1fc753cc6a8d93 to your computer and use it in GitHub Desktop.
var interval = setInterval(function() {
ws.send(rgbToHex(getRandomInt(0,255),getRandomInt(0,255),getRandomInt(0,255)));
}, 1000);
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment