UNPKG

@tsparticles/shape-cards

Version:
176 lines (175 loc) 5.99 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.paths = void 0; exports.drawPath = drawPath; function drawPath(data, path) { if (!path.segments.length || !path.segments[0].values.length) { return; } const { context, radius } = data; context.moveTo(path.segments[0].values[0].x * radius, path.segments[0].values[0].y * radius); for (const segment of path.segments) { context.bezierCurveTo(segment.values[1].x * radius, segment.values[1].y * radius, segment.values[2].x * radius, segment.values[2].y * radius, segment.values[3].x * radius, segment.values[3].y * radius); } for (let i = path.segments.length - 1; i >= 0; i--) { const segment = path.segments[i]; context.bezierCurveTo(-segment.values[2].x * radius, segment.values[2].y * radius, -segment.values[1].x * radius, segment.values[1].y * radius, -segment.values[0].x * radius, segment.values[0].y * radius); } } const n = 1.0 / 2; exports.paths = { heart: { segments: [ { values: [ { x: 0, y: n }, { x: 0, y: n }, { x: n, y: 0 }, { x: n, y: -n / 2 }, ], }, { values: [ { x: n, y: -n / 2 }, { x: n, y: -n / 2 }, { x: n, y: -n }, { x: n / 2, y: -n }, ], }, { values: [ { x: n / 2, y: -n }, { x: n / 2, y: -n }, { x: 0, y: -n }, { x: 0, y: -n / 2 }, ], }, ], }, diamond: { segments: [ { values: [ { x: 0, y: n }, { x: 0, y: n }, { x: (3 * n) / 4, y: 0 }, { x: (3 * n) / 4, y: 0 }, ], }, { values: [ { x: (3 * n) / 4, y: 0 }, { x: (3 * n) / 4, y: 0 }, { x: 0, y: -n }, { x: 0, y: -n }, ], }, ], }, club: { segments: [ { values: [ { x: 0, y: -n }, { x: 0, y: -n }, { x: n / 2, y: -n }, { x: n / 2, y: -n / 2 }, ], }, { values: [ { x: n / 2, y: -n / 2 }, { x: n / 2, y: -n / 2 }, { x: n, y: -n / 2 }, { x: n, y: 0 }, ], }, { values: [ { x: n, y: 0 }, { x: n, y: 0 }, { x: n, y: n / 2 }, { x: n / 2, y: n / 2 }, ], }, { values: [ { x: n / 2, y: n / 2 }, { x: n / 2, y: n / 2 }, { x: n / 8, y: n / 2 }, { x: n / 8, y: n / 8 }, ], }, { values: [ { x: n / 8, y: n / 8 }, { x: n / 8, y: n / 2 }, { x: n / 2, y: n }, { x: n / 2, y: n }, ], }, { values: [ { x: n / 2, y: n }, { x: n / 2, y: n }, { x: 0, y: n }, { x: 0, y: n }, ], }, ], }, spade: { segments: [ { values: [ { x: 0, y: -n }, { x: 0, y: -n }, { x: n, y: -n / 2 }, { x: n, y: 0 }, ], }, { values: [ { x: n, y: 0 }, { x: n, y: 0 }, { x: n, y: n / 2 }, { x: n / 2, y: n / 2 }, ], }, { values: [ { x: n / 2, y: n / 2 }, { x: n / 2, y: n / 2 }, { x: n / 8, y: n / 2 }, { x: n / 8, y: n / 8 }, ], }, { values: [ { x: n / 8, y: n / 8 }, { x: n / 8, y: n / 2 }, { x: n / 2, y: n }, { x: n / 2, y: n }, ], }, { values: [ { x: n / 2, y: n }, { x: n / 2, y: n }, { x: 0, y: n }, { x: 0, y: n }, ], }, ], }, }; });