-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (52 loc) · 1.77 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
49
50
51
52
53
54
55
56
57
58
import { argv } from 'node:process';
import chalk from 'chalk';
import convert from 'color-convert';
let saturation = 0;
let luminosity = 0;
let hexColor = '';
let hue = '';
const userHue = argv[2];
const userLum = argv[3];
if (argv.length < 3) {
hexColor =
'#' +
Math.floor(Math.random() * 16777215)
.toString(16)
.padStart(6, '0');
} else if (argv.length >= 3) {
saturation = Math.ceil(Math.random() * (100 - 50) + 50);
luminosity = Math.ceil(Math.random() * (70 - 20) + 20);
if (userHue === 'red') {
hue = Math.ceil(Math.random() * (10 - 0) + 0);
hexColor = '#' + convert.hsl.hex(hue, saturation, luminosity);
} else if (userHue === 'green') {
hue = Math.ceil(Math.random() * (130 - 90) + 90);
hexColor = '#' + convert.hsl.hex(hue, saturation, luminosity);
} else if (userHue === 'blue') {
hue = Math.ceil(Math.random() * (250 - 220) + 220);
hexColor = '#' + convert.hsl.hex(hue, saturation, luminosity);
}
}
if (argv.length === 4) {
if (userLum === 'light') {
saturation = Math.ceil(Math.random() * (100 - 40) + 40);
luminosity = Math.ceil(Math.random() * (70 - 50) + 50);
hexColor = '#' + convert.hsl.hex(hue, saturation, luminosity);
} else if (userLum === 'dark') {
saturation = Math.ceil(Math.random() * (100 - 40) + 40);
luminosity = Math.ceil(Math.random() * (25 - 9) + 9);
hexColor = '#' + convert.hsl.hex(hue, saturation, luminosity);
}
}
const generateShape = `
###############################
###############################
###############################
##### #####
##### ${hexColor} #####
##### #####
###############################
###############################
###############################
`;
console.log(chalk.hex(hexColor)`${generateShape}`);