Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class='wrapper'>
  <div class='content'>
    <div class='human'>
      <div class='face'>
        <svg viewBox='0 0 40 42' x='0' y='0'>
          <g>
            <rect class='f' height='38' rx='20' ry='20' width='38' x='1' y='2'></rect>
            <rect class='eye' height='9' rx='4.5' ry='4.5' width='9' x='9' y='11'></rect>
            <rect class='eye' height='9' rx='4.5' ry='4.5' width='9' x='22' y='11'></rect>
            <rect class='mouth' height='3' width='10' x='15' y='26'></rect>
            <path class='smile' d='M 11 24 L 29 24 C 29 24 28.8333 32 20 32 C 12 32 11 24 11 24 Z'></path>
          </g>
        </svg>
      </div>
      <div class='io' contenteditable='true'></div>
    </div>
    <div class='machine'>
      <div class='face'>
        <svg viewBox='0 0 54 57' x='0px' y='0px'>
          <g>
            <rect class='f' height='40' width='40' x='7' y='16'></rect>
            <rect class='e' height='13' width='6' x='47' y='27'></rect>
            <rect class='e' height='13' width='6' x='1' y='27'></rect>
            <rect class='eye' height='10' rx='6' ry='6' width='10' x='14' y='27'></rect>
            <rect class='eye' height='10' rx='6' ry='6' width='10' x='30' y='27'></rect>
            <rect class='s' height='8' width='3' x='26' y='9'></rect>
            <rect class='signal' height='7' rx='4' ry='4' width='7' x='24' y='1'></rect>
          </g>
        </svg>
      </div>
      <div class='io' contenteditable='true'></div>
    </div>
  </div>
  <footer>Simple (ASCII) Text to Binary Converter</footer>
</div>

              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Droid+Sans+Mono);
html, body {
  overflow: hidden;
}

body {
  background-color: #fafafa;
  font-family: 'Droid Sans Mono', sans-serif;
}

.wrapper {
  width: 750px;
  height: 560px;
  margin: -280px 0 0 -375px;
  position: absolute;
  top: 50%;
  left: 50%;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1);
}

.content::after {
  content: ".";
  display: block;
  clear: both;
  visibility: hidden;
  line-height: 0;
  height: 0;
}

.face {
  width: 60px;
  height: 60px;
  margin: 35px auto 15px;
}

.human, .machine {
  float: left;
  width: 50%;
  line-height: 1.5;
}
.human .io, .machine .io {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  padding: 20px 10px 30px 20px;
  height: 450px;
  display: block;
  outline: none;
  overflow-y: scroll;
  margin: 0 10px;
  -webkit-mask: -webkit-linear-gradient(top, transparent 0px, black 30px, black 50%, transparent 100%), -webkit-linear-gradient(bottom, transparent 0px, black 30px, black 50%, transparent 100%);
}
.human .io::-webkit-scrollbar, .machine .io::-webkit-scrollbar {
  width: 5px;
}
.human .io::-webkit-scrollbar-thumb, .machine .io::-webkit-scrollbar-thumb {
  border-radius: 3px;
}
.human:after, .machine:after {
  content: ".";
  display: block;
  clear: both;
  visibility: hidden;
  line-height: 0;
  height: 0;
}

.human {
  background-color: #fff;
  color: #16161D;
  font-size: 16px;
  border-radius: 3px 0 0 3px;
}
.human .face svg {
  width: 44px;
  height: 40px;
  position: relative;
  left: 8px;
  top: 8px;
}
.human .face svg .f {
  stroke: #ccc;
  stroke-width: 3px;
  fill: none;
}
.human .face svg .eye, .human .face svg .mouth, .human .face svg .smile {
  fill: #ccc;
}
.human .face.active .smile {
  display: none;
}
.human .face.active .f {
  stroke: #666;
}
.human .face.active .eye, .human .face.active .mouth {
  fill: #666;
}
.human .io::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.1);
}

.machine {
  background-color: #1a1a1a;
  color: #00FF99;
  border-radius: 0 3px 3px 0;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.7), 0 0 10px rgba(0, 255, 153, 0.5);
}
.machine .face svg {
  width: 54px;
  height: 57px;
  position: relative;
  left: 2px;
  top: 1px;
}
.machine .face svg .f, .machine .face svg .e, .machine .face svg .eye {
  stroke: #666;
  stroke-width: 3px;
}
.machine .face svg .s {
  fill: #666;
}
.machine .face svg .signal {
  fill: rgba(0, 255, 153, 0.2);
}
.machine .face.active .signal {
  fill: #00ff99;
}
.machine .face.active .f, .machine .face.active .e, .machine .face.active .eye {
  stroke: #999;
}
.machine .face.active .s {
  fill: #999;
}
.machine .io {
  font-size: 11px;
}
.machine .io::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.15);
}

footer {
  font-size: 11px;
  color: #ccc;
  text-shadow: 0 1px 0 white;
  margin-top: 15px;
}

              
            
!

JS

              
                var UI = {
  human: {
    io: document.querySelector(".human .io"),
    figure: document.querySelector(".human .face")
  },
  machine: {
    io: document.querySelector(".machine .io"),
    figure: document.querySelector(".machine .face")
  }
};

var App = {
  init: function () {
    this.bindEvents();
    UI.human.io.textContent = "Start typing here!";
    // UI.human.io.textContent = "Man lives in the sunlit world of what he believes to be reality. But, there is, unseen by most, an underworld, a place that is just as real, but not as brightly lit... a darkside. The darkside is always there, waiting for us to enter, waiting to enter us. So until next time, try to enjoy the daylight.";
    UI.machine.io.innerHTML = this.toBinary(UI.human.io.textContent);
  },

  bindEvents: function () {
    var _this = this;

    helpers.addEvent(UI.human.io, "keyup", function (ev) {
      UI.machine.figure.classList.add("active");
      UI.human.figure.classList.remove("active");
      var t = setTimeout(function () {
        clearTimeout(t);
        UI.machine.figure.classList.remove("active");
      }, 1000);
      UI.machine.io.innerHTML = _this.toBinary(UI.human.io.textContent);
    });

    helpers.addEvent(UI.machine.io, "keyup", function (ev) {
      UI.human.figure.classList.add("active");
      UI.human.figure.classList.add("active");
      UI.human.io.innerHTML = _this.toHuman(UI.machine.io.textContent);
    });
  },

  toBinary: function (text) {
    var _this = this,
      length = text.length,
      binary = "";
    for (var i = 0; i < length; i += 1) {
      binary += _this.pad(text.charCodeAt(i).toString(2)) + " ";
    }
    return binary;
  },

  toHuman: function (text) {
    var arr = text.trim().split(/\s+/gi),
      result = "";
    arr.forEach(function (a) {
      result += String.fromCharCode(parseInt(a, 2));
    });
    return result;
  },

  pad: function (number) {
    var eight = number;
    while (eight.length < 8) {
      eight = "0" + eight;
    }
    return eight;
  }
};

var helpers = {
  addEvent: function (obj, type, fn) {
    if (obj.addEventListener) {
      obj.addEventListener(type, fn, false);
    } else if (obj.attachEvent) {
      obj["e" + type + fn] = fn;
      obj[type + fn] = function () {
        obj["e" + type + fn](window.event);
      };
      obj.attachEvent("on" + type, obj[type + fn]);
    }
  },
  triggerEvent: function (el, type) {
    if ((el[type] || false) && typeof el[type] == "function") {
      el[type](el);
    }
  }
};

App.init();

              
            
!
999px

Console