Skip to content

Commit 3f5b3f0

Browse files
authored
Merge pull request #53 from bence-toth/diagonal-variance
Introduced diagonal option
2 parents ecb2c99 + b8be301 commit 3f5b3f0

File tree

12 files changed

+158
-45
lines changed

12 files changed

+158
-45
lines changed

README.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,26 @@ The options `xResolution` and `yResolution` are the only options which cannot be
7979

8080
### Variance
8181

82-
| Member name | Description |
83-
|------------------------|----------------------------------------------------|
84-
| `shapeFuzz` | Variance factor of grid points (0-1) |
85-
| `colorFuzz.hue` | Variance factor of triangle color hue (0-1) |
86-
| `colorFuzz.saturation` | Variance factor of triangle color saturation (0-1) |
87-
| `colorFuzz.lightness` | Variance factor of triangle color lightness (0-1) |
88-
| `colorFuzz.alpha` | Variance factor of triangle color alpha (0-1) |
82+
| Member name | Description |
83+
|------------------------|-------------------------------------------------------------|
84+
| `shapeFuzz` | Variance factor of grid points (0-1) |
85+
| `colorFuzz.hue` | Variance factor of triangle color hue (0-1) |
86+
| `colorFuzz.saturation` | Variance factor of triangle color saturation (0-1) |
87+
| `colorFuzz.lightness` | Variance factor of triangle color lightness (0-1) |
88+
| `colorFuzz.alpha` | Variance factor of triangle color alpha (0-1) |
89+
| `diagonals` | Either `'nw-se'`, `'ne-sw'`, `'alternating'`, or `'random'` |
8990

9091
Variance options control how the triangles can deviate from their original shape and coloring.
9192

9293
The option `shapeFuzz` controls how far the grid points may venture from their original location.
9394

9495
Parameters that belong the object `colorFuzz` control how much the triangle colors may deviate from their original color. This can be controlled along all four axes of the HSLA color representation.
9596

97+
The option `diagonals` controls which diagonals of the squares of the grid are used:
98+
- `'nw-se'` draws the diagonals from the top left corners to the bottom right corners (North-West - South-East)
99+
- `'ne-sw'` draws the diagonals from the top right corners to the bottom left corners (North-East - South-West)
100+
- `'alternating'` draws diagonals alternating, so that no two neighboring squares have the same diagonal
101+
- `'random'` draws diagonals randomly
96102

97103
For example:
98104

