-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (38 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const progressBar = require('progress');
const {
defineInnerEdges,
createFile,
SVG,
drawLine,
drawContour
} = require('./lib');
const {
width,
height
} = require('./config');
// numInnerEdges = (width - 1) * height + (height - 1) * width = 2 * width * height - width - height
// Runtime is O( (2 ^ numInnerEdges) * numInnerEdges))
const innerEdges = defineInnerEdges(width, height);
const combinations = Math.pow(2, innerEdges.length);
console.log(`There are ${innerEdges.length} inner edges and ${combinations} combinations`);
const fileBar = new progressBar('creating files [:bar] :percent :elapsed', { total: combinations, width: 30});
const createSvgs = async () => {
for (let svgIndex = 0; svgIndex < combinations; svgIndex++) {
const svg = new SVG();
let parity = 1;
innerEdges.forEach((edge, edgeIndex) => {
if (svgIndex & parity) {
svg.drawLine(edge);
}
parity *= 2;
});
svg.drawContour(width, height);
try {
await createFile(svgIndex, svg.toString());
} catch (err) {
console.log(err);
}
fileBar.tick();
}
}
createSvgs();