Skip to content

Commit

Permalink
Merge pull request #53 from bence-toth/diagonal-variance
Browse files Browse the repository at this point in the history
Introduced diagonal option
  • Loading branch information
bence-toth authored Aug 20, 2020
2 parents ecb2c99 + b8be301 commit 3f5b3f0
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 45 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,26 @@ The options `xResolution` and `yResolution` are the only options which cannot be

### Variance

| Member name | Description |
|------------------------|----------------------------------------------------|
| `shapeFuzz` | Variance factor of grid points (0-1) |
| `colorFuzz.hue` | Variance factor of triangle color hue (0-1) |
| `colorFuzz.saturation` | Variance factor of triangle color saturation (0-1) |
| `colorFuzz.lightness` | Variance factor of triangle color lightness (0-1) |
| `colorFuzz.alpha` | Variance factor of triangle color alpha (0-1) |
| Member name | Description |
|------------------------|-------------------------------------------------------------|
| `shapeFuzz` | Variance factor of grid points (0-1) |
| `colorFuzz.hue` | Variance factor of triangle color hue (0-1) |
| `colorFuzz.saturation` | Variance factor of triangle color saturation (0-1) |
| `colorFuzz.lightness` | Variance factor of triangle color lightness (0-1) |
| `colorFuzz.alpha` | Variance factor of triangle color alpha (0-1) |
| `diagonals` | Either `'nw-se'`, `'ne-sw'`, `'alternating'`, or `'random'` |

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

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

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.

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

For example:

