From 8847b84947d52b6b4b4c8bd37f8abb9637fa703a Mon Sep 17 00:00:00 2001 From: Thomas Jarrand Date: Fri, 8 Dec 2017 09:19:55 +0100 Subject: [PATCH] POC --- src/Scarf.js | 12 ++++++++---- src/pattern/Generator.js | 10 +++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Scarf.js b/src/Scarf.js index 6ab4e9f..11bc275 100644 --- a/src/Scarf.js +++ b/src/Scarf.js @@ -64,10 +64,14 @@ export default class Scarf extends Component { Array.from(pattern).forEach((value, index) => { const crochet = Scarf.createCrochet(index, y); - if (value === 'v') { - this.white += crochet; - } else { - this.red += crochet; + switch (value) { + case 'v': + this.white += crochet; + break; + case 'x': + break; + default: + this.red += crochet; } }); } diff --git a/src/pattern/Generator.js b/src/pattern/Generator.js index 99953cc..26b9301 100644 --- a/src/pattern/Generator.js +++ b/src/pattern/Generator.js @@ -39,7 +39,7 @@ export default class Generator { * * @return {String} */ - static messUp(line, errors = LINE / 10) { + static messUp(line, errors = LINE / 10, holes = 2) { const messedUp = Array.from(line); for (let i = 0; i < errors; i++) { @@ -48,6 +48,14 @@ export default class Generator { messedUp[index] = messedUp[index] === 'v' ? ' ' : 'v'; } + for (let i = 0; i < errors; i++) { + const index = Math.floor(Math.random() * messedUp.length); + + if (Math.random() < 0.2) { + messedUp[index] = 'x'; + } + } + return messedUp.join(''); }