Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stroke colour #157

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ const defaultOptions = {
colorSpace: 'lab',
colorFunction: trianglify.colorFunctions.interpolateLinear(0.5),
strokeWidth: 0,
strokeColor: null,
points: null
}
```
Expand Down Expand Up @@ -255,6 +256,10 @@ Boolean, defaults to `true`. Specifies whether the polygons generated by Triangl

Number, defaults to 0. Specify the width of the strokes used to outline the polygons. This can be used in conjunction with `fill: false` to generate weblike patterns.

**`strokeColor`**

Null, or string of CSS-formatted colors, default is `null`.

**`points`**

Array of points ([x, y]) to triangulate, defaults to null. When not specified an array randomised points is generated filling the space. Points must be within the coordinate space defined by `width` and `height`. See [`examples/custom-points-example.html`](./examples/custom-points-example.html) for a demonstration of how this option can be used to generate circular trianglify patterns.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v4.2
- support for stroke color

v4
- ground-up port to ES2015
- support for node-canvas 2.6
Expand Down
4 changes: 2 additions & 2 deletions src/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class Pattern {
return s('path', {
d,
fill: opts.fill ? poly.color.css() : undefined,
stroke: hasStroke ? poly.color.css() : undefined,
stroke: hasStroke ? opts.strokeColor || optspoly.color.css() : undefined,
'stroke-width': hasStroke ? opts.strokeWidth : undefined,
'stroke-linejoin': hasStroke ? 'round' : undefined,
'shape-rendering': opts.fill ? 'crispEdges' : undefined
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class Pattern {
polys.forEach(poly => drawPoly(
poly,
opts.fill && { color: poly.color },
(opts.strokeWidth > 0) && { color: poly.color, width: opts.strokeWidth }
(opts.strokeWidth > 0) && { color: opts.strokeColor || poly.color, width: opts.strokeWidth }
))

return canvas
Expand Down
1 change: 1 addition & 0 deletions src/trianglify.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const defaultOptions = {
colorFunction: colorFunctions.interpolateLinear(0.5),
fill: true,
strokeWidth: 0,
strokeColor: null,
points: null
}

Expand Down