Update lcars.app.js with final 0.30 version with more colors and random color functionality

Update lcars.app.js with final 0.30 version with more colors and random color functionality
master
Ronin0000 2023-12-09 16:33:39 -08:00 committed by GitHub
parent d9ec4f354c
commit 482b30dfdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 125 additions and 25 deletions

View File

@ -25,12 +25,27 @@ for (const key in saved_settings) {
//Colors to use //Colors to use
var color_options = ['Green','Orange','Cyan','Purple','Red','Blue','Yellow','White','Purple','Pink','Light Green','Dark Green', 'Brown', 'Turquoise', 'Magenta', 'Gold', 'Silver', 'Violet', 'Teal', 'Maroon', 'Lavender']; var color_options = [
var bg_code = ['#00ff00','#FF9900','#0094FF','#FF00DC','#ff0000','#0000ff','#ffef00','#FFFFFF','#FF00FF','#6C00FF','#99FF00','#556B2F', '#8B4513', '#40E0D0', '#FF00FF', '#FFD700', '#C0C0C0', '#EE82EE', '#008080', '#800000', '#E6E6FA']; 'Green', 'Orange', 'Cyan', 'Purple', 'Red', 'Blue', 'Yellow', 'White',
'Purple', 'Pink', 'Light Green', 'Brown', 'Turquoise', 'Magenta', 'Lime',
let color1 = settings.themeColor3BG; 'Gold', 'Sky Blue', 'Rose', 'Lavender', 'Amber', 'Indigo', 'Teal',
let color2 = settings.themeColor1BG; 'Crimson', 'Maroon', 'Firebrick', 'Dark Red', 'Aqua', 'Emerald', 'Royal Blue',
let color3 = settings.themeColor2BG; 'Sunset Orange', 'Turquoise Blue', 'Hot Pink', 'Goldenrod', 'Deep Sky Blue'
];
var bg_code = [
'#00ff00', '#FF9900', '#0094FF', '#FF00DC', '#ff0000', '#0000ff', '#ffef00', '#FFFFFF',
'#FF00FF', '#6C00FF', '#99FF00', '#8B4513', '#40E0D0', '#FF00FF', '#00FF00', '#FFD700',
'#87CEEB', '#FF007F', '#E6E6FA', '#FFBF00', '#4B0082', '#008080', '#DC143C', '#800000',
'#B22222', '#8B0000', '#00FFFF', '#008000', '#4169E1', '#FF4500', '#40E0D0', '#FF69B4',
'#DAA520', '#00BFFF'
];
let color1;
let color2;
let color3;
let cWhite = "#FFFFFF"; let cWhite = "#FFFFFF";
let cBlack = "#000000"; let cBlack = "#000000";
let cGrey = "#424242"; let cGrey = "#424242";
@ -61,10 +76,105 @@ let convert24to16 = function(input)
return "0x"+RGB565.toString(16); return "0x"+RGB565.toString(16);
}; };
let color1C = convert24to16(color1);//Converting colors to the correct format. //Converting colors to the correct format.
let color2C = convert24to16(color2); /*let color1C;
let color3C = convert24to16(color3); let color2C;
let color3C;
let randomColors = function () {
console.log("called");
if (settings.randomColors) {
do {
color1 = bg_code[Math.floor(Math.random() * bg_code.length)];
color2 = bg_code[Math.floor(Math.random() * bg_code.length)];
color3 = bg_code[Math.floor(Math.random() * bg_code.length)];
} while (color1 === color2 || color2 === color3 || color1 === color3);
console.log("random called");
} else {
color1 = settings.themeColor3BG;
color2 = settings.themeColor1BG;
color3 = settings.themeColor2BG;
}
//Converting colors to the correct format.
color1C = convert24to16(color1);
color2C = convert24to16(color2);
color3C = convert24to16(color3);
};*/
let randomColors = function () {
console.log("called");
if (settings.randomColors) {
do {
color1 = getRandomColor();
color2 = getRandomColor();
color3 = getRandomColor();
} while (!areColorsDistinct(color1, color2, color3));
console.log("random called");
} else {
color1 = settings.themeColor3BG;
color2 = settings.themeColor1BG;
color3 = settings.themeColor2BG;
}
// Converting colors to the correct format.
color1C = convert24to16(color1);
color2C = convert24to16(color2);
color3C = convert24to16(color3);
};
// Function to get a random color from the bg_code array.
let getRandomColor = function () {
return bg_code[Math.floor(Math.random() * bg_code.length)];
};
// Function to check if three colors are distinct enough.
let areColorsDistinct = function (color1, color2, color3) {
return (
color1 !== color2 &&
color2 !== color3 &&
color1 !== color3 &&
hasSufficientContrast(color1, color2) &&
hasSufficientContrast(color2, color3) &&
hasSufficientContrast(color1, color3)
);
};
// Function to calculate contrast between two colors.
let hasSufficientContrast = function (color1, color2) {
const contrastThreshold = 0.10; // Adjust this threshold based on your preference.
// Calculate the luminance values (for simplicity, assuming sRGB color space).
const luminance1 = getLuminance(color1);
const luminance2 = getLuminance(color2);
// Calculate the contrast ratio.
const contrastRatio = (Math.max(luminance1, luminance2) + 0.05) / (Math.min(luminance1, luminance2) + 0.05);
// Check if the contrast ratio meets the threshold.
return contrastRatio >= contrastThreshold;
};
// Function to calculate luminance from a hex color.
let getLuminance = function (hexColor) {
const rgb = hexToRgb(hexColor);
return 0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b;
};
// Function to convert hex color to RGB.
let hexToRgb = function (hex) {
const bigint = parseInt(hex.slice(1), 16);
const r = (bigint >> 16) & 255;
const g = (bigint >> 8) & 255;
const b = bigint & 255;
return { r, g, b };
};
randomColors();//Apply random colors if applied
/* /*
* Requirements and globals * Requirements and globals
*/ */
@ -190,14 +300,6 @@ let queueDraw = function() {
}, timeout - (Date.now() % timeout)); }, timeout - (Date.now() % timeout));
}; };
function randomColors() {
if(settings.randomColors == true){
let color1 = bg_code[Math.floor(Math.random() * bg_code.length)];
let color2 = bg_code[Math.floor(Math.random() * bg_code.length)];
let color3 = bg_code[Math.floor(Math.random() * bg_code.length)];
}
}
/** /**
* This function plots a data row in LCARS style. * This function plots a data row in LCARS style.
* Note: It can be called async and therefore, the text alignment and * Note: It can be called async and therefore, the text alignment and
@ -235,7 +337,7 @@ let drawData = function(key, y, c){
let _drawData = function(key, y, c){ let _drawData = function(key, y, c){
key = key.toUpperCase() key = key.toUpperCase();
let text = key; let text = key;
let value = "ERR"; let value = "ERR";
let should_print= true; let should_print= true;
@ -282,7 +384,7 @@ let _drawData = function(key, y, c){
value = Math.round(data.altitude); value = Math.round(data.altitude);
printRow(text, value, y, c); printRow(text, value, y, c);
} }
}) });
} else if(key == "CORET"){ } else if(key == "CORET"){
value = locale.temp(parseInt(E.getTemperature())); value = locale.temp(parseInt(E.getTemperature()));
@ -385,7 +487,7 @@ let drawPosition0 = function(){
drawHorizontalBgLine(color2, batStart, batX2, 171, 5); drawHorizontalBgLine(color2, batStart, batX2, 171, 5);
drawHorizontalBgLine(cGrey, batX2, 172, 171, 5); drawHorizontalBgLine(cGrey, batX2, 172, 171, 5);
for(let i=0; i+batStart<=172; i+=parseInt(batWidth/4)){ for(let i=0; i+batStart<=172; i+=parseInt(batWidth/4)){
drawHorizontalBgLine(cBlack, batStart+i, batStart+i+3, 168, 8) drawHorizontalBgLine(cBlack, batStart+i, batStart+i+3, 168, 8);
} }
// Draw Infos // Draw Infos
@ -614,7 +716,7 @@ let getWeather = function(){
let speedFactor = settings.speed == "kph" ? 1.0 : 1.0 / 1.60934; let speedFactor = settings.speed == "kph" ? 1.0 : 1.0 / 1.60934;
weather.wind = Math.round(wind[1] * speedFactor); weather.wind = Math.round(wind[1] * speedFactor);
return weather return weather;
} catch(ex) { } catch(ex) {
// Return default // Return default
@ -660,7 +762,7 @@ let getAlarmMinutes = function(){
let increaseAlarm = function(){ let increaseAlarm = function(){
try{ try{
let minutes = isAlarmEnabled() ? getAlarmMinutes() : 0; let minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
let alarm = require('sched') let alarm = require('sched');
alarm.setAlarm(TIMER_IDX, { alarm.setAlarm(TIMER_IDX, {
timer : (minutes+5)*60*1000, timer : (minutes+5)*60*1000,
}); });
@ -673,7 +775,7 @@ let decreaseAlarm = function(){
let minutes = getAlarmMinutes(); let minutes = getAlarmMinutes();
minutes -= 5; minutes -= 5;
let alarm = require('sched') let alarm = require('sched');
alarm.setAlarm(TIMER_IDX, undefined); alarm.setAlarm(TIMER_IDX, undefined);
if(minutes > 0){ if(minutes > 0){
@ -784,8 +886,6 @@ Bangle.setUI({mode:"clock",remove:function() {
widget_utils.cleanup(); widget_utils.cleanup();
}}); }});
Bangle.loadWidgets(); Bangle.loadWidgets();
randomColors();//Apply random colors if applied
// Clear the screen once, at startup and draw clock // Clear the screen once, at startup and draw clock
g.setTheme({bg:"#000",fg:"#fff",dark:true}).clear(); g.setTheme({bg:"#000",fg:"#fff",dark:true}).clear();
draw(); draw();