Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --- HUD settings ---
- const spawnX = -18;
- const spawnY = -9; // change to 9 (the y axis is flipped on tw.2s4.me)
- const barLength = 20;
- // Get year progress fraction
- function getYearProgress() {
- const now = new Date();
- const start = new Date(now.getFullYear(), 0, 1);
- const end = new Date(now.getFullYear() + 1, 0, 1);
- return (now - start) / (end - start);
- }
- // --- Draw year + percent ---
- function drawYearLine() {
- const now = new Date();
- const year = now.getFullYear();
- const progress = getYearProgress();
- const percent = (progress * 100).toFixed(2);
- const line = `${year} - ${percent}%`;
- for (let i = 0; i < line.length; i++) {
- writeCharAt(
- line[i],
- colFmt(0, { bold: true }),
- spawnX + i,
- spawnY
- );
- }
- }
- // --- Draw block progress bar ---
- function drawProgressBar() {
- const progress = getYearProgress();
- const filled = Math.round(progress * barLength);
- const bar =
- "▓".repeat(filled) +
- "░".repeat(barLength - filled);
- for (let i = 0; i < bar.length; i++) {
- writeCharAt(
- bar[i],
- colFmt(0, { bold: true }),
- spawnX + i,
- spawnY + 1
- );
- }
- }
- // --- Initial draw ---
- drawYearLine();
- drawProgressBar();
- // --- Timers ---
- setInterval(drawYearLine, 2000);
- setInterval(drawProgressBar, 3500);
Advertisement
Add Comment
Please, Sign In to add comment