106
\$\begingroup\$

Your challenge is to make an infinite loading screen, that looks like this:

enter image description here


Or, to be more specific:

  • Take no input.
  • Output Loading..., with a trailing space, but no trailing newline.
  • Infinitely cycle through the chars |, /, - and \: every 0.25 seconds, overwrite the last one with the next in the sequence. You can overwrite just the last character, or delete and rewrite the whole line, as long Loading... remains unchanged.

Rules

  • The output text must look exactly as specified. Trailing newlines/spaces are acceptable.
  • You should not wait 0.25 seconds before initially showing output - the first frame should be printed as soon as the program is run.
  • Your program should be able to run indefinitely. For example, if you use a counter for frames, the counter should never cause an error by exceeding the maximum in your language.
  • Although the waiting period between each "frame" should be 0.25 seconds, obviously this will never be exact - an error margin of 10% or so is allowed.
  • You may submit a function, but it must print to stdout.
  • You can submit an answer in a non-console (but still text-based) environment, as long as it is capable of producing the loading animation.
  • This is , so the shortest solution (in bytes) wins. Standard code-golf loopholes apply.
  • If possible, please provide a gif of your loading screen in action.

Example

Here is the C++ code I used to create the example (ungolfed):

#include <iostream>
#include <string>
#include <thread>

using namespace std;

int main() {
    string cycle = "|/-\\";
    int i = 0;

    cout << "Loading... ";

    while (true) {
        // Print current character
        cout << cycle[i];

        // Sleep for 0.25 seconds
        this_thread::sleep_for(chrono::milliseconds(250));

        // Delete last character, then increase counter.
        cout << "\b";
        i = ++i % 4;
    }
}

May the best golfer win!

\$\endgroup\$
  • 3
    \$\begingroup\$ Can submissions wait 0.25 seconds before initially displaying output? \$\endgroup\$ – ETHproductions Nov 27 '16 at 20:42
  • 2
    \$\begingroup\$ No, but thanks for mentioning that, I'll add it to the rules @ETHproductions \$\endgroup\$ – FlipTack Nov 27 '16 at 20:43
  • \$\begingroup\$ Is a trailing newline (after the animating symbol) acceptable? \$\endgroup\$ – Copper Nov 27 '16 at 20:43
  • \$\begingroup\$ Of course :) @Copper \$\endgroup\$ – FlipTack Nov 27 '16 at 20:44
  • 1
    \$\begingroup\$ @TheBitByte it means that, theoretically, nothing inside your program will cause it to error - such as a counter overflowing or reaching maximum recursion depth. \$\endgroup\$ – FlipTack Dec 15 '16 at 6:57

93 Answers 93

0
\$\begingroup\$

Yabasic, 83 bytes

An anonymous function that takes no input and outputs to the console in graphics mode. Does not function with TIO.

Clear Screen
?"Loading..."
Do
?@(1,11)Mid$("|/-\\",i+1,1)
Wait.25
i=Mod(i+1,4)
Loop
\$\endgroup\$
  • \$\begingroup\$ Can you use i instead of i+1 in Mid$? \$\endgroup\$ – 12Me21 May 17 '18 at 11:55
  • \$\begingroup\$ @12Me21 Unfortunately not - Mid$ is 1-indexed in Yabasic, so the +1 is necessary. You can see this in the context of this question here \$\endgroup\$ – Taylor Scott May 17 '18 at 12:43
0
\$\begingroup\$

Groovy, 59 bytes, 61 bytes

print'Loading...'for(;;)'|/-\\'.each{print"$it\b";sleep250}

asciicast

\$\endgroup\$
-1
\$\begingroup\$

Rust, 117 Bytes

print!("Loading... ");fn f(){let a="\\|/-";for n in 0 .. 4{std::thread::sleep_ms(250);print!("\x08{}",a[n]);}f();}f;

Fixed some compile errors. Nowhere near a compiler right now so bear with me.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.