initial commit

This commit is contained in:
2023-04-04 23:18:18 +02:00
commit e86d3f6358
11 changed files with 918 additions and 0 deletions

80
common/characters.js Normal file
View File

@@ -0,0 +1,80 @@
export const charwidth = 5;
export const chars = {
'ÿ': [
[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1]
],
'Ÿ': [
[2,2,2,2,2],
[2,2,2,2,2],
[2,2,2,2,2],
[2,2,2,2,2],
[2,2,2,2,2]
]
};
export const numbers = [[
[1,1,1,1,1],
[1,0,0,0,1],
[1,0,2,0,1],
[1,0,0,0,1],
[1,1,1,1,1]
], [
[2,2,0,1,1],
[0,0,0,0,1],
[2,2,2,0,1],
[0,0,0,0,1],
[2,2,2,0,1]
], [
[1,1,1,1,1],
[0,0,0,0,1],
[1,1,1,1,1],
[1,0,0,0,0],
[1,1,1,1,1]
], [
[1,1,1,1,1],
[0,0,0,0,1],
[0,1,1,1,1],
[0,0,0,0,1],
[1,1,1,1,1]
], [
[1,0,2,0,1],
[1,0,0,0,1],
[1,1,1,1,1],
[0,0,0,0,1],
[2,2,2,0,1]
], [
[1,1,1,1,1],
[1,0,0,0,0],
[1,1,1,1,1],
[0,0,0,0,1],
[1,1,1,1,1]
], [
[1,1,1,1,1],
[1,0,0,0,0],
[1,1,1,1,1],
[1,0,0,0,1],
[1,1,1,1,1]
], [
[1,1,1,1,1],
[0,0,0,0,1],
[2,0,2,0,1],
[2,0,2,0,1],
[2,0,2,0,1]
], [
[1,1,1,1,1],
[1,0,0,0,1],
[1,1,1,1,1],
[1,0,0,0,1],
[1,1,1,1,1]
], [
[1,1,1,1,1],
[1,0,0,0,1],
[1,1,1,1,1],
[0,0,0,0,1],
[1,1,1,1,1]
]];

109
common/colors.js Normal file
View File

@@ -0,0 +1,109 @@
import * as themes from "themes";
import * as fs from "fs";
let defaultColorSet = [
'#666',
'#333'
]
function hslToRgb(h, s, l) {
var r, g, b;
if (s == 0) {
r = g = b = l; // achromatic
} else {
var hue2rgb = (p, q, t) => {
if(t < 0) t += 1;
if(t > 1) t -= 1;
if(t < 1/6) return p + (q - p) * 6 * t;
if(t < 1/2) return q;
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
var p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
}
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
const defaultRanges = [[0,1],[0.2,1],[0.2,0.8]];
var currentColorSet = defaultColorSet;
var colorPosition = [0, 0];
var colorReverse = [false, false];
export function setCurrentColorSet(colorSet) {
currentColorSet = colorSet;
}
function generateColors(hsl, variance, ranges, number) {
let colorArray = [];
for (let i=0; i<number; i++) {
colorArray.push(hslToHex(hsl, variance, ranges));
}
return colorArray;
}
function generateColorSet(colorDef, number) {
let colorSet = new Array([],[]);
for (let i=0; i<2; i++) {
if (typeof colorDef[i+1] === 'string') {
colorSet[i] = colorDef[i+1];
} else {
colorSet[i] = generateColors(colorDef[i+1].hsl, colorDef[i+1].variance, colorDef[i+1].ranges, number);
}
}
return colorSet;
}
export function initColors(colorDef, number) {
currentColorSet = generateColorSet(colorDef, number);
console.log('writing colors file');
fs.writeFileSync("colors.txt", currentColorSet, "cbor");
}
export function pickColor(type) {
let currentColor;
if (typeof currentColorSet[type] === 'string') {
currentColor = currentColorSet[type];
} else {
currentColor = currentColorSet[type][colorPosition[type]];
if (colorPosition[type] == currentColorSet[type].length-1) {
colorReverse[type] = true;
} else if (colorPosition[type] == 0) {
colorReverse[type] = false;
}
if (colorReverse[type]) {
colorPosition[type]--;
} else {
colorPosition[type]++;
}
}
return currentColor;
}
export function hslToHex(hsl, variance, ranges) {
let variance = variance || false;
let ranges = ranges || defaultRanges;
if (variance) {
for(let i=0; i<3; i++) {
hsl[i]+=Math.random()*variance[i]-(variance[i]/2);
if (hsl[i] < ranges[i][0]) {
hsl[i] = ranges[i][0];
} else if (hsl[i] > ranges[i][1]) {
hsl[i] = ranges[i][1];
}
}
}
let rgb = hslToRgb(hsl[0], hsl[1], hsl[2]);
return rgbToHex(rgb[0], rgb[1], rgb[2]);
}

69
common/digits.js Normal file
View File

@@ -0,0 +1,69 @@
import document from "document";
import * as colors from "colors";
import * as characters from "characters";
var starttime, endtime;
export let currentDigits = [-1,-1,-1,-1,-1,-1,-1,-1];
function getSquares(character) {
if (typeof character === 'string') {
return characters.chars[character];
} else {
return characters.numbers[character];
}
}
export function setDigits(digits, forceRedraw) {
for(let i=0; i<digits.length; i++) {
let digit = digits[i];
if (forceRedraw || digit != currentDigits[i]) {
setDigit(i, digit);
currentDigits[i] = digit;
}
}
}
export function setDigit(digit, character) {
/*
starttime = new Date();
console.log('updating digit '+digit+': '+character);
*/
/*
squares.forEach(function(line, lineNum) {
line.forEach(function(square, squareNum) {
let squareElem = digitElem.getElementById(lineNum+'-'+squareNum);
if (square == 0) {
squareElem.style.display = 'none';
} else {
//let localColor = colors.pickColor(square-1);
squareElem.style.display = 'inline';
//squareElem.style.fill = localColor;
squareElem.style.fill = 'red';
}
});
});
*/
let squares = getSquares(character);
let digitElemChildren = document.getElementById('digit'+digit).getElementsByClassName('square');
for (let i = 0; i < digitElemChildren.length; i++) {
let square = squares[Math.floor(i/characters.charwidth)][i%characters.charwidth];
let squareElem = digitElemChildren[i];
if (square == 0) {
if (squareElem.style.display !== 'none') {
squareElem.style.display = 'none';
};
} else {
let localColor = colors.pickColor(square-1);
if (squareElem.style.display !== 'inline') {
squareElem.style.display = 'inline';
};
squareElem.style.fill = localColor;
}
}
/*
endtime = new Date();
console.log('digit updated at '+(endtime-starttime)+' ms');
*/
}

182
common/themes.js Normal file
View File

@@ -0,0 +1,182 @@
export const colors = {
whiteMarble: {
hsl: [0.9,0.0,0.7],
variance: [0.01,0.2,0.2],
ranges: [
[0.8,1],
[0.0,0.05],
[0.65,1]
]
},
blackMarble: {
hsl: [0.9,0.0,0.2],
variance: [0.01,0.2,0.1],
ranges: [
[0.8,1],
[0.0,0.05],
[0.15,0.25]
]
},
clearWater: {
hsl: [0.75,1.0,0.6],
variance: [0.1,0.1,0.05],
ranges: [
[0.6,0.7],
[0.8,1.0],
[0.6,0.7]
]
},
void: {
hsl: [0.8,1,0.2],
variance: [0,0.2,0.1],
ranges: [
[0,1],
[0.5,1],
[0.2,0.4]
]
},
lava: {
hsl: [0.1,1,0.5],
variance: [0.12,0.5,0.5],
ranges: [
[0.02,0.15],
[0.8,1],
[0.5,0.6]
]
},
cloudCover: {
hsl: [0.7,0.6,0.7],
variance: [0.05,0.05,0.2],
ranges: [
[0.7,0.72],
[0.4,0.6],
[0.7,0.9]
]
},
forest: {
hsl: [0.35,0.7,0.4],
variance: [0.35,0.05,0.3],
ranges: [
[0.25,0.35],
[0.7,0.8],
[0.35,0.5]
]
},
ruby: {
hsl: [0,0.8,0.4],
variance: [0.05,0.05,0.2],
ranges: [
[0,0.02],
[0.8,0.9],
[0.35,0.55]
]
},
amethyst: {
hsl: [0.8,0.8,0.5],
variance: [0.05,0.05,0.2],
ranges: [
[0.75,0.8],
[0.8,0.9],
[0.4,0.55]
]
},
spottyIce: {
hsl: [0.6,0.8,0.5],
variance: [0.05,0.05,1],
ranges: [
[0.55,0.6],
[0.8,0.9],
[0.2,0.8]
]
},
frost: {
hsl: [0.6,0.8,0.8],
variance: [0.05,0.05,0.7],
ranges: [
[0.55,0.6],
[0.8,0.9],
[0.8,1]
]
},
mint: {
hsl: [0.3,0.8,0.8],
variance: [0.05,0.05,0.7],
ranges: [
[0.25,0.3],
[0.8,0.9],
[0.8,1]
]
},
citrus: {
hsl: [0.15,0.8,0.8],
variance: [0.05,0.05,0.7],
ranges: [
[0.1,0.15],
[0.8,0.9],
[0.6,0.8]
]
},
salad: {
hsl: [0.2,0.8,0.7],
variance: [0.05,0.05,0.3],
ranges: [
[0.17,0.27],
[0.7,0.9],
[0.5,0.7]
]
},
sand: {
hsl: [0.1,0.5,0.7],
variance: [0.05,0.8,0.6],
ranges: [
[0.08,0.1],
[0.4,0.6],
[0.5,0.7]
]
},
orangeJello: {
hsl: [0.07,1,0.5],
variance: [0.3,0,0.1],
ranges: [
[0.06,0.08],
[1,1],
[0.4,0.55]
]
},
electric: {
hsl: [0.5,1,0.5],
variance: [0.3,0.1,0.1],
ranges: [
[0.4,0.5],
[0.95,1],
[0.45,0.55]
]
},
orchid: {
hsl: [0.8,0.4,0.3],
variance: [0.1,0.05,0.1],
ranges: [
[0.75,0.9],
[0.2,0.4],
[0.4,0.7]
]
},
rose: {
hsl: [1,0.7,0.3],
variance: [0.1,0.05,0.2],
ranges: [
[0.95,1],
[0.7,0.8],
[0.45,0.6]
]
},
peach: {
hsl: [1,0.7,0.7],
variance: [0.1,0.05,0.15],
ranges: [
[0.95,1],
[0.7,0.8],
[0.65,0.75]
]
},
}