cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              html, body {
  background: #27272C;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%
}

.pip {
  width: 17px;
  height: 17px;
  margin: 7px;
  background-color: #525252;
  border-radius: 100%;
  transition: all .3s ease-in;
}

.pip--on {
  background-color: #48d8b8;
  transform: scale(1.1);
}

.clock {
  display: flex
}

.binary-digit-group {
  display: flex;
  margin: 0 6px;
}
            
          
!
            
              const Pip = ({isOn}) =>
  <div className={`pip ${isOn && 'pip--on'}`}></div>

const BinaryDigit = ({base2NumberAsArray}) =>
  <div className="binary-digit">
    {
      base2NumberAsArray.map((pip, idx )=> <Pip key={idx} isOn={pip === 1} />)
    }
 </div>

const BinaryDigitGroup = ({group}) =>
  <div className="binary-digit-group">
    {
      group.map((binaryDigit, idx) => <BinaryDigit base2NumberAsArray={binaryDigit} key={idx} /> )
    }
  </div>

class Clock extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      digits: [[], [], []]
    }
  }
  
  componentDidMount() {
    setInterval(function() {
      const date = new Date();
      const newDigits = [
        numberAsBinaryArrayPair(date.getHours()), 
        numberAsBinaryArrayPair(date.getMinutes()),
        numberAsBinaryArrayPair(date.getSeconds())
      ];
      this.setState({
        digits: newDigits
      });
    }.bind(this), 1000);
  }
  
  render() {
    return (
      <div className="app">
        <div className="clock">
         {
           this.state.digits.map(digit => <BinaryDigitGroup group={digit} />)
         }
        </div>
      </div>
    );
  }
}


ReactDOM.render(
  <Clock />,
  document.getElementById('react')
);


function numberToBinary(base10Number) {
  const base2Values = [8, 4, 2, 1];
  let output = [0, 0, 0, 0];
  let remainder = base10Number;
  
  base2Values.forEach((val, idx) => {
    const left = remainder - val;

    if(left >= 0) {
      output[idx] = 1;
      remainder = left
    } 
  });
  
  return output;
}

function numberAsBinaryArrayPair(number) {
  const pair = [];
  if(number < 10) {
    pair[0] = numberToBinary();
    pair[1] = numberToBinary(number);
  } else {
    const numberAsArray = String(number).split('');
    pair[0] = numberToBinary(parseInt(numberAsArray[0], 10));
    pair[1] = numberToBinary(parseInt(numberAsArray[1], 10));
  }
  
  return pair;
}
            
          
!
999px
Loading ..................

Console