Skip to content

Commit

Permalink
POC
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom32i committed Dec 8, 2017
1 parent 1fff632 commit 919baba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/Scarf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}
Expand Down
10 changes: 9 additions & 1 deletion src/pattern/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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('');
}

Expand Down

0 comments on commit 919baba

Please sign in to comment.