)
Variance.propTypes = {
shapeFuzz: number,
+ diagonals: oneOf(['nw-se', 'ne-sw', 'alternating', 'random']),
// eslint-disable-next-line react/forbid-prop-types
colorFuzz: object,
dispatch: func
From cae243e7868f37254b5c82515a5158c839d59eaf Mon Sep 17 00:00:00 2001
From: "Bence A. Toth" <5611525+bence-toth@users.noreply.github.com>
Date: Thu, 20 Aug 2020 22:58:22 +0200
Subject: [PATCH 06/12] Applied library updates to actual source file
---
triangle-mosaic/triangle-mosaic.js | 96 ++++++++++++++++++++++++------
1 file changed, 77 insertions(+), 19 deletions(-)
diff --git a/triangle-mosaic/triangle-mosaic.js b/triangle-mosaic/triangle-mosaic.js
index 120c2cc..113abfc 100644
--- a/triangle-mosaic/triangle-mosaic.js
+++ b/triangle-mosaic/triangle-mosaic.js
@@ -373,6 +373,7 @@ const getRandomTriangleColorDeviation = () => ({
const getRandomGridPointOptions = () => ({
direction: Math.random() * Math.PI * 2,
factor: Math.random(),
+ diagonal: Math.round(Math.random()),
topTriangleColorDeviation: getRandomTriangleColorDeviation(),
bottomTriangleColorDeviation: getRandomTriangleColorDeviation()
})
@@ -409,6 +410,7 @@ const getTriangles = ({
shapeFuzz,
colorFuzz,
coloring,
+ diagonals,
width,
height
}) => {
@@ -443,10 +445,12 @@ const getTriangles = ({
}
const points = [
- // 0----1
- // | / |
- // | / |
- // 2----3
+ //
+ // 0----1 0----1
+ // | / | or | \ |
+ // | / | | \ |
+ // 2----3 2----3
+ //
grid[rowCounter][columnCounter],
grid[rowCounter][columnCounter + 1],
grid[rowCounter + 1][columnCounter],
@@ -463,35 +467,82 @@ const getTriangles = ({
)
})).map(movePoint)
+ const {
+ topTriangleColorDeviation,
+ bottomTriangleColorDeviation,
+ diagonal: pointDiagonal
+ } = points[0]
+
+ const diagonal = (() => {
+ if (diagonals === 'nw-se') {
+ return 0
+ }
+ if (diagonals === 'ne-sw') {
+ return 1
+ }
+ if (diagonals === 'alternating') {
+ return (
+ (
+ ((rowCounter % 2) === 0) && ((columnCounter % 2) === 1)
+ || ((rowCounter % 2) === 1) && ((columnCounter % 2) === 0)
+ )
+ ? 0
+ : 1
+ )
+ }
+ if (diagonals === 'random') {
+ return pointDiagonal
+ }
+ return 0
+ })()
+
const topTriangle = {
// Top triangle
//
- // 0----1
- // | /
- // | /
- // 2
- edges: [points[0], points[1], points[2]],
+ // 0----1 0----1
+ // | / or \ |
+ // | / \ |
+ // 2 3
+ //
+ edges: (
+ (diagonal === 0)
+ ? [points[0], points[1], points[2]]
+ : [points[0], points[1], points[3]]
+ ),
color: getRgbaColor(getTriangleColor({
- triangle: [points[0], points[1], points[2]],
+ triangle: (
+ (diagonal === 0)
+ ? [points[0], points[1], points[2]]
+ : [points[0], points[1], points[3]]
+ ),
coloring,
colorFuzz,
- colorDeviation: points[0].topTriangleColorDeviation
+ colorDeviation: topTriangleColorDeviation
}))
}
const bottomTriangle = {
// Bottom triangle
//
- // 1
- // / |
- // / |
- // 2----3
- edges: [points[1], points[2], points[3]],
+ // 1 0
+ // / | or | \
+ // / | | \
+ // 2----3 2----3
+ //
+ edges: (
+ (diagonal === 0)
+ ? [points[1], points[3], points[2]]
+ : [points[0], points[3], points[2]]
+ ),
color: getRgbaColor(getTriangleColor({
- triangle: [points[1], points[2], points[3]],
+ triangle: (
+ (diagonal === 0)
+ ? [points[1], points[3], points[2]]
+ : [points[0], points[3], points[2]]
+ ),
coloring,
colorFuzz,
- colorDeviation: points[0].bottomTriangleColorDeviation
+ colorDeviation: bottomTriangleColorDeviation
}))
}
@@ -518,6 +569,7 @@ class TriangleMosaic {
lightness: 0.1,
alpha: 0
},
+ diagonals = 'ne-sw',
coloring = {
mode: 'spots',
spots: [
@@ -545,6 +597,7 @@ class TriangleMosaic {
this.yResolution = yResolution
this.shapeFuzz = shapeFuzz
this.colorFuzz = colorFuzz
+ this.diagonals = diagonals
this.coloring = coloring
this.grid = getGrid({
width,
@@ -565,6 +618,7 @@ class TriangleMosaic {
grid: this.grid,
shapeFuzz: this.shapeFuzz * maxVentureDistance,
colorFuzz: this.colorFuzz,
+ diagonals: this.diagonals,
coloring: this.coloring,
width: this.width,
height: this.height
@@ -582,8 +636,9 @@ class TriangleMosaic {
coloring,
width,
height,
+ diagonals,
xResolution,
- yResolution
+ yResolution,
} = {}) {
if (shapeFuzz !== undefined) {
this.shapeFuzz = shapeFuzz
@@ -609,6 +664,9 @@ class TriangleMosaic {
if (height !== undefined) {
this.height = height
}
+ if (diagonals !== undefined) {
+ this.diagonals = diagonals
+ }
if (xResolution !== undefined) {
this.xResolution = xResolution
}
From 067fb3524adacda36ae8ae3d148f6491bafbfad0 Mon Sep 17 00:00:00 2001
From: "Bence A. Toth" <5611525+bence-toth@users.noreply.github.com>
Date: Thu, 20 Aug 2020 23:04:55 +0200
Subject: [PATCH 07/12] Updated change log
---
changelog.md | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/changelog.md b/changelog.md
index 9aa180b..a9fcca1 100644
--- a/changelog.md
+++ b/changelog.md
@@ -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.
From 5e24d971fa7f296c10777b174629e50bb53cc4f4 Mon Sep 17 00:00:00 2001
From: "Bence A. Toth" <5611525+bence-toth@users.noreply.github.com>
Date: Thu, 20 Aug 2020 23:12:29 +0200
Subject: [PATCH 08/12] Updated readme with diagonals
---
README.md | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index e57ac38..0d32824 100644
--- a/README.md
+++ b/README.md
@@ -79,13 +79,14 @@ 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.
@@ -93,6 +94,11 @@ The option `shapeFuzz` controls how far the grid points may venture from their o
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:
@@ -106,6 +112,7 @@ const options = {
lightness: 0.1,
alpha: 0
},
+ diagonals: 'nw-se',
...
}
```
@@ -264,6 +271,7 @@ let options = {
lightness: 0.1,
alpha: 0
},
+ diagonals: 'nw-se',
coloring: {
mode: 'linearGradient',
start: {
@@ -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.
From 4503a05ea3b2bffea3bbf8ab8d29589aeb6d71bf Mon Sep 17 00:00:00 2001
From: "Bence A. Toth" <5611525+bence-toth@users.noreply.github.com>
Date: Thu, 20 Aug 2020 23:12:54 +0200
Subject: [PATCH 09/12] 1.1.0
---
package-lock.json | 2 +-
package.json | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index f77730d..a38f82d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,5 +1,5 @@
{
"name": "triangle-mosaic",
- "version": "1.0.1",
+ "version": "1.1.0",
"lockfileVersion": 1
}
diff --git a/package.json b/package.json
index 804ab51..8d3911a 100644
--- a/package.json
+++ b/package.json
@@ -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": {
From e0a62d63f21f2bba152a16661a46c1c5229a37a1 Mon Sep 17 00:00:00 2001
From: "Bence A. Toth" <5611525+bence-toth@users.noreply.github.com>
Date: Thu, 20 Aug 2020 23:24:22 +0200
Subject: [PATCH 10/12] Updated triangle-mosaic on demo page
---
triangle-mosaic-demo/package-lock.json | 6 +++---
triangle-mosaic-demo/package.json | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/triangle-mosaic-demo/package-lock.json b/triangle-mosaic-demo/package-lock.json
index 1296ac1..36b9179 100644
--- a/triangle-mosaic-demo/package-lock.json
+++ b/triangle-mosaic-demo/package-lock.json
@@ -17449,9 +17449,9 @@
}
},
"triangle-mosaic": {
- "version": "1.0.1",
- "resolved": "https://registry.npmjs.org/triangle-mosaic/-/triangle-mosaic-1.0.1.tgz",
- "integrity": "sha512-J6l90+MV4BeKrELc3EEepcANo88m6pQP24tZSXSt2+uvOgqRItE1o20hS/c1qFmVVvUqHRZm7FbaBemlzKR6VA=="
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/triangle-mosaic/-/triangle-mosaic-1.1.0.tgz",
+ "integrity": "sha512-O9nWsawT73rARaPAshldRTeCG73WOdEXUx8dvU3wEDa+hD/3LDmXzntigNNyfYs0VK9uOPojoDyF0Vnz4hqCDQ=="
},
"trim": {
"version": "0.0.1",
diff --git a/triangle-mosaic-demo/package.json b/triangle-mosaic-demo/package.json
index 723f982..0b4f076 100644
--- a/triangle-mosaic-demo/package.json
+++ b/triangle-mosaic-demo/package.json
@@ -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",
From 0cbdb089fdbc1d21a167882aabfb871c4b481e9d Mon Sep 17 00:00:00 2001
From: "Bence A. Toth" <5611525+bence-toth@users.noreply.github.com>
Date: Thu, 20 Aug 2020 23:26:41 +0200
Subject: [PATCH 11/12] Importing library from npm package
---
.../src/components/app/app.jsx | 2 +-
.../src/components/app/triangleMosaic.js | 688 ------------------
2 files changed, 1 insertion(+), 689 deletions(-)
delete mode 100644 triangle-mosaic-demo/src/components/app/triangleMosaic.js
diff --git a/triangle-mosaic-demo/src/components/app/app.jsx b/triangle-mosaic-demo/src/components/app/app.jsx
index 142d2cd..0f2b0eb 100644
--- a/triangle-mosaic-demo/src/components/app/app.jsx
+++ b/triangle-mosaic-demo/src/components/app/app.jsx
@@ -1,4 +1,5 @@
import React, {useEffect, useReducer, useRef, useState} from 'react'
+import TriangleMosaic from 'triangle-mosaic'
import Coloring from '../coloring/coloring'
import ColoringPresets from '../coloringPresets/coloringPresets'
@@ -7,7 +8,6 @@ import Variance from '../variance/variance'
import {useDebounce} from './app.hooks'
import {initialState, reducer} from './app.state'
import {downloadSvg, getConfigFromState} from './app.utility'
-import TriangleMosaic from './triangleMosaic'
import './app.css'
diff --git a/triangle-mosaic-demo/src/components/app/triangleMosaic.js b/triangle-mosaic-demo/src/components/app/triangleMosaic.js
deleted file mode 100644
index 113abfc..0000000
--- a/triangle-mosaic-demo/src/components/app/triangleMosaic.js
+++ /dev/null
@@ -1,688 +0,0 @@
-// ----------------------------------------------------------------------------
-// Render
-
-const renderSvg = ({
- width,
- height,
- children
-} = {}) => `
-