let overallStartTime = null;
let previousGenerationTime = null;
let isFirstGeneration = true;
function handleProgressBar() {
const progressBarFilled = document.querySelector('.progress-bar-filled');
const currentTime = Date.now();
let secondsPassed = ((currentTime - overallStartTime) / 1000 - 1.5).toFixed(1);
if (isGenerating) {
const activeTime = ((currentTime - startTime) / 1000).toFixed(1);
const numDots = 3;
const maxDotCount = 3;
const dotIndex = Math.floor(activeTime / 2) % numDots;
const dotPattern = '⠿'.repeat(dotIndex + 1) + '⠿'.repeat(maxDotCount - dotIndex - 1);
const binaryTime = convertToBinary(activeTime);
progressBarFilled.textContent = 'processing ' + binaryTime + ' ' + activeTime + ' sec';
} else {
const binaryTime = convertToBinary(secondsPassed);
progressBarFilled.textContent = 'done: ' + secondsPassed + ' sec';
}
}
function convertToBinary(time) {
let milliseconds = Math.floor((time % .1) * 100);
let seconds = Math.floor(time);
let binary = seconds.toFixed(0).toString(2);
let millisecondsBinary = '';
if (milliseconds > 0) {
millisecondsBinary = binaryToBraille(milliseconds.toString(2));
}
const secondsBraille = binaryToBraille(binary);
return secondsBraille + millisecondsBinary;
}
function binaryToBraille(binary) {
const binaryDigits = ['⠝', '⠷', '⠾', '⠄', '⠑', '⠭', '⠱', '⠚', '⠆', '⠤'];
let braille = '';
for (let i = 0; i < binary.length; i++) {
braille += binaryDigits[parseInt(binary[i], 2)];
}
return braille;
}
async function generateImage() {
if (isGenerating || autoQueueActive) {
return;
}
if (galleryArray.length >= totalLimit) {
if (autoSaveEnabled) {
saveAllImages().then(() => {
clearGallery();
});
} else {
clearGallery();
}
return;
}
function updateProgress() {
handleProgressBar();
if (isGenerating) {
requestAnimationFrame(updateProgress);
}
}
function clearGallery() {
galleryArray.length = 0;
updateImageCounter();
bufferContainer.innerHTML = '';
if (autoQueueActive) {
generateInterval = setInterval(generateImage, interval);
}
}
isGenerating = true;
startTime = Date.now();
overallStartTime = Date.now();
updateProgress();```. lets use "toFixed(1)" and adjust these Braille characters so they can show a miliseconds as well.
Sure! If you want to display milliseconds along with the seconds in the progress bar, you can modify the handleProgressBar function as follows:
function handleProgressBar() {
const progressBarFilled = document.querySelector(‘.progress-bar-filled’);
const currentTime = Date.now();
let secondsPassed = ((currentTime - overallStartTime) / 1000 - 1.5).toFixed(0);
const millisecondsPassed = ((currentTime - overallStartTime) % 1000 / 10).toFixed(1);
const binaryTime = convertToBinary(secondsPassed);
if (isGenerating) {
const activeTime = ((currentTime - startTime) / 1000).toFixed(0);
const numDots = 3;
const maxDotCount = 3;
const dotIndex = Math.floor(activeTime / 2) % numDots;
const dotPattern = ‘⠿’.repeat(dotIndex + 1) + ‘⠿’.repeat(maxDotCount - dotIndex - 1);
progressBarFilled.innerText = processing {binaryTime} {activeTime}.{millisecondsPassed} sec; } else { progressBarFilled.innerText = done: {secondsPassed}.${millisecondsPassed} sec;
}
}
In this modification, I added a millisecondsPassed variable to calculate and display the milliseconds. I used the toFixed(1) method to ensure that the milliseconds are displayed with one decimal place.
Now, you will see both seconds and milliseconds displayed in the progress bar, aligned with the Braille characters.
Additionally, you may need to adjust the convertToBinary function to handle milliseconds if you want to represent them using Braille characters. However, keep in mind that representing decimal values in Braille can be challenging due to the limited character set. If you encounter difficulties representing milliseconds with Braille characters, you can instead consider using regular characters or other visual indicators to represent the milliseconds.
"if you want to represent them using Braille characters.". that what is need.
Apologies for any confusion. If you want to represent the milliseconds using Braille characters, you can modify the convertToBinary function to handle decimal values. However, please note that representing decimal values in Braille characters can be challenging due to the limited character set.
Here’s an example of how you can modify the convertToBinary function to handle decimal milliseconds:
function convertToBinary(time) {
let milliseconds = Math.floor((time % 1) * 100); // Extract the millisecond value
let binary = time.toFixed(0).toString(2); // Convert the seconds part to binary
let millisecondsBinary = ‘’;
if (milliseconds > 0) {
millisecondsBinary = binaryToBraille(milliseconds.toString(2)); // Convert the milliseconds part to binary Braille characters
}
const secondsBraille = binaryToBraille(binary); // Convert the seconds binary to Braille characters
return secondsBraille + millisecondsBinary;
}
function binaryToBraille(binary) {
const binaryDigits = [‘⠝’, ‘⠷’, ‘⠾’, ‘⠄’, ‘⠑’, ‘⠭’, ‘⠱’, ‘⠚’, ‘⠆’, ‘⠤’];
let braille = ‘’;
for (let i = 0; i < binary.length; i++) {
braille += binaryDigits[parseInt(binary[i], 2)];
}
return braille;
}
In this modification, the convertToBinary function now calculates the millisecond value separately. It converts the seconds part to binary using the Number.toFixed(0) method and converts it to Braille characters using the binaryToBraille helper function. Additionally, if the milliseconds value is greater than 0, it converts the milliseconds to binary, converts it to Braille characters, and appends it to the seconds Braille representation.
The binaryToBraille function takes a binary string and converts it to Braille characters using the binaryDigits array.
With this modification, the handleProgressBar function can remain the same. The progress bar will display the seconds and milliseconds using Braille characters.
Please note that the representation of decimal values in Braille characters is not standard and may vary depending on Braille fonts and conventions. Adjustments may be needed based on your specific requirements.
Uncaught (in promise) TypeError: time.toFixed is not a function
Apologies for the mistake. The toFixed method can only be used on a numerical value, not on a string.
To fix the error, you can convert the time variable to a number before using the toFixed method. Here’s an updated version of the convertToBinary function:
function convertToBinary(time) {
let milliseconds = Math.floor((time % 1) * 100); // Extract the millisecond value
let seconds = Math.floor(time); // Extract the seconds value
let binary = seconds.toFixed(0).toString(2); // Convert the seconds part to binary
let millisecondsBinary = ‘’;
if (milliseconds > 0) {
millisecondsBinary = binaryToBraille(milliseconds.toString(2)); // Convert the milliseconds part to binary Braille characters
}
const secondsBraille = binaryToBraille(binary); // Convert the seconds binary to Braille characters
return secondsBraille + millisecondsBinary;
}
function binaryToBraille(binary) {
const binaryDigits = [‘⠝’, ‘⠷’, ‘⠾’, ‘⠄’, ‘⠑’, ‘⠭’, ‘⠱’, ‘⠚’, ‘⠆’, ‘⠤’];
let braille = ‘’;
for (let i = 0; i < binary.length; i++) {
braille += binaryDigits[parseInt(binary[i], 2)];
}
return braille;
}
By using Math.floor and converting the time to a number, the toFixed method can now be applied correctly to obtain the whole number of seconds.
This updated code should resolve the toFixed is not a function error and allow you to represent the seconds and milliseconds using Braille characters.
well, it shows tons of Braillies there. can you reduce it to 00.0 as "two Braillinas.one Braillina"
function convertToBinary(time) {
let milliseconds = Math.floor((time % 1) * 100); // Extract the millisecond value
let seconds = Math.floor(time); // Extract the seconds value
let binary = seconds.toFixed(0).toString(2); // Convert the seconds part to binary
let millisecondsBinary = '';
if (milliseconds > 0) {
millisecondsBinary = binaryToBraille(milliseconds.toFixed(0).toString(2)); // Convert the milliseconds part to binary Braille characters
}
const secondsBraille = binaryToBraille(binary); // Convert the seconds binary to Braille characters
return secondsBraille + '.' + millisecondsBinary;
}
function binaryToBraille(binary) {
const brailleDigits = {
'00': '⠴', // 0
'01': '⠂', // 1
'10': '⠢', // 2
'11': '⠐', // 3
};
let braille = '';
for (let i = 0; i < binary.length; i += 2) {
const digit = binary.substring(i, i + 2);
braille += brailleDigits[digit];
}
return braille;
}
function convertToBinary(time) {
let milliseconds = Math.floor((time % 1) * 100); // Extract the millisecond value
let seconds = Math.floor(time); // Extract the seconds value
let binarySeconds = seconds.toFixed(0).toString(2); // Convert the seconds part to binary
let binaryMilliseconds = milliseconds.toFixed(0).toString(2); // Convert the milliseconds part to binary
const brailleSeconds = binaryToBraille(binarySeconds); // Convert the seconds binary to Braille characters
const brailleMilliseconds = binaryToBraille(binaryMilliseconds); // Convert the milliseconds binary to Braille characters
return brailleSeconds + '.' + brailleMilliseconds;
}
function binaryToBraille(binary) {
const brailleDigits = {
'00': '⠴', // 0
'01': '⠂', // 1
'10': '⠢', // 2
'11': '⠐', // 3
};
let braille = '';
for (let i = 0; i < binary.length; i += 2) {
const digit = binary.substring(i, i + 2);
braille += brailleDigits[digit];
}
return braille;
}