Created
March 6, 2015 02:01
-
-
Save driverdan/e9dd4f2c0e51b28c30fd to your computer and use it in GitHub Desktop.
AnyBar node example - Set random colors
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 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AnyBar: https://github.com/tonsky/AnyBar