canvas2d-wrapper 1.3.4 → 1.5.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/README.md CHANGED
@@ -1,98 +1,101 @@
1
- # canvas2d-wrapper
2
-
3
- > A React Wrapper to use HTML5 canvas with mouse move and zoom abilities.
4
-
5
- [![NPM](https://img.shields.io/npm/v/canvas2d-wrapper.svg)](https://www.npmjs.com/package/canvas2d-wrapper)
6
-
7
- Do you want an example app made with this library ? Check out my game Alchemistry on [Steam](https://store.steampowered.com/app/1730540/Alchemistry/) or on [itch.io](https://elanis.itch.io/alchemistry).
8
-
9
- ## Install
10
-
11
- ```bash
12
- npm install --save canvas2d-wrapper
13
- ```
14
-
15
- ## Usage
16
-
17
- ```jsx
18
- import React from 'react'
19
-
20
- import { Canvas2D, CanvasImage, Circle, Polygon, Rect } from 'canvas2d-wrapper'
21
- import 'canvas2d-wrapper/dist/index.css'
22
-
23
- const App = () => {
24
- const elements = [];
25
- for(let i = 0; i < 998; i++) {
26
- let object = null;
27
- if(Math.random() > 0.5) {
28
- object = new Rect({
29
- id: i,
30
- x: 50 - Math.round(Math.random() * 100),
31
- y: 50 - Math.round(Math.random() * 100),
32
- width: 1,
33
- height: 1,
34
- fill: (Math.random() > 0.5) ? 'black' : undefined,
35
- stroke: (Math.random() > 0.5) ? 'black' : undefined
36
- });
37
- } else {
38
- object = new Circle({
39
- id: i,
40
- x: 50 - Math.round(Math.random() * 100),
41
- y: 50 - Math.round(Math.random() * 100),
42
- radius: 0.5,
43
- fill: (Math.random() > 0.5) ? 'black' : undefined,
44
- stroke: (Math.random() > 0.5) ? 'black' : undefined
45
- });
46
- }
47
-
48
- if(!object.fill && !object.stroke) {
49
- object.fill = 'green';
50
- }
51
-
52
- elements.push(object);
53
- }
54
-
55
- const points = [];
56
- for(let i = 0; i < 5; i++) {
57
- points.push({
58
- x: 50 - Math.round(Math.random() * 100),
59
- y: 50 - Math.round(Math.random() * 100),
60
- });
61
- }
62
-
63
- const polygon = new Polygon({
64
- id: 'poly',
65
- points,
66
- stroke: 'red',
67
- });
68
- elements.push(polygon);
69
-
70
- const polygon2 = new Polygon({
71
- id: 'poly',
72
- points,
73
- fill: 'orange',
74
- zIndex: -1,
75
- });
76
- elements.push(polygon2);
77
-
78
- return (
79
- <Canvas2D
80
- elements={elements}
81
- width={1200}
82
- height={700}
83
- minZoom={0.25}
84
- maxZoom={4}
85
- tileSize={32}
86
- onClick={(e) => {
87
- console.log('Click event:', e);
88
- }}
89
- />
90
- );
91
- }
92
-
93
- export default App;
94
- ```
95
-
96
- ## License
97
-
98
- MIT © [Elanis](https://github.com/Elanis)
1
+ # canvas2d-wrapper
2
+
3
+ > A React Wrapper to use HTML5 canvas with mouse move and zoom abilities.
4
+
5
+ [![NPM](https://img.shields.io/npm/v/canvas2d-wrapper.svg)](https://www.npmjs.com/package/canvas2d-wrapper)
6
+ [![Reliability Rating](https://sonar.dysnomia.studio/api/project_badges/measure?project=canvas2d-wrapper&metric=reliability_rating)](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper) [![Maintainability Rating](https://sonar.dysnomia.studio/api/project_badges/measure?project=canvas2d-wrapper&metric=sqale_rating)](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper) [![Security Rating](https://sonar.dysnomia.studio/api/project_badges/measure?project=canvas2d-wrapper&metric=security_rating)](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper)
7
+ [![Duplicated Lines (%)](https://sonar.dysnomia.studio/api/project_badges/measure?project=canvas2d-wrapper&metric=duplicated_lines_density)](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper) [![Coverage](https://sonar.dysnomia.studio/api/project_badges/measure?project=canvas2d-wrapper&metric=coverage)](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper)
8
+
9
+
10
+ Do you want an example app made with this library ? Check out my game Alchemistry on [Steam](https://store.steampowered.com/app/1730540/Alchemistry/) or on [itch.io](https://elanis.itch.io/alchemistry).
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install --save canvas2d-wrapper
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```jsx
21
+ import React from 'react'
22
+
23
+ import { Canvas2D, CanvasImage, Circle, Polygon, Rect } from 'canvas2d-wrapper'
24
+ import 'canvas2d-wrapper/dist/index.css'
25
+
26
+ const App = () => {
27
+ const elements = [];
28
+ for(let i = 0; i < 998; i++) {
29
+ let object = null;
30
+ if(Math.random() > 0.5) {
31
+ object = new Rect({
32
+ id: i,
33
+ x: 50 - Math.round(Math.random() * 100),
34
+ y: 50 - Math.round(Math.random() * 100),
35
+ width: 1,
36
+ height: 1,
37
+ fill: (Math.random() > 0.5) ? 'black' : undefined,
38
+ stroke: (Math.random() > 0.5) ? 'black' : undefined
39
+ });
40
+ } else {
41
+ object = new Circle({
42
+ id: i,
43
+ x: 50 - Math.round(Math.random() * 100),
44
+ y: 50 - Math.round(Math.random() * 100),
45
+ radius: 0.5,
46
+ fill: (Math.random() > 0.5) ? 'black' : undefined,
47
+ stroke: (Math.random() > 0.5) ? 'black' : undefined
48
+ });
49
+ }
50
+
51
+ if(!object.fill && !object.stroke) {
52
+ object.fill = 'green';
53
+ }
54
+
55
+ elements.push(object);
56
+ }
57
+
58
+ const points = [];
59
+ for(let i = 0; i < 5; i++) {
60
+ points.push({
61
+ x: 50 - Math.round(Math.random() * 100),
62
+ y: 50 - Math.round(Math.random() * 100),
63
+ });
64
+ }
65
+
66
+ const polygon = new Polygon({
67
+ id: 'poly',
68
+ points,
69
+ stroke: 'red',
70
+ });
71
+ elements.push(polygon);
72
+
73
+ const polygon2 = new Polygon({
74
+ id: 'poly',
75
+ points,
76
+ fill: 'orange',
77
+ zIndex: -1,
78
+ });
79
+ elements.push(polygon2);
80
+
81
+ return (
82
+ <Canvas2D
83
+ elements={elements}
84
+ width={1200}
85
+ height={700}
86
+ minZoom={0.25}
87
+ maxZoom={4}
88
+ tileSize={32}
89
+ onClick={(e) => {
90
+ console.log('Click event:', e);
91
+ }}
92
+ />
93
+ );
94
+ }
95
+
96
+ export default App;
97
+ ```
98
+
99
+ ## License
100
+
101
+ MIT © [Elanis](https://github.com/Elanis)