-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.mjs
More file actions
42 lines (34 loc) · 1.21 KB
/
cli.mjs
File metadata and controls
42 lines (34 loc) · 1.21 KB
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
#!/usr/bin/env node
import parseArgs from 'minimist';
import Trianglify from 'trianglify';
import wallpaper from 'wallpaper';
import fs from 'fs';
(async () => {
const parsedArgs = parseArgs(process.argv.slice(2));
const screenWidth = parsedArgs.width ?? 3840;
const screenHeight = parsedArgs.height ?? 2160;
const variance = parsedArgs.variance ?? Math.random();
const cellSize = parsedArgs.cellSize ?? Math.floor(Math.random() * 200 + 40);
const seed = parsedArgs.seed ?? null;
const colors = parsedArgs.colors?.split(',') ?? 'random';
const pngURI = Trianglify({
width: screenWidth,
height: screenHeight,
cell_size: cellSize,
x_colors: colors,
y_colors: 'match_x',
variance,
seed,
}).png();
const data = pngURI.substr(pngURI.indexOf('base64') + 7);
const buffer = new Buffer.from(data, 'base64');
const wallpaperFileName = 'wallpaper.png';
fs.writeFile(wallpaperFileName, buffer, async () => {
await wallpaper.set(wallpaperFileName);
console.log(
`Wallpaper generated & set with screenWidth: ${screenWidth}, screenHeight: ${screenHeight}, variance: ${variance}, cellSize: ${cellSize}, seed: ${seed} & colors: ${
Array.isArray(colors) ? colors.join(',') : colors
}.`
);
});
})();