Skip to content

Commit

Permalink
make order of frames deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
twhitbeck committed Apr 5, 2018
1 parent 6390d3c commit c8d9d30
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const fs = require('mz/fs');
const path = require('path');
const http = require('http');
const {Readable} = require('stream');
const colors = require('colors/safe');

const frames = [];

// Setup frames in memory
fs.readdir('./frames').then(data => {
data.forEach(async frame => {
const f = await fs.readFile(`./frames/${frame}`);
frames.push(f.toString());
})
let frames;

(async () => {
const framesPath = 'frames';
const files = await fs.readdir(framesPath);

frames = await Promise.all(files.map(async (file) => {
const frame = await fs.readFile(path.join(framesPath, file));
return frame.toString();
}));
})().catch((err) => {
console.log('Error loading frames');
console.log(err);
});

const colorsOptions = ['red', 'yellow', 'green', 'blue', 'magenta', 'cyan', 'white'];
Expand All @@ -21,7 +28,10 @@ const streamer = stream => {
let lastColor = -1;
let newColor = 0;
return setInterval(() => {
if (index >= frames.length) index = 0; stream.push('\033[2J\033[H');
if (index >= frames.length) index = 0;

// clear the screen
stream.push('\033[2J\033[H');

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

Expand Down

0 comments on commit c8d9d30

Please sign in to comment.