Créez une barre de chargement de style Windows en suivant les instructions suivantes.
(remarquez que cela diffère de Loading ... Forever )
Votre sortie devrait commencer par [.... ]
.
Chaque tick, vous devriez attendre 100 ms, puis déplacez chaque point d'un caractère à droite. si le point est sur le dixième caractère, déplacez-le vers le premier. Notez que vous devez effacer l’écran avant de relancer la sortie. La sortie est ordonnée comme suit:
[.... ]
[ .... ]
[ .... ]
[ .... ]
[ .... ]
[ .... ]
[ ....]
[. ...]
[.. ..]
[... .]
..Alors il boucle pour toujours.
Règles
- C’est du code-golf , donc la réponse la plus courte gagne
je doute d’accepter une réponse gagnante - S'il vous plaît fournir un fichier gif de la barre de chargement en action si possible.
code-golf
ascii-art
kolmogorov-complexity
animation
Matthew Roh
la source
la source
\r
option est-elle autorisée au lieu d'effacer littéralement l'écran?Réponses:
V,
171615 octets<esc>
est0x1b
.Et l'hexdump:
Explication
la source
i.... <esc>qq:sl 100m<CR>$X|P@qq@q
devrait fonctionner (<esc>
est évidemment la touche d'échappement et<CR>
un saut de ligne) (il y a 6 espaces après les 4 points)gó
fonction est utile.CSS / HTML,
202190186 + 45 =247235231 octetsEdit: Sauvegardé
1214 octets grâce à @Luke.la source
b
?ch
à la fin;0
n'a pas besoin d'une unité.<x>
à<span>
(et dans le CSS ainsi:x
devientspan
etx>x
devientspan>*
)? Cela économise ledisplay:inline-block;
, mais ne coûte que 15 octets. Donc, un total de 6B sont sauvegardés.position:absolute;
.PowerShell,
67 à66 octets-1 en utilisant un constructeur raccourci grâce à Beatcracker
remplace la chaîne par une copie de la chaîne où le dernier caractère est placé devant les caractères restants, efface l'écran, l'imprime, puis se met en veille pendant 100 ms.
économisé de nombreux octets en utilisant le constructeur de la boucle for plutôt que d’envelopper la logique dans la chaîne.
la source
for
tour de boucle et me faire relire à propos de_Join .$s='.'*4+' '*6
.[.... ]
. Vous pouvez le réparer sans pénalité:for($s='.'*4+' '*6){cls;"[$s]";$s=-join($s[,9+0..8]);sleep -m 100}
Python 3 ,
99938583 + 2 ( drapeau -u ) octets-12 octets grâce à ovs
-2 octets grâce à totalementhumain
Essayez-le en ligne!
la source
flush=True
? Cela fonctionne sans pour moiprint(end='\r[%s]'%s,flush=1)
-u
indicateur de ligne de commande. SO questions[9]+s[:9]
.Lot Windows,
201181 octetsIl s'avère que l'utilisation de la méthode old-school économise réellement des octets!
Remarque:
Veuillez noter que mon enregistreur GIF a sauté quelques images, faisant sauter la barre de chargement
:(
la source
@echo off
et de remplacer ledo @(echo %%~p&timeout/t 0 >nul&cls)
travail par fonctionne également et devrait enregistrer 11 caractères (200 octets sur mon ordinateur)Mathematica,
6777 octets+10 octets car j'ai oublié les crochets.
la source
Animate
? :|C (gcc),
126125124123122121119118117114115 bytesThis one uses a bitmask to keep track of where the dots are.
I had to add another byte as I was only outputting 5 spaces before.
Try it online!
la source
Javascript (ES6), 86 bytes
la source
with
. Always +1 forwith
!JavaScript (ES6) + HTML,
1048583 bytesinput
instead of apre
.Try It
Requires a closing
>
on theinput
tag in order to function in a Snippet.la source
[]
s?<input>
instead of<pre>
and thenvalue
instead ofinnerText
?s='.... ';setInterval(f=>{o.value='[${s=s[9]+s.slice(0,9)}]'},100);<input id=o
, maybe someone can improve it (replace quotation mark with `)Noodel,
16151413 bytes[ CỤ‘Ṁ~ððÐ]ʠḷẸḍt]ʠ[Ð.×4¤×6⁺ḷẸḍt]ʠ⁶¤⁴.ȧ[ėÐḷẸḍtTry it:)
How it works
Update
Try it:)
Don’t know why this took me a while to think of. Anyways, this places it at 13 bytes.
la source
PHP, 67 bytes
no comment
la source
C#,
162157 bytesor as whole program for 177 bytes
la source
for(string o="[.... ]";;)
can be golfed tovar o="[.... ]";for(;;)
. Or you can us a port of my Java 7 answer to golf the total some more:()=>{var o=".... "for(;;){o=(o+o).Substring(9,10);System.Console.Write("["+o+"]\n");System.Threading.Thread.Sleep(100);System.Console.Clear();}};
$"[{o}]\n"
System.Console.Write(o)
withSystem.Console.Write(o+"\r")
you can remove theSystem.Console.Clear();
Pure bash, 68
la source
MATL, 24 bytes
Try it at MATL Online! Or see a gif from the offline compiler:
Explanation
la source
Jelly,
2827 bytesHow?
la source
C (gcc),
202198196189969988867977757473 bytesSaved
78 bytes thanks to Digital Trauma.Or, if your system's
stdout
doesn't need to be flushed after every write without a newline:C (gcc), 70 bytes
How it works
usleep(
sleeps for the next return value in microseconds.dprintf(2,
prints to file descriptor 2, orstderr
. This is necessary because whilestdout
is line-buffered (meaning output will not show until it prints a newline),stderr
is character-buffered (all output is shown immediately)."\r
prints a carriage return (clears the current line).[%-10.10s]"
is theprintf
format specifier for a string with exact length 10 (no matter what string provided the output will always be a string with length 10), padded with spaces to the right if necessary. This will be enclosed with brackets.".... ...."
is the loading bar.+i%10
offsets the loading bar by the current index modulo 10. For example, ifi == 3
,i % 10
is equal to 3. Offsetting the loading bar by 3 makes it equal to". ...."
.printf
format specifier, it limits to a length of 10 if necessary and adds spaces to the end if necessary. Therefore, the loading bar will always be between[.... ]
and[. ...]
.la source
i;f(){for(;;i=++i%10)usleep(7500*dprintf(2,"\r[%-10.10s]",".... ...."-i+10));}
should work.f(i){usleep(dprintf(2,"\r[%-10.10s]",".... ...."+i%10)<<13);f(i+9);}
Java 7,
139124 bytes\r
thanks to @Phoenix.The carriage return
\r
resets the 'cursor' back to the begin of the line, which can then be overwritten. Unfortunately, online compilers nor the Eclipse IDE doesn't support this, so I've added a gif at the end of this answer to show it from Windows Command Prompt.Try it here. (Slightly modified so you won't have to wait for the time-out before viewing the result. Also, the TIO doesn't support carriage returns, so every line is printed without overwriting the previous line.)
Explanation:
Output gif:
la source
println
withprint
and outputting a carriage return. Might not work in your IDE's terminal, but it would work in any other sane one.\r\n
? How doesSystem.out.print(someString+"\r\n);
clear the console.. It's the same as usingSystem.out.println(someString);
.. It simply goes to the next line, but doesn't remove any previous line printed.. :S\r
, without\n
. That resets the "cursor" to the beginning of the line so printing anything will overwrite that line.Python 2,
8178 bytes-1 byte (noticing I missed use of
%s
when Rod submitted an almost identical Python 3 version at the same time!)-2 bytes (using totallyhuman's idea - replace
s[-1]+s[:-1]
withs[9]+s[:9]
)la source
\r
overwrites the line and the,
makes it print a tuple rather than a string - I saw it a while back somewhere and have used it before too.sys.stdout.flush()
)Go,
150145132129124 bytes-5 bytes thanks to sudee.
I feel like I don't see enough Go here... But my answer is topping C so... pls halp golf?
Try it online!
la source
100000000
to10^8
to save 5 bytes.10**8
which also gives an error.1e8
.VBA 32-bit,
159157143141134 BytesVBA does not have a built in function that allows for waiting for time periods less than one second so we must declare a function from
kernel32.dll
32 Bit Declare Statement (41 Bytes)
64 Bit Declare Statement (49 Bytes)
Additionally, we must include a
DoEvents
flag to avoid the infinite loop from making Excel appear as non-responsive. The final function is then a subroutine which takes no input and outputs to the VBE immediate window.Immediate Window function, 93 Bytes
Anonymous VBE immediate window function that takes no input and outputs to the range
A1
on the ActiveSheetOld Version, 109 Bytes
Immediate window function that takes no input and outputs to the VBE immediate window.
Ungolfted and formatted
-2 Bytes for removing whitespace
-30 Bytes for counting correctly
-14 Bytes for converting to immediate window function
Output
The gif below uses the full subroutine version because I was too lazy to rerecord this with the immediate window function.
la source
a
at the top of the output?a
as is listed above; this is functionally equivalant to the more verbosecall a()
.05AB1E, 23 bytes
Try it online!
Explanation
la source
Batch,
9998 bytesSaved 1 byte thanks to SteveFest!
(I could remove
\r
from the code, but in the spirit of batch golfing, I won't.)There are four spaces after the first line.
The main logic is modifying the string.
%s:~-1%
is the last character of%s%
and%s:~0,-1%
is all but the last character of%s%
. Thus, we are moving the last character to the front of the string, which rotates the string.la source
0
in the variable substring can be removedcmder
. Nice job.Ruby,
5756 bytesHeavily influenced by other answers here.
Saved a byte thanks to @manatwork. Also apparently I have trouble counting characters -- I use ST3 and apparently it will include newlines in the count of characters in the line if you're not attentive.
la source
s
?s
at the beginning of the program as 4.
s and a few spacess[0..8]
→s.chop
Perl, 69 bytes
-3 bytes thanks to @Dom Hastings.
That
select undef,undef,undef,.1
is the shortest way to sleep less than 1 second in Perl, and it takes a lot of bytes...Slightly longer (79 bytes), there is:
la source
!print
but you need parens so it ends up the same length :/Bash,
939096 bytesview here
couldn't get nested { } in for syntax
la source
Groovy, 72 bytes
Explaination
la source
\r
to return the cursor to the start of the line. It appears that at least several answers are doing this. From there, you could delete the *20, saving 3 bytes.Haskell (Windows), 159 bytes
Explanation
Haskell's purity made generating the cycling dot pattern somewhat complex. I ended up creating a nested list comprehension that generated an infinite list of strings in the order they should be output, then went back added the appropriate IO operations.
la source
Ruby, 61 bytes
If the spec were for the dots to scroll left instead of right, it would save 1 byte because
rotate!
with no arguments shifts the array once to the left.la source
GNU sed (with exec extension), 64
Score includes +1 for
-r
flag.la source
c, 100
la source
stderr
usingdprintf
and not just useprintf
?stderr
is character buffered, whereasstdout
is line buffered. Since I don't want to print any\n
, then withprintf()
I'd have to explicitlyfflush(stdout)
as well as#include <stdio.h>
#include <stdio.h>
to flush STDOUT.fflush(0)
flushes all buffers.main
tof
, that counts.