Skip to content

Instantly share code, notes, and snippets.

@driverdan
Created March 6, 2015 02:01
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 driverdan/e9dd4f2c0e51b28c30fd to your computer and use it in GitHub Desktop.
Save driverdan/e9dd4f2c0e51b28c30fd to your computer and use it in GitHub Desktop.
AnyBar node example - Set random colors
var dgram = require('dgram');
// Create UDP client
var client = dgram.createSocket('udp4');
// Define all the colors
var colors = [
'black',
'blue',
'cyan',
'green',
'orange',
'purple',
'red',
'white',
'yellow'
];
var setRandomColor = function () {
// Pick a random color
var color = new Buffer(colors[~~(Math.random() * colors.length)]);
// Send the color to AnyBar
client.send(color, 0, color.length, 1738, 'localhost', function(err) {
setTimeout(setRandomColor, 1000);
});
};
setRandomColor();
@driverdan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment