mirror of
https://github.com/danbulant/console256
synced 2026-05-19 03:58:36 +00:00
implement colors
This commit is contained in:
parent
ee65374c78
commit
f29d28fec3
4 changed files with 60 additions and 3 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
package-lock.json
|
||||
node_modules
|
||||
45
index.js
45
index.js
|
|
@ -1,3 +1,44 @@
|
|||
const readline = require("readline");
|
||||
const render = require("./src/render");
|
||||
|
||||
const WIDTH = process.stdout.columns
|
||||
const HEIGHT = process.stdout.rows;
|
||||
const arrAvg = arr => arr.reduce((a,b) => a + b, 0) / arr.length;
|
||||
const MAX_COLORS = 360;
|
||||
|
||||
const keepAlive = new readline.Interface({
|
||||
input: process.stdin,
|
||||
output: process.stdou
|
||||
});
|
||||
|
||||
const WIDTH = process.stdout.columns;
|
||||
const HEIGHT = process.stdout.rows;
|
||||
|
||||
const view = [];
|
||||
|
||||
for(var row = 0; row < HEIGHT; row++){
|
||||
view[row] = [];
|
||||
|
||||
for(var column = 0; column < WIDTH; column++){
|
||||
const val = arrAvg([(row / HEIGHT) * MAX_COLORS, (column / WIDTH) * MAX_COLORS]);
|
||||
view[row][column] = {0: val, 1: " "};
|
||||
}
|
||||
}
|
||||
|
||||
view[0][0] = {0: 15, 1: " "};
|
||||
view[HEIGHT - 1][WIDTH - 1] = {0: 15, 1: " "};
|
||||
|
||||
render(view);
|
||||
|
||||
var counter = 0;
|
||||
setInterval(() => {
|
||||
for(var row = 0; row < HEIGHT; row++){
|
||||
for(var column = 0; column < WIDTH; column++){
|
||||
const val = arrAvg([(row / HEIGHT) * MAX_COLORS - counter, (column / WIDTH) * MAX_COLORS - counter]) + counter;
|
||||
view[row][column] = {0: val, 1: " "};
|
||||
}
|
||||
}
|
||||
|
||||
render(view);
|
||||
counter++;
|
||||
|
||||
if(counter > MAX_COLORS) counter = 0;
|
||||
}, 300);
|
||||
|
|
@ -8,5 +8,8 @@
|
|||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"chalk": "^3.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
src/render.js
Normal file
11
src/render.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
const chalk = require("chalk");
|
||||
|
||||
module.exports = (array)=>{
|
||||
console.clear();
|
||||
|
||||
for(var row of array){
|
||||
for(var column of row){
|
||||
process.stdout.write(chalk.bgHsl(column[0], 50, 50)(column[1]))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue