-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstipple-mapper.js
50 lines (39 loc) · 1.03 KB
/
stipple-mapper.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
49
50
'use strict';
import Canvas from 'canvas';
const Image = Canvas.Image;
import fs from 'fs-extra';
import path from 'path';
import colors from 'colors';
import GIFEncoder from 'gifencoder';
import cliProgress from 'cli-progress';
import seedrandom from 'seedrandom';
import * as color_convert from './color-convert.js';
import {writeImage, writeImageSilent, getOutputImage} from './image-loader.js';
const rnd = seedrandom('This is the seed');
export {
map,
}
async function map(settings, mirrors, reflections) {
// shuffle reflections array
for (let i = reflections.length - 1; i > 0; i--) {
const j = Math.floor(rnd() * (i + 1));
[reflections[i], reflections[j]] = [reflections[j], reflections[i]];
}
var mapping = mirrors.map((mirror, i) => {
const aim_position = reflections[i];
return {
mirror: {
x: mirror.x,
y: mirror.y,
},
palette: {
x: aim_position.x,
y: aim_position.y,
}
};
})
const mapping_conf = {
mapping,
}
return mapping_conf;
}