Skip to content

Instantly share code, notes, and snippets.

@JRJurman
Last active October 6, 2018 15:44
Show Gist options
  • Select an option

  • Save JRJurman/72dfa5ec07a61c83ee979d98a17bca02 to your computer and use it in GitHub Desktop.

Select an option

Save JRJurman/72dfa5ec07a61c83ee979d98a17bca02 to your computer and use it in GitHub Desktop.
Digit for Binary Clock Medium Article
const Tram = require('tram-one')
const html = Tram.html({
'led': require('./led')
})
module.exports = (attrs) => {
const binaryValue = parseInt(attrs.value).toString(2)
const fullBinaryString = '0000'.slice(0, 4 - binaryValue.length).concat(binaryValue)
const isOn = fullBinaryString.split('').map(value => value === '1')
return html`
<div>
<led size=${attrs.size} ${isOn[0] ? 'on' : ''} />
<led size=${attrs.size} ${isOn[1] ? 'on' : ''} />
<led size=${attrs.size} ${isOn[2] ? 'on' : ''} />
<led size=${attrs.size} ${isOn[3] ? 'on' : ''} />
</div>
`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment