-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglitchrothko-bundle.js
7 lines (5 loc) · 5.05 KB
/
glitchrothko-bundle.js
1
2
3
4
5
6
7
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,a=Array(e.length);t<e.length;t++)a[t]=e[t];return a}return Array.from(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,a,r){return a&&e(t.prototype,a),r&&e(t,r),t}}(),Artifier=function(){function e(){_classCallCheck(this,e),this.artifyImageOnload()}return _createClass(e,[{key:"artifyImageOnload",value:function(){var e=this;document.addEventListener("DOMContentLoaded",function(){var t=document.querySelector(".Canvas"),a=t.getContext("2d");document.querySelector(".Uploader").addEventListener("change",function(r){var n=new Image,o=new FileReader;o.onload=function(e){n.src=e.target.result},o.readAsDataURL(r.target.files[0]),n.onload=function(){var r=document.querySelector(".Content").offsetHeight-document.querySelector(".UploadWrapper").offsetHeight,o=r/n.height,u=Math.round(n.width*o);t.height=r,t.width=u,a.drawImage(n,0,0,u,r);var i=new ImageData(e.artFunction(a,u,r),u);a.putImageData(i,0,0)}})})}},{key:"artFunction",value:function(e,t,a){return new Uint8ClampedArray(e.getImageData(0,0,t,a).data)}},{key:"rgbToHsl",value:function(e){var t=e[0]/255,a=e[1]/255,r=e[2]/255,n=Math.max(t,a,r),o=Math.min(t,a,r),u=void 0,i=void 0,c=(n+o)/2;if(n===o)u=i=0;else{var l=n-o;switch(i=c>.5?l/(2-n-o):l/(n+o),n){case t:u=(a-r)/l+(a<r?6:0);break;case a:u=(r-t)/l+2;break;case r:u=(t-a)/l+4}u/=6}return[360*u,100*i,100*c]}},{key:"rgbaToRgb",value:function(e){var t=e[0]/255,a=e[1]/255,r=e[2]/255,n=e[3]/255,o=[];return o[0]=255*(1-n+n*t),o[1]=255*(1-n+n*a),o[2]=255*(1-n+n*r),[].concat(o,[255])}},{key:"rgbToXyz",value:function(e){var t=e[0]/255,a=e[1]/255,r=e[2]/255;return t>.04045?t=Math.pow((t+.055)/1.055,2.4):t/=12.92,a>.04045?a=Math.pow((a+.055)/1.055,2.4):a/=12.92,r>.04045?r=Math.pow((r+.055)/1.055,2.4):r/=12.92,t*=100,a*=100,r*=100,[.4124*t+.3576*a+.1805*r,.2126*t+.7152*a+.0722*r,.0193*t+.1192*a+.9505*r]}},{key:"xyzToLab",value:function(e){var t=e[0]/94.811,a=e[1]/100,r=e[2]/107.304;return t=t>.008856?Math.pow(t,1/3):7.787*t+16/116,a=a>.008856?Math.pow(a,1/3):7.787*a+16/116,r=r>.008856?Math.pow(r,1/3):7.787*r+16/116,[116*a-16,500*(t-a),200*(a-r)]}},{key:"getPixelAt",value:function(e,t,a,r){var n=4*e*a+4*t;return[r[n],r[n+1],r[n+2],r[n+3]]}},{key:"mergeArrays",value:function(e,t){e.push.apply(e,_toConsumableArray(t))}}]),e}();exports.default=Artifier;
},{}],2:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_Artifier2=require("./Artifier.js"),_Artifier3=_interopRequireDefault(_Artifier2),GlitchRothko=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this))}return _inherits(t,e),_createClass(t,[{key:"artFunction",value:function(e,t,r){for(var n=e.getImageData(0,0,t,r).data,o=[],i=[],a=[],u=[],s=0;s<r;s++)for(var l=0;l<t;l++){var c=this.getPixelAt(s,l,t,n),f=this.getHighestOfThree(c);"red"===f&&this.mergeArrays(o,c),"green"===f&&this.mergeArrays(i,c),"blue"===f&&this.mergeArrays(a,c),"grayscale"===f&&this.mergeArrays(u,c)}return new Uint8ClampedArray([].concat(o,i,a,u))}},{key:"getHighestOfThree",value:function(e){var t=void 0,r=void 0;return e[0]===e[1]&&e[0]===e[2]?"grayscale":(e[0]>e[1]?(t="red",r=0):(t="green",r=1),e[2]>e[r]&&(t="blue"),t)}}]),t}(_Artifier3.default);exports.default=GlitchRothko;var gr=new GlitchRothko;
},{"./Artifier.js":1}]},{},[2]);