led-canvas
Version:
Lightweight led board implemented with canvas
68 lines (60 loc) • 1.35 kB
JavaScript
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Cursor = (function () {
var Cursor = function Cursor(x, y, height, maxX, maxY) {
this.x = x;
this.y = y;
this.height = height;
this.max = {
x: maxX,
y: maxY
};
};
_classProps(Cursor, null, {
reset: {
writable: true,
value: function () {
this.x = 1;
this.y = 0;
}
},
plus: {
writable: true,
value: function (x) {
if (this.x + x <= this.max.x) {
this.x += x;
} else {
this.line();
}
}
},
minus: {
writable: true,
value: function (x) {
if (this.x + x >= 0) {
this.x -= x;
} else {
this.line(-1);
}
}
},
line: {
writable: true,
value: function (offset) {
if (offset === undefined) offset = 1;
var distance = offset * this.height;
this.x = 1;
if (this.y + distance <= this.max.y && this.y + distance >= 0) {
this.y += distance;
} else {
this.reset();
}
}
}
});
return Cursor;
})();
module.exports = Cursor;