123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <input id="input" type="text" value="Ԉ"/>
<canvas id="canv">
</canvas>
<!--
Use input to change shuffled text
Shuffled Digits are result of Math.random()*Math.PI
Initial hue value is set at 3.14159265359

!-->
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=EB+Garamond);
html, body{
  background:hsla(0,0%,5%,1);
  margin:0;
  overflow:hidden;
  width:100%; 
  font-family: 'EB Garamond', serif;
  
}
input{
  background:hsla(0, 0%, 0%, .5);
  border:none;
  padding:.8em;
  color:hsla(205, 95%, 75%, 1);
  position:absolute;
  top:0;
  left:0;
  
}

            
          
!
            
              window.addEventListener("load", function() {
  var c = document.getElementById("canv");
  var $ = c.getContext('2d');
  _txtD = new _txtDraw(c);
  _ptxtD = new _txtP(c);
  c.width = window.innerWidth;
  c.height = window.innerHeight;
  var tField = document.getElementById("input");
  
  tField.addEventListener("keyup", function() {
    _toPart(this.value);
  }, false);

  _toPart(tField.value);

}, false);


var Part = function() {
  this.go();

  return this;
};
Part.prototype = {
  go: function() {
    this.curr_ = null;
    this.prev_ = null;
  },

  _add: function(p_) {
    if (!this.curr_) {
      this.curr_ = this.prev_ = p_;
    } else {
      this.prev_.next = p_;
      this.prev_ = p_;
    }
  },

  _rem: function() {
    var node = this.curr_;
    if (!node) {
      return;
    }

    var del_ = null;
    do {
      del_ = node.next;
      delete node;
      node = null;
      if (!del_) {
        break;
      }
    } while (node = del_.next);
    this.curr_ = null;
    this.prev_ = null;
  },

  _getCurr: function() {
    return this.curr_;
  }
};

var pTxt = function(x, y) {
  this.x = x;
  this.y = y;
};
pTxt.prototype = {};

var _txtDraw = function(c) {
  this.go(c);

  return this;
};
_txtDraw.prototype = {
  go: function(c) {
    this.c = c;
    this.$ = c.getContext('2d');
    this.bg = [0, 0, 0, 0];
  },

  _drwTxt: function(txt) {
    this.$.clearRect(0, 0, this.c.width, this.c.height);
    this.$.font = "25px EB Garamond";
    this.$.fillStyle = "#CCC";
    this.$.fillText(txt, 5, 30);
  },

  isstart: function(px, idx) {
    var a = 1;
    if (px[idx + a] != this.bg[a]) {
      return true;
    }
    return false;
  },

  _getPos: function(l) {
    if (!l) {
      return;
    }

    var upper = left = 0;
    var imgData = this.$.getImageData(upper, left,
      this.c.width, this.c.height);
    for (var x = 0; x < this.c.width; x++) {
      for (var y = 0; y < this.c.height; y++) {
        var idx = (x + y * this.c.width) *2 ;
        if (this.isstart(imgData.data, idx)) {
          l({
            "$": this.$,
            "x": x,
            "y": y
          });
        }
      }
    }
  }
};

var _txtP = function(c) {
  this.go(c);

  return this;
};
_txtP.prototype = {
  go: function(c) {
    this.c = c;
    this.$ = c.getContext('2d');
  },

  _set: function(msec) {
    this.t = msec;
  },

  _begin: function(pm) {
    var it_ = this;
    var u = 3.14159265359;
    this.id_ = setInterval((function() {
      u-= 0.5;
      return (function() {
        this.$.clearRect(0, 0, this.c.width, this.c.height);
        this.$.font = "bold 20px EB Garamond";
        this.$.fillStyle = 'hsla('+u+',95%,50%,1)';
        var node = part._getCurr();
        if (!node) {
          return;
        }
        do {
          this.$.fillText(Math.round(Math.random() * Math.PI*2), node.x * 10, node.y * 8);
/* 
 Display random Characters rather than PI digits:    this.$.fillText(String.fromCharCode(Math.round(Math.random() * 42 + 48)), node.x * 8-200, node.y * 6);
*/
        } while (node = node.next);
      }.call(it_));
    }), this.t);
  },

  _fin: function() {
    clearInterval(this.id_);
  },

  _clr: function() {
    this.$.clearRect(0, 0, this.c.width, this.c.height);
  }
};

var part = new Part();
var _txtD = null;
var _ptxtD = null;

var _toPart = function(txt) {
  part._rem();
  _ptxtD._fin();
  _ptxtD._clr();
  _txtD._drwTxt(txt);
  
  var isL = function(x) {
    x.$.fillRect(x.x, x.y, 1, 1);
    part._add(new pTxt(x.x, x.y));
  };
  _txtD._getPos(isL);
  _ptxtD._set(60);
  _ptxtD._begin(part);
};
window.addEventListener('resize',function(){
  c.width = window.innerWidth;
  c.height = window.innerHeight;
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console