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.

            
              <canvas id="canv"></canvas>
<!--
apparent text position issue on mobile...need to work that out (the second part of the text is displaced, first part seems to display fine)

Edit: I think I may have fixed the above issue - it's better(not perfect) on my mobile..
 --!>

            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Rock+Salt);

body{
  width:100%; 
  margin:0;
  overflow:hidden;
  background:hsla(0,0%,5%,1);
}
canvas{
  background:transparent;
}
            
          
!
            
              var _c = document.getElementById("canv"),
    _$ = _c.getContext("2d");
    _c.width = window.innerWidth;
    _c.height = window.innerHeight;

var anim = (function(w) {
  var arr = [],
      sz = 1.3;
  var part = function(x, y, vx, vy, _x, _y, col) {
    this.x = x;
    this.y = y;
    this.vx = vx;
    this.vy = vy;
    this.nx = _x;
    this.ny = _y;
    this.col = col;
    this.dn = false;
    this.grav = Math.random() * 3 + 6.8;
    this.fin(_x, _y);
  }
  part.prototype = {
    _fill: function() {
      _$.fillStyle = this.col;
      _$.fillRect(this.x - sz / 2, this.y - sz / 2, sz, sz)
    },
    fin: function(_x, _y) {
      this._x = _x;
      this._y = _y;
    },
    upd: function(_t_) {
      this.x += this.vx * _t_;
      this.y += this.vy * _t_;
      if (!this.dn) {
        var ay = this._y - this.y;
        var ax = this._x - this.x;
        this.xy = Math.sqrt(ax * ax + ay * ay);
        var za = 20;
        var ax = za * (ax / this.xy);
        var ay = za * (ay / this.xy);
        this.vx = (this.vx + ax * _t_) * 0.95;
        this.vy = (this.vy + ay * _t_) * 0.95;
      } else {
        this.vy += this.grav * _t_;
        if (this.y > _c.height) {
          arr.splice(arr.indexOf(this), 1, null);
        }
      }
    },
    run: function(_t_) {
      this.upd(_t_);
      this._fill();
    }
  }
  var anim = function() {
    this.pos = "init"
  };

  var anime = anim.prototype;
  anime.set = function() {
    this.c = document.createElement("canvas");
    var $ = this.c.getContext("2d");
    this.c.width = window.innerWidth;
    this.c.height = window.innerHeight;
    $.font = "70px Rock Salt";
    $.fillStyle = "hsla(327, 95%, 55%, 1)";
    var t = "Make";
    $.fillText(t, (this.c.width - $.measureText(t).width) * 0.5, this.c.height * 0.3);
    $.font = "80px Rock Salt";
    $.fillStyle = "hsla(293, 95%, 45%, 1)";
    var t0 = "Beautiful Things!";
    $.fillText(t0, (this.c.width - $.measureText(t0).width) * 0.5, this.c.height * 0.5);
    $.fillStyle = "hsla(176, 95%, 45%, 1)";
    $.font = "65px Rock Salt";
    var t1 = "Even If...";
    $.fillText(t1, (this.c.width - $.measureText(t1).width) * 0.5, this.c.height * 0.7);
    var id = $.getImageData(0, 0, this.c.width, this.c.height);
    arr = [];
    for (var x = 0; x < id.width; x += 2) {
      for (var y = 0; y < id.height; y += 3) {
        var i = (y * id.width + x) * 4;
        if (id.data[i + 3] > 128) {
          var p = new part(
            _c.width / 2 - 1 + 2 * Math.random(),
            _c.height / 2 - 1 + 2 * Math.random(),
            0,
            0,
            x + (_c.width / 2 - this.c.width / 2),
            y + (_c.height / 2 - this.c.height / 2),
            "rgba(" + id.data[i] + "," + id.data[i + 1] + "," + id.data[i + 2] + ",1)"
          );
          p.fin(_c.width / 2, _c.height / 2);
          arr.push(p);
        }
      }
    }
  };

  function txt() {
    var $ = this.c.getContext("2d");
    $.clearRect(0, 0, this.c.width, this.c.height);
    this.c.width = window.innerWidth;
    this.c.height = window.innerHeight;
    $.fillStyle = "hsla(359, 95%, 35%, 1)";
    $.font = "70px Rock Salt";
    var t2 = "💕";
    $.fillText(t2, (this.c.width - $.measureText(t2).width) * 0.05, this.c.height * 0.29);
    $.font = "50px Rock Salt";
    $.fillStyle = "hsla(44, 95%, 45%, 1)";
    var t3 = "NOBODY";
    $.fillText(t3, (this.c.width - $.measureText(t3).width) * 0.05, this.c.height * 0.2);
    $.font = "40px Rock Salt";
    $.fillStyle = "hsla(170, 5%, 35%, 1)";
    var t4 = 'Cares...';
    $.fillText(t4, (this.c.width - $.measureText(t4).width) * 0.143, this.c.height * 0.29);
    return $.getImageData(0, 0, this.c.width, this.c.height);
  }
  anime.nxt = function() {
    var id = txt.call(this);
    var idx = 0;
    var d;
    arr.sort(function() {
      return Math.random() - Math.random();
    });

    for (var x = 0; x < id.width; x += 1) {
      for (var y = 0; y < id.height; y += 2) {
        if (!(d = arr[idx])) continue;
        var i = (y * id.width + x) * 4;
        if (id.data[i + 3] > 128) {
          d.fin(x + (_c.width / 3), y + 50);
          d.col = "rgba(" + id.data[i] + "," + id.data[i + 1] + "," + id.data[i + 2] + ",1)";
          idx++
        }
      }
    }
    while (idx < arr.length) {
      if (!(d = arr[idx++])) continue;
      d.dn = true;
      d.vx = 0;
    }
  }
  anime.upd = function(_t_) {
    var i, d;
    _t_ /= 90;
    var num = 0;
    for (i = 0; i < arr.length; i++) {
      if (!(d = arr[i])) continue;
      d.run(_t_);
      if (d.xy < 3) num++;
    }

    if (num >= 5 * arr.length / 6) {
      switch (this.pos) {
        case 'init':
          this.pos = "one";

          for (i = 0; i < arr.length; i++) {
            if (!(d = arr[i])) continue;
            d.fin(d.nx, d.ny);
          }
          break;
        case 'one':
          this.pos = "two";
          this.nxt();
          break;
        default:
          break;
      }
    }
  };

  return new anim();
})(window)

var main = {
  set: function() {
    anim.set();
  },
  run: function() {
    var _this = this;
    _$.clearRect(0, 0, _c.width, _c.height);
    anim.upd(16);
    window.requestAnimationFrame(function() {
      _this.run();
    })
  }
};
main.set();
main.run();

window.addEventListener('resize',function(){
c.width = window.innerWidth;
c.height = window.innerHeight;
_c.width = window.innerWidth;
_c.height = window.innerHeight;
}, false);
            
          
!
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