Skip to content

Commit

Permalink
Added reroll for duplicate colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kangaroux committed Jan 8, 2018
1 parent 74b19dc commit 7e031f9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions index.js
Expand Up @@ -14,13 +14,26 @@ fs.readdir('./frames').then(data => {
});

const colorsOptions = ['red', 'yellow', 'green', 'blue', 'magenta', 'cyan', 'white'];
const numColors = colorsOptions.length;

const streamer = stream => {
let index = 0;
let lastColor = -1;
let newColor = 0;
return setInterval(() => {
if (index >= frames.length) index = 0; stream.push('\033c');
const c = colorsOptions[Math.floor(Math.random() * colorsOptions.length)];
stream.push(colors[c](frames[index]));

newColor = Math.floor(Math.random() * numColors);

// Reroll for a new color if it was the same as last frame
if(newColor == lastColor) {
newColor += (1 + Math.floor(Math.random() * (numColors - 1)));
newColor %= numColors;
}

lastColor = newColor;
stream.push(colors[colorsOptions[newColor]](frames[index]));

index++;
}, 70);
}
Expand Down

0 comments on commit 7e031f9

Please sign in to comment.