Skip to content

Commit 34f4d59

Browse files
committed
1 parent a45a43f commit 34f4d59

File tree

7 files changed

+1093
-1692
lines changed

7 files changed

+1093
-1692
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ test/coverage
88
dist
99
test/unit/bundle.js
1010
doc/reference
11-
test/test.html
11+
test/test.html
12+
.DS_Store

CHANGELOG.md

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
## Pending Next Release
1+
## v1.4.0
22

3-
- fix: make .image() use the transformation matrix ([Michael Elsdörfer](https://github.com/miracle2k)) (https://github.com/zenozeng/p5.js-svg/pull/227)
3+
4+
- chore(deps): upgrade deps
5+
- fix: make .image() use the transformation matrix
6+
([Michael Elsdörfer](https://github.com/miracle2k))
7+
(https://github.com/zenozeng/p5.js-svg/pull/227)
48

59
## v1.3.3
610

@@ -14,7 +18,9 @@
1418

1519
## v1.3.1
1620

17-
- fix(SVGCanvasElement): addEventListener, fixes https://github.com/zenozeng/p5.js-svg/issues/202, fixes https://github.com/zenozeng/p5.js-svg/issues/196
21+
- fix(SVGCanvasElement): addEventListener, fixes
22+
https://github.com/zenozeng/p5.js-svg/issues/202, fixes
23+
https://github.com/zenozeng/p5.js-svg/issues/196
1824

1925
## v1.3.0
2026

@@ -27,7 +33,8 @@
2733

2834
## v1.2.1
2935

30-
- fix: add p5.Color.prototype.indexOf, fixes https://github.com/zenozeng/p5.js-svg/issues/204
36+
- fix: add p5.Color.prototype.indexOf, fixes
37+
https://github.com/zenozeng/p5.js-svg/issues/204
3138

3239
## v1.2.0
3340

@@ -48,7 +55,9 @@
4855

4956
## v1.0.7
5057

51-
- feat: sync element's width and height to context ([email protected]), calling clear() in your draw function will now trigger internal context.__clearCanvas() to remove elements.
58+
- feat: sync element's width and height to context ([email protected]), calling
59+
clear() in your draw function will now trigger internal
60+
context.__clearCanvas() to remove elements.
5261
- test: add test for loadFont, fixes #147
5362

5463
## v1.0.6
@@ -57,13 +66,18 @@
5766

5867
## v1.0.5
5968

60-
- feat: implement CanvasTransform Interface, see https://github.com/gliffy/canvas2svg/pull/83, fixes https://github.com/zenozeng/p5.js-svg/issues/170,
61-
- refactor: support [email protected], see https://github.com/zenozeng/p5.js-svg/pull/182
69+
- feat: implement CanvasTransform Interface, see
70+
https://github.com/gliffy/canvas2svg/pull/83, fixes
71+
https://github.com/zenozeng/p5.js-svg/issues/170,
72+
- refactor: support [email protected], see
73+
https://github.com/zenozeng/p5.js-svg/pull/182
6274
- refactor: ESM
6375
- refactor: remove loadGraphics
6476
- fix: keep svgcanvas's root `<g>` when applying filter
65-
- fix: call _incrementPreload & _decrementPreload in p5.prototype.loadSVG, fixes https://github.com/zenozeng/p5.js-svg/issues/168
66-
- test: add test for resetMatrix, for https://github.com/zenozeng/p5.js-svg/issues/170
77+
- fix: call _incrementPreload & _decrementPreload in p5.prototype.loadSVG, fixes
78+
https://github.com/zenozeng/p5.js-svg/issues/168
79+
- test: add test for resetMatrix, for
80+
https://github.com/zenozeng/p5.js-svg/issues/170
6781
- test: diff without converting to png
6882
- test: update IO/saveFrames tests
6983

@@ -77,7 +91,7 @@ [email protected] (tests with [email protected])
7791

7892
- Remove String.prototype.repeat polyfill
7993

80-
Since https://github.com/processing/p5.js/issues/858 already fixed.
94+
Since https://github.com/processing/p5.js/issues/858 already fixed.
8195

8296
- Replace `this._graphics` with `this._renderer` (for [email protected])
8397

@@ -105,9 +119,11 @@ [email protected] (requires [email protected])
105119

106120
## v0.4.3
107121

108-
[email protected] (requires [email protected] with [patch#850](https://github.com/processing/p5.js/pull/850))
122+
123+
[patch#850](https://github.com/processing/p5.js/pull/850))
109124

110-
- Write filter attribute every time filter applied, fixes https://github.com/zenozeng/p5.js-svg/issues/137
125+
- Write filter attribute every time filter applied, fixes
126+
https://github.com/zenozeng/p5.js-svg/issues/137
111127

112128
- Fix SVGElement.unfilter not work when arg not defined
113129

@@ -119,11 +135,14 @@ [email protected] (requires [email protected] with [patch#850](https://github.com/processin
119135

120136
## v0.4.2
121137

122-
[email protected] (requires [email protected], with [patch#850](https://github.com/processing/p5.js/pull/850))
138+
139+
[patch#850](https://github.com/processing/p5.js/pull/850))
123140

124141
### p5.SVG
125142

126-
- add String.prototype.repeat polyfill: fixes https://github.com/zenozeng/p5.js-svg/issues/126 & https://github.com/zenozeng/p5.js-svg/issues/127
143+
- add String.prototype.repeat polyfill: fixes
144+
https://github.com/zenozeng/p5.js-svg/issues/126 &
145+
https://github.com/zenozeng/p5.js-svg/issues/127
127146

128147
- Update Browser Compatibility Info (add Safari 8 on Mac and Safari on iOS 8)
129148

@@ -133,7 +152,8 @@ [email protected] (requires [email protected], with [patch#850](https://github.com/processi
133152

134153
## v0.4.1
135154

136-
[email protected] (built on top of [email protected], with [patch#850](https://github.com/processing/p5.js/pull/850))
155+
[email protected] (built on top of [email protected], with
156+
[patch#850](https://github.com/processing/p5.js/pull/850))
137157

138158
Fix some issues in IE 10 and Safari (iOS).
139159

@@ -143,25 +163,31 @@ Fix some issues in IE 10 and Safari (iOS).
143163

144164
- Use Node.childNodes for IE
145165

146-
- Update test/io/save/canvas's-save, fixes https://github.com/zenozeng/p5.js-svg/issues/123
166+
- Update test/io/save/canvas's-save, fixes
167+
https://github.com/zenozeng/p5.js-svg/issues/123
147168

148-
- Use \<svg\> to display tests, ignore diff, workround for https://github.com/zenozeng/p5.js-svg/issues/124
169+
- Use \<svg\> to display tests, ignore diff, workround for
170+
https://github.com/zenozeng/p5.js-svg/issues/124
149171

150-
- use devicePixelRatio for diffCanvas in tests, fixes https://github.com/zenozeng/p5.js-svg/issues/125
172+
- use devicePixelRatio for diffCanvas in tests, fixes
173+
https://github.com/zenozeng/p5.js-svg/issues/125
151174

152175
### svgcanvas
153176

154-
- Use parentNode.removeChild instead of childNode.remove for IE, fixes https://github.com/zenozeng/p5.js-svg/issues/120
177+
- Use parentNode.removeChild instead of childNode.remove for IE, fixes
178+
https://github.com/zenozeng/p5.js-svg/issues/120
155179

156-
- Patch for IE's bug: search for a duplicate xmnls, fixes https://github.com/zenozeng/p5.js-svg/issues/121
180+
- Patch for IE's bug: search for a duplicate xmnls, fixes
181+
https://github.com/zenozeng/p5.js-svg/issues/121
157182

158183
- Use Node.childNodes for IE
159184

160185
## v0.4.0
161186

162187
### p5.svg
163188

164-
[email protected] (built on top of [email protected], with [patch#850](https://github.com/processing/p5.js/pull/850))
189+
[email protected] (built on top of [email protected], with
190+
[patch#850](https://github.com/processing/p5.js/pull/850))
165191

166192
#### Filters
167193

@@ -173,7 +199,7 @@ [email protected] (built on top of [email protected], with [patch#850](https://github.com/p
173199

174200
- SVGElement.prototype.unfilter = function(filter, arg)
175201

176-
Undo the filter applied.
202+
Undo the filter applied.
177203

178204
- SVGFilters.colorMatrix = function(inGraphics, resultGraphics, matrix)
179205

@@ -183,23 +209,26 @@ [email protected] (built on top of [email protected], with [patch#850](https://github.com/p
183209

184210
- SVGFilters.invert using feColorMatrix
185211

186-
- SVGFilters.threshold using feColorMatrix and feComponentTransfer (linear feFunc)
212+
- SVGFilters.threshold using feColorMatrix and feComponentTransfer (linear
213+
feFunc)
187214

188215
- SVGFilters.opaque using feColorMatrix
189216

190217
- SVGFilters._discreteTableValues
191218

192-
Generate discrete table values based on the given color map function
219+
Generate discrete table values based on the given color map function
193220

194221
- SVGFilters.posterize using feComponentTransfer (discrete feFunc)
195222

196223
- SVGFilters.erode using feOffset and feBlend
197224

198-
Will create 4 offset layer and combine them with current layer using darken blend mode.
225+
Will create 4 offset layer and combine them with current layer using darken
226+
blend mode.
199227

200228
- SVGFilters.dilate using feOffset and feBlend
201229

202-
Will create 4 offset layer and combine them with current layer using lighten blend mode.
230+
Will create 4 offset layer and combine them with current layer using lighten
231+
blend mode.
203232

204233
#### p5.SVGElement
205234

@@ -217,19 +246,19 @@ [email protected] (built on top of [email protected], with [patch#850](https://github.com/p
217246

218247
- SVGElement.prototype.parentNode()
219248

220-
Get parent node
249+
Get parent node
221250

222251
- SVGElement.prototype.parentNode(selector)
223252

224-
Get parent node matching given selector
253+
Get parent node matching given selector
225254

226255
- SVGElement.prototype.matches = function(selector)
227256

228-
To tell whether a element matches certain selector
257+
To tell whether a element matches certain selector
229258

230259
- SVGElement.prototype._getDefs
231260

232-
Get defs element, or create one if not exists
261+
Get defs element, or create one if not exists
233262

234263
#### RendererSVG
235264

@@ -289,13 +318,16 @@ [email protected] (built on top of [email protected])
289318

290319
- add RendererSVG.prototype._applyDefaults, fixes #95 (lineWidth issue)
291320

292-
- Rendering functions (createCanvas(), resizeCanvas(), noCanvas(), createGraphics()) now covered with unit tests
321+
- Rendering functions (createCanvas(), resizeCanvas(), noCanvas(),
322+
createGraphics()) now covered with unit tests
293323

294324
- use createCanvas(w, h, SVG) instead of createSVG(w, h)
295325

296326
- set viewBox attribute when resize, fixes scale issue
297327

298-
- add RendererSVG.prototype._withPixelDensity (temporally set pixel density to 1), fixes window scaled issue (https://github.com/zenozeng/p5.js-svg/issues/35)
328+
- add RendererSVG.prototype._withPixelDensity (temporally set pixel density to
329+
1), fixes window scaled issue
330+
(https://github.com/zenozeng/p5.js-svg/issues/35)
299331

300332
- Fix issues in test-render
301333

README.md

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# p5.js-svg
22

3-
The main goal of p5.SVG is to provide a SVG runtime for p5.js,
4-
so that we can draw using p5's powerful API in \<svg\>, save things to svg file
5-
and manipulating existing SVG file without rasterization.
3+
The main goal of p5.SVG is to provide a SVG runtime for p5.js, so that we can
4+
draw using p5's powerful API in \<svg\>, save things to svg file and
5+
manipulating existing SVG file without rasterization.
66

77
## Getting Started
88

@@ -18,21 +18,20 @@ Open your sketch.js and edit it:
1818

1919
```javascript
2020
function setup() {
21-
createCanvas(100, 100, SVG);
22-
background(255);
23-
fill(150);
24-
stroke(150);
21+
createCanvas(100, 100, SVG);
22+
background(255);
23+
fill(150);
24+
stroke(150);
2525
}
2626

2727
function draw() {
28-
var r = frameCount % 200 * Math.sqrt(2);
29-
background(255);
30-
ellipse(0, 0, r, r);
28+
var r = frameCount % 200 * Math.sqrt(2);
29+
background(255);
30+
ellipse(0, 0, r, r);
3131
}
3232
```
3333

34-
Then you can open your html file, and view the result.
35-
It's \<svg\>!
34+
Then you can open your html file, and view the result. It's \<svg\>!
3635

3736
![SVG Gettting Started](./doc/svg-getting-started.png)
3837

@@ -44,22 +43,26 @@ It's \<svg\>!
4443
## SVG Renderer vs Canvas2D Renderer
4544

4645
The major difference is that SVG Renderer is based on SVG Document Object Model
47-
while Canvas 2D Renderer is based on pixels.
48-
Therefore, the performance may not be as good as canvas, but SVG-format vector images can be rendered at any size without loss of quality.
46+
while Canvas 2D Renderer is based on pixels. Therefore, the performance may not
47+
be as good as canvas, but SVG-format vector images can be rendered at any size
48+
without loss of quality.
4949

50-
Note that not all drawing results are exactly same in pixel-level.For example, the round rects below are almost same, but there are some pixels different.
50+
Note that not all drawing results are exactly same in pixel-level.For example,
51+
the round rects below are almost same, but there are some pixels different.
5152

5253
![round rect](doc/round-rect.png)
5354

54-
As for filters, gray(), invert(), threshold(), opaque() did have same behavior as Canvas2D Renderer. But blur(), erode(), dilate() didn't.
55+
As for filters, gray(), invert(), threshold(), opaque() did have same behavior
56+
as Canvas2D Renderer. But blur(), erode(), dilate() didn't.
5557

56-
To implement blur, feGaussianBlur was used, which is different from Processing's blur.
57-
![blur](doc/blur.png)
58+
To implement blur, feGaussianBlur was used, which is different from Processing's
59+
blur. ![blur](doc/blur.png)
5860

59-
As for erode() and dilate(), they were implemnted using feOffset and feBlend. So, the result is not exactly same.
60-
![erode](doc/erode.png)
61+
As for erode() and dilate(), they were implemnted using feOffset and feBlend.
62+
So, the result is not exactly same. ![erode](doc/erode.png)
6163

62-
You can view all the pixels based diff on the [online tests](http://zenozeng.github.io/p5.js-svg/test/).
64+
You can view all the pixels based diff on the
65+
[online tests](http://zenozeng.github.io/p5.js-svg/test/).
6366

6467
## Browser Compatibility
6568

@@ -70,20 +73,25 @@ [email protected] was tested and should work on:
7073

7174
## How it works
7275

73-
p5.RendererSVG is a class which extends p5.Renderer2D.
74-
A mocked \<canvas\> element and a CanvasRenderingContext2D api are provided using [svgcanvas](https://github.com/zenozeng/svgcanvas),
75-
which is JavaScript Object that syncs proprieties and draws on \<svg\> element.
76+
p5.RendererSVG is a class which extends p5.Renderer2D. A mocked \<canvas\>
77+
element and a CanvasRenderingContext2D api are provided using
78+
[svgcanvas](https://github.com/zenozeng/svgcanvas), which is JavaScript Object
79+
that syncs proprieties and draws on \<svg\> element.
7680

7781
## Known issue
7882

7983
### Too many child elements
8084

81-
Since SVG is XML-based, every call of the draw function will insert elements into it, and these elements keep existing even if they are not visible. So, long-time running will result in too many child elements. We recommend calling clear() in your draw function, which will trigger internal context.__clearCanvas() to remove elements.
85+
Since SVG is XML-based, every call of the draw function will insert elements
86+
into it, and these elements keep existing even if they are not visible. So,
87+
long-time running will result in too many child elements. We recommend calling
88+
clear() in your draw function, which will trigger internal
89+
context.__clearCanvas() to remove elements.
8290

8391
```javascript
8492
function draw() {
85-
clear();
86-
// draw
93+
clear();
94+
// draw
8795
}
8896
```
8997

@@ -102,11 +110,9 @@ npm run build
102110

103111
## Tests
104112

105-
p5.SVG was driven by tests.
106-
We use Karma and mocha.
107-
Most tests are based on pixel-diff.
108-
There are still some p5's methods not covered with unit tests.
109-
But Rendering and Shape API are already covered with tests and should work.
113+
p5.SVG was driven by tests. We use Karma and mocha. Most tests are based on
114+
pixel-diff. There are still some p5's methods not covered with unit tests. But
115+
Rendering and Shape API are already covered with tests and should work.
110116

111117
If you found a bug, feel free to open a issue or pull a request.
112118

@@ -115,6 +121,3 @@ https://github.com/zenozeng/p5.js-svg/tree/master/test/unit
115121

116122
You can also run the online test yourself:
117123
https://zenozeng.github.io/p5.js-svg/test/
118-
119-
And this is our coverage report:
120-
https://coveralls.io/github/zenozeng/p5.js-svg?branch=master

0 commit comments

Comments
 (0)