ng-chiptan
Version:
angularjs component to render chiptan flicker code
104 lines (98 loc) • 4.85 kB
JavaScript
!function (t) {
var e = {};
function n(r) {
if (e[r]) return e[r].exports;
var o = e[r] = {i: r, l: !1, exports: {}};
return t[r].call(o.exports, o, o.exports, n), o.l = !0, o.exports
}
n.m = t, n.c = e, n.d = function (t, e, r) {
n.o(t, e) || Object.defineProperty(t, e, {enumerable: !0, get: r})
}, n.r = function (t) {
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {value: "Module"}), Object.defineProperty(t, "__esModule", {value: !0})
}, n.t = function (t, e) {
if (1 & e && (t = n(t)), 8 & e) return t;
if (4 & e && "object" == typeof t && t && t.__esModule) return t;
var r = Object.create(null);
if (n.r(r), Object.defineProperty(r, "default", {
enumerable: !0,
value: t
}), 2 & e && "string" != typeof t) for (var o in t) n.d(r, o, function (e) {
return t[e]
}.bind(null, o));
return r
}, n.n = function (t) {
var e = t && t.__esModule ? function () {
return t.default
} : function () {
return t
};
return n.d(e, "a", e), e
}, n.o = function (t, e) {
return Object.prototype.hasOwnProperty.call(t, e)
}, n.p = "", n(n.s = 0)
}([function (t, e, n) {
"use strict";
function r(t) {
var e = t.toUpperCase().replace(/[^a-fA-F0-9]/g, ""), n = function (t, e) {
for (var n = t.toString(16).toUpperCase(); n.length < e;) n = "0" + n;
return n
}, r = function (t) {
for (var e = 0; 0 != t;) e += t % 10, t = Math.floor(t / 10);
return e
};
this.getCode = function () {
return e
}, function () {
var t = e.length / 2 - 1;
e = n(t, 2) + e.substr(2);
for (var o = function () {
var t = 0, n = "", r = parseInt(e.slice(0, 2), 16);
for (t += 2; t < e.length - 2;) t += 1, r = parseInt(e.slice(t, t + 1), 16), t += 1, n += e.slice(t, t + 2 * r), t += 2 * r;
return n
}(), i = 0, a = 0; a < o.length; a += 2) i += 1 * parseInt(o[a], 16) + r(2 * parseInt(o[a + 1], 16));
i = (10 - i % 10) % 10, e = e.substr(0, e.length - 2) + n(i, 1) + e.substr(e.length - 1);
for (var l = 0, c = 0; c < e.length - 2; c++) l ^= parseInt(e[c], 16);
e = e.substr(0, e.length - 1) + n(l, 1)
}()
}
function o(t, e, n, r) {
var o, i, a, l, c, u, s = this;
this.reset = function () {
i = 0, a = 1
};
this.step = function () {
var t = c.width / 5;
l[i][0] = a;
for (var e = 0; e < 5; e++) 1 == l[i][e] ? u.fillStyle = r : u.fillStyle = n, u.fillRect(e * t + 7, 7, t - 14, c.height - 14);
return --a < 0 && (a = 1, ++i >= l.length && (i = 0)), 0
}, this.getCanvas = function () {
return c
}, this.setCode = function (t) {
o = t.getCode(), function () {
var t = new Object;
t[0] = [0, 0, 0, 0, 0], t[1] = [0, 1, 0, 0, 0], t[2] = [0, 0, 1, 0, 0], t[3] = [0, 1, 1, 0, 0], t[4] = [0, 0, 0, 1, 0], t[5] = [0, 1, 0, 1, 0], t[6] = [0, 0, 1, 1, 0], t[7] = [0, 1, 1, 1, 0], t[8] = [0, 0, 0, 0, 1], t[9] = [0, 1, 0, 0, 1], t.A = [0, 0, 1, 0, 1], t.B = [0, 1, 1, 0, 1], t.C = [0, 0, 0, 1, 1], t.D = [0, 1, 0, 1, 1], t.E = [0, 0, 1, 1, 1], t.F = [0, 1, 1, 1, 1], o = "0FFF" + o, l = new Array;
for (var e = 0; e < o.length; e += 2) l[e] = t[o[e + 1]], l[e + 1] = t[o[e]]
}(), s.reset()
}, function (t, e, n, r) {
(c = document.createElement("canvas")).width = t, c.height = e, c.getContext && (u = c.getContext("2d")), u.fillStyle = n, u.fillRect(0, 0, c.width, c.height)
}(t, e, n)
}
n.r(e), angular.module("ngChiptan", []).component("ngChiptan", {
template: "\n <div id='flickercontainer'></div>\n ",
bindings: {code: "<", width: "<", height: "<", bgColor: "<", barColor: "<"},
controller: function () {
var t = this;
this.$onInit = function () {
t.state = {canvas: new o(t.width, t.height, t.bgColor, t.barColor), code: new r(t.code)};
var e = t.state, n = e.canvas, i = e.code;
t.code && (document.getElementById("flickercontainer").appendChild(n.getCanvas()), n.setCode(i), t.startFlicker())
}, this.startFlicker = function () {
t.interval = setInterval(t.step.bind(t), 50)
}, this.stopFlicker = function () {
clearInterval(t.interval)
}, this.step = function () {
t.state.canvas.step()
}
}
})
}]);