smoothretro82

Tw.2s4.me Scrolling ticker script (update #2)

Nov 8th, 2025 (edited)
66
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. // Assume writeCharAt is defined somewhere in the environment.
  2.  
  3. /**
  4. * Helper function to display text at a specific coordinate, clearing the previous display area.
  5. * @param {string} text The text to display.
  6. * @param {number} startX The starting X coordinate.
  7. * @param {number} startY The starting Y coordinate.
  8. */
  9. const displayAt = (text, startX, startY) => {
  10. // Clear the current line first (assuming max 20 chars for this example)
  11. writeCharAt(" ".repeat(20), 0, -8, -5);
  12.  
  13. for (let i = 0; i < text.length; i++) {
  14. writeCharAt(text[i], 0, startX + i, startY);
  15. }
  16. };
  17.  
  18. // --- Multiple Messages Setup ---
  19. const messages = [
  20. "hello and welcome",
  21. "This is message two",
  22. "And a third one!",
  23. "Looping..."
  24. ];
  25. let currentMessageIndex = 0;
  26. let currentFrame = 0;
  27. const updateInterval = 850; // A faster interval for a smoother scroll
  28.  
  29. /**
  30. * The main animation loop.
  31. */
  32. setInterval(() => {
  33. const message = messages[currentMessageIndex];
  34. const fullLength = message.length;
  35. // We can define the total frames needed to scroll one message fully
  36. const totalFramesForMessage = fullLength * 2 + 1;
  37.  
  38. // Calculate the text snippet based on the current frame
  39. let displayedText;
  40.  
  41. if (currentFrame < fullLength) {
  42. // Phase 1: Text scrolls off to the left
  43. displayedText = message.substring(currentFrame) + " ".repeat(currentFrame);
  44. } else {
  45. // Phase 2: Text scrolls in from the right
  46. const charsToShow = currentFrame - fullLength;
  47. displayedText = " ".repeat(fullLength - charsToShow) + message.substring(0, charsToShow);
  48. }
  49.  
  50. // Ensure the text length is consistent for display
  51. // padEnd ensures that we clear the full space the message might occupy
  52. displayedText = displayedText.padEnd(fullLength, " ");
  53.  
  54. // Update the display (using coordinates from original script)
  55. displayAt(displayedText, cursor.x, cursor.y);
  56.  
  57. // --- Message Switching Logic ---
  58. // Increment the frame counter
  59. currentFrame++;
  60.  
  61. // Check if the current message's animation sequence is complete
  62. if (currentFrame >= totalFramesForMessage) {
  63. currentFrame = 0; // Reset frame counter for the new message
  64. currentMessageIndex = (currentMessageIndex + 1) % messages.length; // Move to the next message (loops back to 0)
  65. }
  66.  
  67. }, updateInterval);
  68.  
Advertisement
Comments
  • smoothretro82
    255 days (edited)
    # text 0.17 KB | 0 0
    1. If you don't want the ticker to stay with your cursor, edit this line:
    2.  
    3. displayAt(displayedText, cursor.x, cursor.y); // replace cursor.x, cursor.y with x and y coords
Add Comment
Please, Sign In to add comment