Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Assume writeCharAt is defined somewhere in the environment.
- /**
- * Helper function to display text at a specific coordinate, clearing the previous display area.
- * @param {string} text The text to display.
- * @param {number} startX The starting X coordinate.
- * @param {number} startY The starting Y coordinate.
- */
- const displayAt = (text, startX, startY) => {
- // Clear the current line first (assuming max 20 chars for this example)
- writeCharAt(" ".repeat(20), 0, -8, -5);
- for (let i = 0; i < text.length; i++) {
- writeCharAt(text[i], 0, startX + i, startY);
- }
- };
- // --- Multiple Messages Setup ---
- const messages = [
- "hello and welcome",
- "This is message two",
- "And a third one!",
- "Looping..."
- ];
- let currentMessageIndex = 0;
- let currentFrame = 0;
- const updateInterval = 850; // A faster interval for a smoother scroll
- /**
- * The main animation loop.
- */
- setInterval(() => {
- const message = messages[currentMessageIndex];
- const fullLength = message.length;
- // We can define the total frames needed to scroll one message fully
- const totalFramesForMessage = fullLength * 2 + 1;
- // Calculate the text snippet based on the current frame
- let displayedText;
- if (currentFrame < fullLength) {
- // Phase 1: Text scrolls off to the left
- displayedText = message.substring(currentFrame) + " ".repeat(currentFrame);
- } else {
- // Phase 2: Text scrolls in from the right
- const charsToShow = currentFrame - fullLength;
- displayedText = " ".repeat(fullLength - charsToShow) + message.substring(0, charsToShow);
- }
- // Ensure the text length is consistent for display
- // padEnd ensures that we clear the full space the message might occupy
- displayedText = displayedText.padEnd(fullLength, " ");
- // Update the display (using coordinates from original script)
- displayAt(displayedText, cursor.x, cursor.y);
- // --- Message Switching Logic ---
- // Increment the frame counter
- currentFrame++;
- // Check if the current message's animation sequence is complete
- if (currentFrame >= totalFramesForMessage) {
- currentFrame = 0; // Reset frame counter for the new message
- currentMessageIndex = (currentMessageIndex + 1) % messages.length; // Move to the next message (loops back to 0)
- }
- }, updateInterval);
Advertisement
Comments
-
- If you don't want the ticker to stay with your cursor, edit this line:
- displayAt(displayedText, cursor.x, cursor.y); // replace cursor.x, cursor.y with x and y coords
Add Comment
Please, Sign In to add comment