@@ -106,6 +112,7 @@ const options = {
106112
lightness: 0.1,
107113
alpha: 0
108114
},
115+
diagonals: 'nw-se',
109116
...
110117
}
111118
```
@@ -264,6 +271,7 @@ let options = {
264271
lightness: 0.1,
265272
alpha: 0
266273
},
274+
diagonals: 'nw-se',
267275
coloring: {
268276
mode: 'linearGradient',
269277
start: {
@@ -326,4 +334,4 @@ console.log(myNewSvgCode)
326334

327335
Triangle Mosaic is [licensed under MIT](./LICENSE).
328336

329-
Whatever you create with the library or web-based tool is yours and you may license it in any way you see fit.
337+
The images you create with the library or web-based tool are yours and you may license them in any way you see fit.

changelog.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change log
22

3+
## 1.1.0
4+
5+
Bugfix: Gradients do not fail anymore if start and end point have the same x coordinates.
6+
7+
Bugfix: Hue fuzz/variance can now correctly cross the 0-360° mark.
8+
9+
New feature: Introduced `diagonal` option.
10+
11+
312
## 1.0.1
413

514
Got rid of optional chaining operator as it was causing issues.

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "triangle-mosaic",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Generate colorful triangle-based SVG patterns (like this point_down) with ease.",
55
"main": "./triangle-mosaic/triangle-mosaic.js",
66
"repository": {

triangle-mosaic-demo/package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

triangle-mosaic-demo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react-scripts": "3.4.3",
1818
"stylelint": "^13.6.1",
1919
"stylelint-config-standard": "^20.0.0",
20-
"triangle-mosaic": "^1.0.1"
20+
"triangle-mosaic": "^1.1.0"
2121
},
2222
"scripts": {
2323
"start": "react-scripts start",

triangle-mosaic-demo/src/components/app/app.css

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727
#sidebar > footer {
2828
text-align: center;
29+
margin-bottom: 2rem;
2930
}
3031

3132
#sidebar > footer > .byLine {
32-
font-size: 1.1rem;
33+
margin-top: 1rem;
34+
font-size: 0.8rem;
3335
}
3436

3537
#sidebar > footer a {
@@ -39,6 +41,11 @@
3941
text-decoration: none;
4042
}
4143

44+
#sidebar > footer > .byLine a {
45+
padding: 0;
46+
font-size: 0.8rem;
47+
}
48+
4249
#sidebar > footer a:hover,
4350
#sidebar > footer a:active {
4451
text-decoration: underline;

triangle-mosaic-demo/src/components/app/app.jsx

+13-10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const App = () => {
4444
<Variance
4545
shapeFuzz={state.shapeFuzz}
4646
colorFuzz={state.colorFuzz}
47+
diagonals={state.diagonals}
4748
dispatch={dispatch}
4849
/>
4950
<ColoringPresets
@@ -60,36 +61,38 @@ const App = () => {
6061
/>
6162
</div>
6263
<footer>
63-
<div className='byLine'>
64+
<div>
6465
<a
65-
href='https://github.com/bence-toth'
66+
href='https://github.com/bence-toth/triangle-mosaic#readme'
6667
target='_blank'
6768
rel='noopener noreferrer'
6869
>
69-
by Bence A. Tóth
70+
About
7071
</a>
71-
</div>
72-
<div>
7372
<a
74-
href='https://github.com/bence-toth/triangle-mosaic#readme'
73+
href='https://github.com/bence-toth/triangle-mosaic/issues'
7574
target='_blank'
7675
rel='noopener noreferrer'
7776
>
78-
About
77+
Report a bug
7978
</a>
8079
<a
8180
href='https://github.com/bence-toth/triangle-mosaic#license'
8281
target='_blank'
8382
rel='noopener noreferrer'
8483
>
85-
License
84+
License (MIT)
8685
</a>
86+
</div>
87+
<div className='byLine'>
88+
made with ❤ by
89+
{' '}
8790
<a
88-
href='https://github.com/bence-toth/triangle-mosaic/issues'
91+
href='https://github.com/bence-toth'
8992
target='_blank'
9093
rel='noopener noreferrer'
9194
>
92-
Report a bug
95+
Bence A. Tóth
9396
</a>
9497
</div>
9598
</footer>

triangle-mosaic-demo/src/components/app/app.state.js

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const initialState = {
3232
lightness: 0.1,
3333
alpha: 0
3434
},
35+
diagonals: 'nw-se',
3536
coloringMode: 'single',
3637
coloringSingle: {
3738
color: '#ffc107'
@@ -107,6 +108,7 @@ const actions = {
107108
updateSaturationFuzz: 'updateSaturationFuzz',
108109
updateLightnessFuzz: 'updateLightnessFuzz',
109110
updateAlphaFuzz: 'updateAlphaFuzz',
111+
updateDiagonals: 'updateDiagonals',
110112
updateColoringMode: 'updateColoringMode',
111113
updateSingleColor: 'updateSingleColor',
112114
addSpot: 'addSpot',
@@ -185,6 +187,11 @@ const reducer = (state, action) => {
185187
alpha: action.alphaFuzz
186188
}
187189
}
190+
case actions.updateDiagonals:
191+
return {
192+
...state,
193+
diagonals: action.diagonals
194+
}
188195
case actions.updateColoringMode:
189196
return {
190197
...state,

triangle-mosaic-demo/src/components/app/app.utility.js

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const getConfigFromState = ({
3131
yResolution,
3232
shapeFuzz,
3333
colorFuzz,
34+
diagonals,
3435
coloringMode,
3536
coloringSingle,
3637
coloringGradient,
@@ -45,6 +46,7 @@ const getConfigFromState = ({
4546
}),
4647
shapeFuzz,
4748
colorFuzz,
49+
diagonals,
4850
coloring: {
4951
mode: coloringMode,
5052
...((coloringMode === 'single') && coloringSingle),

triangle-mosaic-demo/src/components/variance/variance.jsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable sonarjs/no-identical-functions */
22
import React from 'react'
3-
import {func, number, object} from 'prop-types'
3+
import {func, number, object, oneOf} from 'prop-types'
44

55
import {actions} from '../app/app.state'
66

77
const Variance = ({
88
shapeFuzz,
99
colorFuzz,
10+
diagonals,
1011
dispatch
1112
}) => (
1213
<fieldset>
@@ -106,11 +107,29 @@ const Variance = ({
106107
step={0.01}
107108
/>
108109
</div>
110+
<div className='formField'>
111+
<label htmlFor='form-diagonals'>Diagonals</label>
112+
{/* eslint-disable-next-line jsx-a11y/no-onchange */}
113+
<select
114+
onChange={({target: {value}}) => dispatch({
115+
type: actions.updateDiagonals,
116+
diagonals: value
117+
})}
118+
value={diagonals}
119+
id='form-diagonals'
120+
>
121+
<option value='nw-se'>North-West - South-East</option>
122+
<option value='ne-sw'>North-East - South-West</option>
123+
<option value='alternating'>Alternating</option>
124+
<option value='random'>Random</option>
125+
</select>
126+
</div>
109127
</fieldset>
110128
)
111129

112130
Variance.propTypes = {
113131
shapeFuzz: number,
132+
diagonals: oneOf(['nw-se', 'ne-sw', 'alternating', 'random']),
114133
// eslint-disable-next-line react/forbid-prop-types
115134
colorFuzz: object,
116135
dispatch: func

0 commit comments

Comments
 (0)