Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
597 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const Blub = require('..') | ||
const blubs = [] | ||
const paired = [] | ||
|
||
Blub.discover(blub => { | ||
const {address} = blub | ||
if (!paired.includes(address)) { | ||
Blub.pair(blub, dispatch => { | ||
blubs.push(dispatch) | ||
paired.push(address) | ||
}) | ||
} | ||
}) | ||
|
||
const colors = [0x33, 0xcc, 0xff] | ||
|
||
setInterval(() => | ||
blubs.forEach(dispatch => dispatch(Blub.setColors(...colors, 0xff))), 250) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const net = require('net') | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
const app = express() | ||
const socket = net.connect('/tmp/blub') | ||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded({extended: true})) | ||
app.post('/colors', function (request, response) { | ||
socket.write(request.body.color) | ||
response.send('thanks!') | ||
}) | ||
app.listen(8018) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!doctype html> | ||
<form action="http://localhost:8018/colors" method="POST"> | ||
<input type="color" name="color"> | ||
<input type="submit" value="please"> | ||
</form> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Array.prototype.mapPairs = function (fn) { | ||
// only works on evenly lengthed lists | ||
const length = this.length | ||
const out = [] | ||
for (let i = 0; i < length; i += 2) { | ||
out.push(fn([this[i], this[i + 1]])) | ||
} | ||
return out | ||
} | ||
const net = require('net') | ||
const socket = net.connect('/tmp/blub') | ||
const tinygradient = require('tinygradient') | ||
|
||
const rainbow = tinygradient([ | ||
'#ff2217', | ||
'#ffaa11', | ||
'#eeee22', | ||
'#33ff66', | ||
'#33ccff', | ||
'#1111ee', | ||
'purple', | ||
'#9933ec', | ||
'#ff22ee', | ||
'#ff2217' | ||
]).rgb(9 * 9 * 2) | ||
|
||
// const rainbow = tinygradient([ | ||
// 'red', | ||
// 'orange', | ||
// 'yellow', | ||
// 'green', | ||
// 'blue', | ||
// 'indigo', | ||
// 'violet' | ||
// ]).rgb(7 * 7 * 2) | ||
|
||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
;(async () => { | ||
while (true) { | ||
for (const color of rainbow) { | ||
console.log(`writing ${color.toHexString()}`) | ||
socket.write(color.toHexString()) | ||
await new Promise(resolve => setTimeout(resolve, 7 * 7 * 2)) | ||
} | ||
} | ||
})() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const net = require('net') | ||
const socket = net.connect('/tmp/blub') | ||
|
||
// const rainbow = [ | ||
// [0xff, 0x22, 0x17], | ||
// [0xff, 0xaa, 0x11], | ||
// [0xee, 0xee, 0x22], | ||
// [0x33, 0xff, 0x99], | ||
// [0x33, 0xcc, 0xff], | ||
// [0x11, 0x11, 0xee], | ||
// [0x99, 0x33, 0xec], | ||
// [0xff, 0x22, 0xee] | ||
// ] | ||
|
||
const rainbow = [ | ||
'ff2217', | ||
'ffaa11', | ||
'eeee22', | ||
'33ff66', | ||
'33ccff', | ||
'1111ee', | ||
'9933ec', | ||
'ff22ee' | ||
] | ||
|
||
;(async () => { | ||
let index = 0 | ||
while (true) { | ||
index = index >= rainbow.length ? 0 : index + 1 | ||
socket.write(`#${rainbow[index]}`) | ||
await new Promise(resolve => setTimeout(resolve, 500)) | ||
} | ||
})() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fs = require('fs') | ||
const net = require('net') | ||
const Blub = require('..') | ||
const blubs = [] | ||
const paired = [] | ||
|
||
Blub.discover(blub => { | ||
const {address} = blub | ||
if (!paired.includes(address)) { | ||
Blub.pair(blub, dispatch => { | ||
blubs.push(dispatch) | ||
paired.push(address) | ||
}) | ||
} | ||
}) | ||
|
||
const path = '/tmp/blub' | ||
|
||
fs.unlink(path, () => { | ||
const server = net.createServer(connection => { | ||
connection.on('data', data => { | ||
const hexmatch = data.toString().match(/^#([\da-z]{2})([\da-z]{2})([\da-z]{2})$/) | ||
const rgbmatch = data.toString().match(/^rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\)$/) | ||
const brightness = 0xff | ||
let red, green, blue | ||
if (hexmatch) { | ||
[red, green, blue] = hexmatch.slice(1).map(n => parseInt(n, 16)) | ||
} | ||
if (rgbmatch) { | ||
[red, green, blue] = rgbmatch.slice(1) | ||
} | ||
blubs.forEach(dispatch => dispatch(Blub.setColors(red, green, blue, brightness))) | ||
}) | ||
}).listen(path, () => { | ||
console.log('server bound on %s', path) | ||
}) | ||
}) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(async () => { | ||
const net = require('net') | ||
const socket = net.connect('/tmp/blub') | ||
const pink = '#f8caff' | ||
const blue = '#72f0ca' | ||
let color = pink | ||
while (true) { | ||
color = color === pink ? blue : pink | ||
socket.write(color) | ||
await new Promise(resolve => setTimeout(resolve, 700)) | ||
} | ||
})() |