@tsparticles/shape-rounded-polygon 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/browser/IRoundedPolygonShape.js +1 -0
- package/browser/RoundedParticle.js +1 -0
- package/browser/RoundedPolygonDrawer.js +31 -0
- package/browser/index.js +4 -0
- package/cjs/IRoundedPolygonShape.js +2 -0
- package/cjs/RoundedParticle.js +2 -0
- package/cjs/RoundedPolygonDrawer.js +35 -0
- package/cjs/index.js +8 -0
- package/esm/IRoundedPolygonShape.js +1 -0
- package/esm/RoundedParticle.js +1 -0
- package/esm/RoundedPolygonDrawer.js +31 -0
- package/esm/index.js +4 -0
- package/package.json +55 -0
- package/report.html +39 -0
- package/tsparticles.shape.rounded-polygon.js +146 -0
- package/tsparticles.shape.rounded-polygon.min.js +2 -0
- package/tsparticles.shape.rounded-polygon.min.js.LICENSE.txt +1 -0
- package/types/IRoundedPolygonShape.d.ts +5 -0
- package/types/RoundedParticle.d.ts +4 -0
- package/types/RoundedPolygonDrawer.d.ts +7 -0
- package/types/index.d.ts +2 -0
- package/umd/IRoundedPolygonShape.js +12 -0
- package/umd/RoundedParticle.js +12 -0
- package/umd/RoundedPolygonDrawer.js +45 -0
- package/umd/index.js +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Rounded Polygon Shape
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/@tsparticles/shape-rounded-polygon)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/shape-rounded-polygon)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/shape-rounded-polygon) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) additional rounded polygon shape.
|
|
10
|
+
|
|
11
|
+
## How to use it
|
|
12
|
+
|
|
13
|
+
### CDN / Vanilla JS / jQuery
|
|
14
|
+
|
|
15
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
|
+
|
|
17
|
+
Including the `tsparticles.shape.rounded-polygon.min.js` file will export the function to load the shape:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
loadRoundedPolygonShape;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the shape like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadRoundedPolygonShape(tsParticles);
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
/* here you can use particles.shape.type: "rounded-polygon" */
|
|
36
|
+
/* or you can use particles.shape.type: "triangle" */
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
})();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### ESM / CommonJS
|
|
43
|
+
|
|
44
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
45
|
+
|
|
46
|
+
```shell
|
|
47
|
+
$ npm install @tsparticles/shape-rounded-polygon
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
or
|
|
51
|
+
|
|
52
|
+
```shell
|
|
53
|
+
$ yarn add @tsparticles/shape-rounded-polygon
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then you need to import it in the app, like this:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
60
|
+
const { loadRoundedPolygonShape } = require("@tsparticles/shape-rounded-polygon");
|
|
61
|
+
|
|
62
|
+
(async () => {
|
|
63
|
+
await loadRoundedPolygonShape(tsParticles);
|
|
64
|
+
})();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
or
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
71
|
+
import { loadRoundedPolygonShape } from "@tsparticles/shape-rounded-polygon";
|
|
72
|
+
|
|
73
|
+
(async () => {
|
|
74
|
+
await loadRoundedPolygonShape(tsParticles);
|
|
75
|
+
})();
|
|
76
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
function polygon(sides, radius, rot = 0) {
|
|
3
|
+
const step = (Math.PI * 2) / sides, path = [];
|
|
4
|
+
for (let i = 0; i < sides; i++) {
|
|
5
|
+
path.push({ x: Math.cos(i * step + rot) * radius, y: Math.sin(i * step + rot) * radius });
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
}
|
|
9
|
+
function roundedPath(context, path, radius) {
|
|
10
|
+
let p1 = path[0], p2 = path[1];
|
|
11
|
+
const len = path.length;
|
|
12
|
+
context.moveTo((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);
|
|
13
|
+
for (let i = 1; i <= len; i++) {
|
|
14
|
+
p1 = p2;
|
|
15
|
+
p2 = path[(i + 1) % len];
|
|
16
|
+
context.arcTo(p1.x, p1.y, (p1.x + p2.x) / 2, (p1.y + p2.y) / 2, radius);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class RoundedPolygonDrawer {
|
|
20
|
+
draw(context, particle, radius) {
|
|
21
|
+
roundedPath(context, polygon(particle.sides, radius), particle.borderRadius ?? 5);
|
|
22
|
+
}
|
|
23
|
+
getSidesCount(particle) {
|
|
24
|
+
const roundedPolygon = particle.shapeData;
|
|
25
|
+
return Math.round(getRangeValue(roundedPolygon?.sides ?? 5));
|
|
26
|
+
}
|
|
27
|
+
particleInit(container, particle) {
|
|
28
|
+
const shapeData = particle.shapeData;
|
|
29
|
+
particle.borderRadius = Math.round(getRangeValue(shapeData?.radius ?? 5)) * container.retina.pixelRatio;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RoundedPolygonDrawer = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
function polygon(sides, radius, rot = 0) {
|
|
6
|
+
const step = (Math.PI * 2) / sides, path = [];
|
|
7
|
+
for (let i = 0; i < sides; i++) {
|
|
8
|
+
path.push({ x: Math.cos(i * step + rot) * radius, y: Math.sin(i * step + rot) * radius });
|
|
9
|
+
}
|
|
10
|
+
return path;
|
|
11
|
+
}
|
|
12
|
+
function roundedPath(context, path, radius) {
|
|
13
|
+
let p1 = path[0], p2 = path[1];
|
|
14
|
+
const len = path.length;
|
|
15
|
+
context.moveTo((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);
|
|
16
|
+
for (let i = 1; i <= len; i++) {
|
|
17
|
+
p1 = p2;
|
|
18
|
+
p2 = path[(i + 1) % len];
|
|
19
|
+
context.arcTo(p1.x, p1.y, (p1.x + p2.x) / 2, (p1.y + p2.y) / 2, radius);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class RoundedPolygonDrawer {
|
|
23
|
+
draw(context, particle, radius) {
|
|
24
|
+
roundedPath(context, polygon(particle.sides, radius), particle.borderRadius ?? 5);
|
|
25
|
+
}
|
|
26
|
+
getSidesCount(particle) {
|
|
27
|
+
const roundedPolygon = particle.shapeData;
|
|
28
|
+
return Math.round((0, engine_1.getRangeValue)(roundedPolygon?.sides ?? 5));
|
|
29
|
+
}
|
|
30
|
+
particleInit(container, particle) {
|
|
31
|
+
const shapeData = particle.shapeData;
|
|
32
|
+
particle.borderRadius = Math.round((0, engine_1.getRangeValue)(shapeData?.radius ?? 5)) * container.retina.pixelRatio;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.RoundedPolygonDrawer = RoundedPolygonDrawer;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadRoundedPolygonShape = void 0;
|
|
4
|
+
const RoundedPolygonDrawer_1 = require("./RoundedPolygonDrawer");
|
|
5
|
+
async function loadRoundedPolygonShape(engine, refresh = true) {
|
|
6
|
+
await engine.addShape("rounded-polygon", new RoundedPolygonDrawer_1.RoundedPolygonDrawer(), refresh);
|
|
7
|
+
}
|
|
8
|
+
exports.loadRoundedPolygonShape = loadRoundedPolygonShape;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
function polygon(sides, radius, rot = 0) {
|
|
3
|
+
const step = (Math.PI * 2) / sides, path = [];
|
|
4
|
+
for (let i = 0; i < sides; i++) {
|
|
5
|
+
path.push({ x: Math.cos(i * step + rot) * radius, y: Math.sin(i * step + rot) * radius });
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
}
|
|
9
|
+
function roundedPath(context, path, radius) {
|
|
10
|
+
let p1 = path[0], p2 = path[1];
|
|
11
|
+
const len = path.length;
|
|
12
|
+
context.moveTo((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);
|
|
13
|
+
for (let i = 1; i <= len; i++) {
|
|
14
|
+
p1 = p2;
|
|
15
|
+
p2 = path[(i + 1) % len];
|
|
16
|
+
context.arcTo(p1.x, p1.y, (p1.x + p2.x) / 2, (p1.y + p2.y) / 2, radius);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class RoundedPolygonDrawer {
|
|
20
|
+
draw(context, particle, radius) {
|
|
21
|
+
roundedPath(context, polygon(particle.sides, radius), particle.borderRadius ?? 5);
|
|
22
|
+
}
|
|
23
|
+
getSidesCount(particle) {
|
|
24
|
+
const roundedPolygon = particle.shapeData;
|
|
25
|
+
return Math.round(getRangeValue(roundedPolygon?.sides ?? 5));
|
|
26
|
+
}
|
|
27
|
+
particleInit(container, particle) {
|
|
28
|
+
const shapeData = particle.shapeData;
|
|
29
|
+
particle.borderRadius = Math.round(getRangeValue(shapeData?.radius ?? 5)) * container.retina.pixelRatio;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/esm/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsparticles/shape-rounded-polygon",
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
|
+
"description": "tsParticles rounded polygon shape",
|
|
5
|
+
"homepage": "https://particles.js.org",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/matteobruni/tsparticles.git",
|
|
9
|
+
"directory": "shapes/rounded-polygon"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"front-end",
|
|
13
|
+
"frontend",
|
|
14
|
+
"tsparticles",
|
|
15
|
+
"particles",
|
|
16
|
+
"particle",
|
|
17
|
+
"canvas",
|
|
18
|
+
"jsparticles",
|
|
19
|
+
"xparticles",
|
|
20
|
+
"particles-js",
|
|
21
|
+
"particles.js",
|
|
22
|
+
"particles-ts",
|
|
23
|
+
"particles.ts",
|
|
24
|
+
"typescript",
|
|
25
|
+
"javascript",
|
|
26
|
+
"animation",
|
|
27
|
+
"web",
|
|
28
|
+
"html5",
|
|
29
|
+
"web-design",
|
|
30
|
+
"webdesign",
|
|
31
|
+
"css",
|
|
32
|
+
"html",
|
|
33
|
+
"css3",
|
|
34
|
+
"animated",
|
|
35
|
+
"background",
|
|
36
|
+
"@tsparticles/shape"
|
|
37
|
+
],
|
|
38
|
+
"author": "Matteo Bruni <matteo.bruni@me.com>",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/matteobruni/tsparticles/issues"
|
|
42
|
+
},
|
|
43
|
+
"main": "cjs/index.js",
|
|
44
|
+
"jsdelivr": "tsparticles.shape.rounded-polygon.min.js",
|
|
45
|
+
"unpkg": "tsparticles.shape.rounded-polygon.min.js",
|
|
46
|
+
"module": "esm/index.js",
|
|
47
|
+
"types": "types/index.d.ts",
|
|
48
|
+
"sideEffects": false,
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@tsparticles/engine": "^3.0.0-beta.0"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|