@dank-inc/sketchy
Version:
A Super-dank sketching library built with ♥ and typescript!
38 lines (37 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawShape = exports.saver = exports.arc = void 0;
var arc = function (context, x, y, r, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.fill, fill = _c === void 0 ? true : _c, _d = _b.stroke, stroke = _d === void 0 ? false : _d, _e = _b.start, start = _e === void 0 ? 0 : _e, _f = _b.end, end = _f === void 0 ? Math.PI * 2 : _f;
context.beginPath();
context.arc(x, y, r, start, end);
context.closePath();
if (stroke)
context.stroke();
if (fill)
context.fill();
};
exports.arc = arc;
var saver = function (context, body) {
context.save();
body();
context.restore();
};
exports.saver = saver;
var drawShape = function (context, points, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.fill, fill = _c === void 0 ? false : _c, _d = _b.stroke, stroke = _d === void 0 ? false : _d, _e = _b.closed, closed = _e === void 0 ? true : _e;
context.beginPath();
var _f = points[0], x = _f[0], y = _f[1];
context.moveTo(x, y);
for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
var _g = points_1[_i], x_1 = _g[0], y_1 = _g[1];
context.lineTo(x_1, y_1);
}
if (closed)
context.lineTo(x, y);
if (stroke)
context.stroke();
if (fill)
context.fill();
};
exports.drawShape = drawShape;