Expand All @@ -106,6 +112,7 @@ const options = {
lightness: 0.1,
alpha: 0
},
diagonals: 'nw-se',
...
}
```
Expand Down Expand Up @@ -264,6 +271,7 @@ let options = {
lightness: 0.1,
alpha: 0
},
diagonals: 'nw-se',
coloring: {
mode: 'linearGradient',
start: {
Expand Down Expand Up @@ -326,4 +334,4 @@ console.log(myNewSvgCode)

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

Whatever you create with the library or web-based tool is yours and you may license it in any way you see fit.
The images you create with the library or web-based tool are yours and you may license them in any way you see fit.
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change log

## 1.1.0

Bugfix: Gradients do not fail anymore if start and end point have the same x coordinates.

Bugfix: Hue fuzz/variance can now correctly cross the 0-360° mark.

New feature: Introduced `diagonal` option.


## 1.0.1

Got rid of optional chaining operator as it was causing issues.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "triangle-mosaic",
"version": "1.0.1",
"version": "1.1.0",
"description": "Generate colorful triangle-based SVG patterns (like this point_down) with ease.",
"main": "./triangle-mosaic/triangle-mosaic.js",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions triangle-mosaic-demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion triangle-mosaic-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react-scripts": "3.4.3",
"stylelint": "^13.6.1",
"stylelint-config-standard": "^20.0.0",
"triangle-mosaic": "^1.0.1"
"triangle-mosaic": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
9 changes: 8 additions & 1 deletion triangle-mosaic-demo/src/components/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@

#sidebar > footer {
text-align: center;
margin-bottom: 2rem;
}

#sidebar > footer > .byLine {
font-size: 1.1rem;
margin-top: 1rem;
font-size: 0.8rem;
}

#sidebar > footer a {
Expand All @@ -39,6 +41,11 @@
text-decoration: none;
}

#sidebar > footer > .byLine a {
padding: 0;
font-size: 0.8rem;
}

#sidebar > footer a:hover,
#sidebar > footer a:active {
text-decoration: underline;
Expand Down
23 changes: 13 additions & 10 deletions triangle-mosaic-demo/src/components/app/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const App = () => {
<Variance
shapeFuzz={state.shapeFuzz}
colorFuzz={state.colorFuzz}
diagonals={state.diagonals}
dispatch={dispatch}
/>
<ColoringPresets
Expand All @@ -60,36 +61,38 @@ const App = () => {
/>
</div>
<footer>
<div className='byLine'>
<div>
<a
href='https://github.com/bence-toth'
href='https://github.com/bence-toth/triangle-mosaic#readme'
target='_blank'
rel='noopener noreferrer'
>
by Bence A. Tóth
About
</a>
</div>
<div>
<a
href='https://github.com/bence-toth/triangle-mosaic#readme'
href='https://github.com/bence-toth/triangle-mosaic/issues'
target='_blank'
rel='noopener noreferrer'
>
About
Report a bug
</a>
<a
href='https://github.com/bence-toth/triangle-mosaic#license'
target='_blank'
rel='noopener noreferrer'
>
License
License (MIT)
</a>
</div>
<div className='byLine'>
made with ❤ by
{' '}
<a
href='https://github.com/bence-toth/triangle-mosaic/issues'
href='https://github.com/bence-toth'
target='_blank'
rel='noopener noreferrer'
>
Report a bug
Bence A. Tóth
</a>
</div>
</footer>
Expand Down
7 changes: 7 additions & 0 deletions triangle-mosaic-demo/src/components/app/app.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const initialState = {
lightness: 0.1,
alpha: 0
},
diagonals: 'nw-se',
coloringMode: 'single',
coloringSingle: {
color: '#ffc107'
Expand Down Expand Up @@ -107,6 +108,7 @@ const actions = {
updateSaturationFuzz: 'updateSaturationFuzz',
updateLightnessFuzz: 'updateLightnessFuzz',
updateAlphaFuzz: 'updateAlphaFuzz',
updateDiagonals: 'updateDiagonals',
updateColoringMode: 'updateColoringMode',
updateSingleColor: 'updateSingleColor',
addSpot: 'addSpot',
Expand Down Expand Up @@ -185,6 +187,11 @@ const reducer = (state, action) => {
alpha: action.alphaFuzz
}
}
case actions.updateDiagonals:
return {
...state,
diagonals: action.diagonals
}
case actions.updateColoringMode:
return {
...state,
Expand Down
2 changes: 2 additions & 0 deletions triangle-mosaic-demo/src/components/app/app.utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const getConfigFromState = ({
yResolution,
shapeFuzz,
colorFuzz,
diagonals,
coloringMode,
coloringSingle,
coloringGradient,
Expand All @@ -45,6 +46,7 @@ const getConfigFromState = ({
}),
shapeFuzz,
colorFuzz,
diagonals,
coloring: {
mode: coloringMode,
...((coloringMode === 'single') && coloringSingle),
Expand Down
21 changes: 20 additions & 1 deletion triangle-mosaic-demo/src/components/variance/variance.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable sonarjs/no-identical-functions */
import React from 'react'
import {func, number, object} from 'prop-types'
import {func, number, object, oneOf} from 'prop-types'

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

const Variance = ({
shapeFuzz,
colorFuzz,
diagonals,
dispatch
}) => (
<fieldset>
Expand Down Expand Up @@ -106,11 +107,29 @@ const Variance = ({
step={0.01}
/>
</div>
<div className='formField'>
<label htmlFor='form-diagonals'>Diagonals</label>
{/* eslint-disable-next-line jsx-a11y/no-onchange */}
<select
onChange={({target: {value}}) => dispatch({
type: actions.updateDiagonals,
diagonals: value
})}
value={diagonals}
id='form-diagonals'
>
<option value='nw-se'>North-West - South-East</option>
<option value='ne-sw'>North-East - South-West</option>
<option value='alternating'>Alternating</option>
<option value='random'>Random</option>
</select>
</div>
</fieldset>
)

Variance.propTypes = {
shapeFuzz: number,
diagonals: oneOf(['nw-se', 'ne-sw', 'alternating', 'random']),
// eslint-disable-next-line react/forbid-prop-types
colorFuzz: object,
dispatch: func
Expand Down
Loading

0 comments on commit 3f5b3f0

Please sign in to comment.