-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
108 lines (103 loc) · 2.71 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// let input = console.log(process.argv);
const randomColor = require('randomcolor'); // import the script
const prompt = require('prompt-sync')();
const chalk = require('chalk');
// console.log(chalk.blue('Hello world!'));
function createArray(arrEx, length, width) {
for (let i = 0; i < width; i++) {
arrEx[i] = [];
for (let x = 0; x < length; x++) {
arrEx[i][x] = '#';
}
}
}
//
function arrReplace(arr, length, width) {
const middleL = Math.floor(length / 2);
const middleW = Math.floor(width / 2);
for (let i = middleW - 1; i <= middleW + 1; i++) {
for (let x = middleL - 10; x <= middleL + 10; x++) {
arr[i][x] = ' ';
}
}
}
function hexArr(arr, length, width, str) {
const middleL = Math.floor(length / 2);
const middleW = Math.floor(width / 2);
const text = str;
let charC = 0;
for (let i = middleW; i < middleW + 1; i++) {
for (let x = middleL - 3; x < middleL + 3; x++) {
arr[i][x] = text.charAt(charC);
charC++;
}
}
}
//
function printArr(arr, length, width, hex) {
const useColor = hex;
hexArr(arr, length, width, useColor);
for (let i = 0; i < width; i++) {
console.log();
for (let x = 0; x < length; x++) {
process.stdout.write(chalk.hex(useColor)(arr[i][x]));
}
}
console.log();
}
//
//
function print() {
let bool = true;
while (bool) {
const input1 = prompt('input: ');
const inp = input1.split(' ');
if (input1 === '') {
const arr = [];
createArray(arr, 31, 9);
arrReplace(arr, 31, 9);
printArr(arr, 31, 9, randomColor());
} else if (inp.length === 1 && inp[0] === 'ask') {
console.log('Enter color and luminosity!');
} else if (inp.length === 1 && inp[0] === 'random') {
const arr = [];
createArray(arr, 31, 9);
arrReplace(arr, 31, 9);
printArr(arr, 31, 9, randomColor());
} else if (inp.length === 1 && inp[0] === 'quit') {
bool = false;
} else if (inp.length === 2) {
const hexcode = randomColor({
luminosity: inp[0],
hue: inp[1],
});
const arr = [];
createArray(arr, 31, 9);
arrReplace(arr, 31, 9);
printArr(arr, 31, 9, hexcode);
} else if (inp.length === 3 && inp[0].includes('x')) {
const leandwi = inp[0].split('x');
const hexcode = randomColor({
luminosity: inp[1],
hue: inp[2],
});
const arr = [];
createArray(arr, leandwi[0], leandwi[1]);
arrReplace(arr, leandwi[0], leandwi[1]);
printArr(arr, leandwi[0], leandwi[1], hexcode);
} else {
console.log('error');
}
console.log();
}
}
//
//
//
//
// main
const arr = [];
createArray(arr, 31, 9);
arrReplace(arr, 31, 9);
printArr(arr, 31, 9, randomColor());
print();