Spinning rod animation/Text: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 44: | Line 44: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">L |
||
L(rod) ‘\|/-’ |
L(rod) ‘\|/-’ |
||
print(rod, end' "\r") |
print(rod, end' "\r") |
||
sleep(0.25)</ |
sleep(0.25)</syntaxhighlight> |
||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
< |
<syntaxhighlight lang="action!">PROC Wait(BYTE frames) |
||
BYTE RTCLOK=$14 |
BYTE RTCLOK=$14 |
||
frames==+RTCLOK |
frames==+RTCLOK |
||
Line 77: | Line 77: | ||
CH=$FF |
CH=$FF |
||
CRSINH=0 ;show cursor |
CRSINH=0 ;show cursor |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Spinning_rod_animation_text.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Spinning_rod_animation_text.png Screenshot from Atari 8-bit computer] |
||
Line 86: | Line 86: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_IO; |
||
procedure Spinning_Rod is |
procedure Spinning_Rod is |
||
Line 108: | Line 108: | ||
end loop; |
end loop; |
||
Put (ASCII.ESC & "[?25h"); -- Restore the cursor |
Put (ASCII.ESC & "[?25h"); -- Restore the cursor |
||
end Spinning_Rod;</ |
end Spinning_Rod;</syntaxhighlight> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} |
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} |
||
Sadly, Algol 68 doesn't have a standard delay/sleep routine, so this sample delays with a busy loop. A loop of 2 000 000 gives a reasonable spinning rod on the machine I tried it on. Increase the outer loop maximum for a longer animation. |
Sadly, Algol 68 doesn't have a standard delay/sleep routine, so this sample delays with a busy loop. A loop of 2 000 000 gives a reasonable spinning rod on the machine I tried it on. Increase the outer loop maximum for a longer animation. |
||
< |
<syntaxhighlight lang="algol68">FOR i TO 1 000 DO # increase/decrease the TO value for a longer/shorter animation # |
||
FOR d TO 2 000 000 DO SKIP OD; # adjust to change the spin rate # |
FOR d TO 2 000 000 DO SKIP OD; # adjust to change the spin rate # |
||
print( ( CASE 1 + i MOD 4 IN "/", "-", "\", "|" ESAC, REPR 8 ) ) |
print( ( CASE 1 + i MOD 4 IN "/", "-", "\", "|" ESAC, REPR 8 ) ) |
||
OD</ |
OD</syntaxhighlight> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f SPINNING_ROD_ANIMATION_TEXT.AWK |
# syntax: GAWK -f SPINNING_ROD_ANIMATION_TEXT.AWK |
||
@load "time" |
@load "time" |
||
Line 129: | Line 129: | ||
exit(0) |
exit(0) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|BaCon}}== |
=={{header|BaCon}}== |
||
< |
<syntaxhighlight lang="qbasic">WHILE TRUE |
||
PRINT CR$, TOKEN$("🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘", x); |
PRINT CR$, TOKEN$("🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘", x); |
||
x = IIF(x>7, 1, x+1) |
x = IIF(x>7, 1, x+1) |
||
SLEEP 250 |
SLEEP 250 |
||
WEND</ |
WEND</syntaxhighlight> |
||
=={{header|Bash}}== |
=={{header|Bash}}== |
||
< |
<syntaxhighlight lang="bash">while : ; do |
||
for rod in \| / - \\ ; do printf ' %s\r' $rod; sleep 0.25; done |
for rod in \| / - \\ ; do printf ' %s\r' $rod; sleep 0.25; done |
||
done</ |
done</syntaxhighlight> |
||
(Added an indent in the printf to better see the spinning rod). |
(Added an indent in the printf to better see the spinning rod). |
||
=={{header|C}}== |
=={{header|C}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <time.h> |
#include <time.h> |
||
Line 174: | Line 174: | ||
printf("\033[?25h"); // restore the cursor |
printf("\033[?25h"); // restore the cursor |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C Shell}}== |
=={{header|C Shell}}== |
||
< |
<syntaxhighlight lang="csh">while 1 |
||
foreach rod ('|' '/' '-' '\') |
foreach rod ('|' '/' '-' '\') |
||
printf ' %s\r' $rod; sleep 0.25 |
printf ' %s\r' $rod; sleep 0.25 |
||
end |
end |
||
end</ |
end</syntaxhighlight> |
||
(Added an indent in the printf to better see the spinning rod). |
(Added an indent in the printf to better see the spinning rod). |
||
=={{header|Caché ObjectScript}}== |
=={{header|Caché ObjectScript}}== |
||
< |
<syntaxhighlight lang="caché objectscript">SPINROD |
||
; spin 10 times with quarter-second wait |
; spin 10 times with quarter-second wait |
||
for i = 1:1:10 { |
for i = 1:1:10 { |
||
Line 196: | Line 196: | ||
} |
} |
||
} |
} |
||
quit</ |
quit</syntaxhighlight> |
||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
< |
<syntaxhighlight lang="lisp">(while t |
||
(dolist (char (string-to-list "\\|/-")) |
(dolist (char (string-to-list "\\|/-")) |
||
(message "%c" char) |
(message "%c" char) |
||
(sit-for 0.25)))</ |
(sit-for 0.25)))</syntaxhighlight> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: calendar combinators.extras formatting io sequences |
||
threads ; |
threads ; |
||
[ |
[ |
||
"\\|/-" [ "%c\r" printf flush 1/4 seconds sleep ] each |
"\\|/-" [ "%c\r" printf flush 1/4 seconds sleep ] each |
||
] forever</ |
] forever</syntaxhighlight> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
Tested in gforth 0.7.9 |
Tested in gforth 0.7.9 |
||
< |
<syntaxhighlight lang="forth"> |
||
: rod |
: rod |
||
cr |
cr |
||
Line 227: | Line 227: | ||
; |
; |
||
rod |
rod |
||
</syntaxhighlight> |
|||
</lang> |
|||
This one is designed to be embedded in a program when the user has to wait for some (silent) task to finish. It is designed as a coroutine, so the state of the spinner is preserved. |
This one is designed to be embedded in a program when the user has to wait for some (silent) task to finish. It is designed as a coroutine, so the state of the spinner is preserved. |
||
{{works with|4tH v3.64.0}} |
{{works with|4tH v3.64.0}} |
||
<lang> |
<syntaxhighlight lang="text"> |
||
include lib/yield.4th |
include lib/yield.4th |
||
Line 252: | Line 252: | ||
test |
test |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">' version 13-07-2018 |
||
' compile with: fbc -s console |
' compile with: fbc -s console |
||
Line 271: | Line 271: | ||
Wend |
Wend |
||
End</ |
End</syntaxhighlight> |
||
=={{header|GlovePIE}}== |
=={{header|GlovePIE}}== |
||
Because GlovePIE is a looping programming language, which means the script is ran over and over again in a looping fashion, this code loops again and again until it's stopped. |
Because GlovePIE is a looping programming language, which means the script is ran over and over again in a looping fashion, this code loops again and again until it's stopped. |
||
< |
<syntaxhighlight lang="glovepie">debug="|" |
||
wait 250 ms |
wait 250 ms |
||
debug="/" |
debug="/" |
||
Line 282: | Line 282: | ||
wait 250 ms |
wait 250 ms |
||
debug="\" |
debug="\" |
||
wait 250 ms</ |
wait 250 ms</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{works with|Ubuntu 16.04}} |
{{works with|Ubuntu 16.04}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 311: | Line 311: | ||
} |
} |
||
fmt.Print("\033[?25h") // restore the cursor |
fmt.Print("\033[?25h") // restore the cursor |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Uses the terminfo library to make the cursor invisible, if possible. |
Uses the terminfo library to make the cursor invisible, if possible. |
||
< |
<syntaxhighlight lang="haskell">import Control.Concurrent (threadDelay) |
||
import Control.Exception (bracket_) |
import Control.Exception (bracket_) |
||
import Control.Monad (forM_) |
import Control.Monad (forM_) |
||
Line 342: | Line 342: | ||
putStrLn "Spinning rod demo. Hit ^C to stop it.\n" |
putStrLn "Spinning rod demo. Hit ^C to stop it.\n" |
||
term <- setupTermFromEnv |
term <- setupTermFromEnv |
||
bracket_ (cursorOff term) (cursorOn term) spin</ |
bracket_ (cursorOff term) (cursorOn term) spin</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="java">public class SpinningRod |
||
{ |
{ |
||
public static void main(String[] args) throws InterruptedException { |
public static void main(String[] args) throws InterruptedException { |
||
Line 367: | Line 367: | ||
System.out.print("\033[?25h"); // restore the cursor |
System.out.print("\033[?25h"); // restore the cursor |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Javascript}}== |
=={{header|Javascript}}== |
||
Node JS: |
Node JS: |
||
< |
<syntaxhighlight lang="javascript"> |
||
const rod = (function rod() { |
const rod = (function rod() { |
||
const chars = "|/-\\"; |
const chars = "|/-\\"; |
||
Line 382: | Line 382: | ||
})(); |
})(); |
||
setInterval(rod, 250); |
setInterval(rod, 250); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="julia">while true |
||
for rod in "\|/-" # this needs to be a string, a char literal cannot be iterated over |
for rod in "\|/-" # this needs to be a string, a char literal cannot be iterated over |
||
print(rod,'\r') |
print(rod,'\r') |
||
Line 392: | Line 392: | ||
end |
end |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="scala">// Version 1.2.50 |
||
const val ESC = "\u001b" |
const val ESC = "\u001b" |
||
Line 418: | Line 418: | ||
} |
} |
||
print("$ESC[?25h") // restore the cursor |
print("$ESC[?25h") // restore the cursor |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
<syntaxhighlight lang="lua"> |
|||
<lang Lua> |
|||
-- |
-- |
||
-- Simple String Animation - semi-hard-coded variant - you can alter the chars table - update the count and run it... |
-- Simple String Animation - semi-hard-coded variant - you can alter the chars table - update the count and run it... |
||
Line 512: | Line 512: | ||
_data.anim, _data.count, _data.index, _data.expiry = _tab, nil, nil, nil; |
_data.anim, _data.count, _data.index, _data.expiry = _tab, nil, nil, nil; |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
Usage: |
Usage: |
||
<syntaxhighlight lang="lua"> |
|||
<lang Lua> |
|||
-- 1 second delay, going backwards. |
-- 1 second delay, going backwards. |
||
print( string.BasicAnimation( 1, true ) ); |
print( string.BasicAnimation( 1, true ) ); |
||
Line 527: | Line 527: | ||
-- 1 second delay going backwards |
-- 1 second delay going backwards |
||
print( string.BasicAnimation( 1 ) ); |
print( string.BasicAnimation( 1 ) ); |
||
</syntaxhighlight> |
|||
</lang> |
|||
===Extended Modular Variant=== |
===Extended Modular Variant=== |
||
<syntaxhighlight lang="lua"> |
|||
<lang Lua> |
|||
-- |
-- |
||
-- Simple String Animation - Josh 'Acecool' Moser under modified ACL - Free to use, modify and learn from. |
-- Simple String Animation - Josh 'Acecool' Moser under modified ACL - Free to use, modify and learn from. |
||
Line 874: | Line 874: | ||
return _char, _has_frame_advanced; |
return _char, _has_frame_advanced; |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
<br /> |
<br /> |
||
Line 880: | Line 880: | ||
<br /> |
<br /> |
||
<syntaxhighlight lang="lua"> |
|||
<lang Lua> |
|||
-- |
-- |
||
-- In some HUD element, or where text is output... such as 'Loading' ... try: |
-- In some HUD element, or where text is output... such as 'Loading' ... try: |
||
Line 896: | Line 896: | ||
-- In this example print would be draw.Text or something along those lines. |
-- In this example print would be draw.Text or something along those lines. |
||
print( 'Loading' .. string.SimpleAnimation( STRING_ANIMATION_DOTS ) ); |
print( 'Loading' .. string.SimpleAnimation( STRING_ANIMATION_DOTS ) ); |
||
</syntaxhighlight> |
|||
</lang> |
|||
<br /> |
<br /> |
||
Line 902: | Line 902: | ||
<br /> |
<br /> |
||
<syntaxhighlight lang="lua"> |
|||
<lang Lua> |
|||
-- |
-- |
||
-- Example - This is one way it could be used without rendering it every frame... Pseudo code and a task which is a good idea to do - when the map is added, add a function to register the animation and also go through each animation index and see which element is |
-- Example - This is one way it could be used without rendering it every frame... Pseudo code and a task which is a good idea to do - when the map is added, add a function to register the animation and also go through each animation index and see which element is |
||
Line 945: | Line 945: | ||
end |
end |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Module Checkit { |
Module Checkit { |
||
n$=lambda$ n=1, a$="|/-\" -> { |
n$=lambda$ n=1, a$="|/-\" -> { |
||
Line 963: | Line 963: | ||
CheckIt |
CheckIt |
||
</syntaxhighlight> |
|||
</lang> |
|||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Module Checkit { |
Module Checkit { |
||
n=1 |
n=1 |
||
Line 977: | Line 977: | ||
CheckIt |
CheckIt |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">chars = "|/\[Dash]\\"; |
||
pos = 1; |
pos = 1; |
||
Dynamic[c] |
Dynamic[c] |
||
Line 987: | Line 987: | ||
c = StringTake[chars, {pos}]; |
c = StringTake[chars, {pos}]; |
||
Pause[0.25]; |
Pause[0.25]; |
||
]</ |
]</syntaxhighlight> |
||
=={{header|MelonBasic}}== |
=={{header|MelonBasic}}== |
||
< |
<syntaxhighlight lang="melonbasic">Wait:0.25 |
||
Delete:1 |
Delete:1 |
||
Say:/ |
Say:/ |
||
Line 1,001: | Line 1,001: | ||
Wait:0.25 |
Wait:0.25 |
||
Delete:1 |
Delete:1 |
||
Goto:1</ |
Goto:1</syntaxhighlight> |
||
=={{header|Microsoft Small Basic}}== |
=={{header|Microsoft Small Basic}}== |
||
< |
<syntaxhighlight lang="microsoftsmallbasic">a[1]="|" |
||
a[2]="/" |
a[2]="/" |
||
a[3]="-" |
a[3]="-" |
||
Line 1,015: | Line 1,015: | ||
Program.Delay(250) |
Program.Delay(250) |
||
EndFor |
EndFor |
||
EndWhile</ |
EndWhile</syntaxhighlight> |
||
=={{header|MiniScript}}== |
=={{header|MiniScript}}== |
||
Control over the text cursor -- or indeed, whether there ''is'' a text cursor, or even text at all -- depends on the host environment. Here's a version that works with [https://miniscript.org/MiniMicro/ MiniMicro]: |
Control over the text cursor -- or indeed, whether there ''is'' a text cursor, or even text at all -- depends on the host environment. Here's a version that works with [https://miniscript.org/MiniMicro/ MiniMicro]: |
||
< |
<syntaxhighlight lang="miniscript">print "Press control-C to exit..." |
||
while true |
while true |
||
for c in "|/-\" |
for c in "|/-\" |
||
Line 1,025: | Line 1,025: | ||
wait 0.25 |
wait 0.25 |
||
end for |
end for |
||
end while</ |
end while</syntaxhighlight> |
||
And here's a version that will work with command-line MiniScript, running on a terminal that interprets standard VT100 escape sequences: |
And here's a version that will work with command-line MiniScript, running on a terminal that interprets standard VT100 escape sequences: |
||
< |
<syntaxhighlight lang="miniscript">while true |
||
for c in "|/-\" |
for c in "|/-\" |
||
print c |
print c |
||
Line 1,034: | Line 1,034: | ||
print char(27) + "[2A" // move cursor up 2 lines |
print char(27) + "[2A" // move cursor up 2 lines |
||
end for |
end for |
||
end while</ |
end while</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
With some modifications. |
With some modifications. |
||
< |
<syntaxhighlight lang="nim">import std/monotimes, times, os |
||
const A = ["|", "/", "—", "\\"] |
const A = ["|", "/", "—", "\\"] |
||
Line 1,055: | Line 1,055: | ||
if (now - start).inSeconds >= 5: |
if (now - start).inSeconds >= 5: |
||
break |
break |
||
echo "$\e[?25h" # Restore the cursor.</ |
echo "$\e[?25h" # Restore the cursor.</syntaxhighlight> |
||
=={{header|NS-HUBASIC}}== |
=={{header|NS-HUBASIC}}== |
||
The 0.25 second delay assumes the program is running at 60 frames per second. |
The 0.25 second delay assumes the program is running at 60 frames per second. |
||
< |
<syntaxhighlight lang="ns-hubasic">10 DIM A(4) |
||
20 A(1)=236 |
20 A(1)=236 |
||
30 A(2)=234 |
30 A(2)=234 |
||
Line 1,069: | Line 1,069: | ||
90 PAUSE 15 |
90 PAUSE 15 |
||
100 NEXT |
100 NEXT |
||
110 GOTO 60</ |
110 GOTO 60</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
The statement <code>$| =1</code> is required in order to disable output buffering. |
The statement <code>$| =1</code> is required in order to disable output buffering. |
||
< |
<syntaxhighlight lang="perl">$|= 1; |
||
while () { |
while () { |
||
Line 1,080: | Line 1,080: | ||
printf "\r ($_)"; |
printf "\r ($_)"; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Extending it for moon phases: |
Extending it for moon phases: |
||
< |
<syntaxhighlight lang="perl">$|=1; |
||
binmode STDOUT, ":utf8"; |
binmode STDOUT, ":utf8"; |
||
Line 1,100: | Line 1,100: | ||
# (3) `@{}` dereferences the created list. |
# (3) `@{}` dereferences the created list. |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
=== console version === |
=== console version === |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (cursor, sleep)</span> |
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (cursor, sleep)</span> |
||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"please_wait... "</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"please_wait... "</span><span style="color: #0000FF;">)</span> |
||
Line 1,115: | Line 1,115: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" \ndone"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- clear rod, "done" on next line</span> |
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" \ndone"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- clear rod, "done" on next line</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=== GUI version === |
=== GUI version === |
||
{{libheader|Phix/pGUI}} |
{{libheader|Phix/pGUI}} |
||
{{libheader|Phix/online}} |
{{libheader|Phix/online}} |
||
You can run this online [http://phix.x10.mx/p2js/Spinning_rod.htm here] (don't expect too much, improvements welcome). |
You can run this online [http://phix.x10.mx/p2js/Spinning_rod.htm here] (don't expect too much, improvements welcome). |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\Spinning_rod_animation.exw |
-- demo\rosetta\Spinning_rod_animation.exw |
||
Line 1,221: | Line 1,221: | ||
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span> |
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
<syntaxhighlight lang="lisp"> |
|||
<lang Lisp> |
|||
(de rod () |
(de rod () |
||
(until () |
(until () |
||
Line 1,230: | Line 1,230: | ||
(prin R (wait 250) "\r")(flush) ) ) ) |
(prin R (wait 250) "\r")(flush) ) ) ) |
||
(rod) |
(rod) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">from time import sleep |
||
while True: |
while True: |
||
for rod in r'\|/-': |
for rod in r'\|/-': |
||
print(rod, end='\r') |
print(rod, end='\r') |
||
sleep(0.25)</ |
sleep(0.25)</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
(define (anim) |
(define (anim) |
||
Line 1,248: | Line 1,248: | ||
(anim)) |
(anim)) |
||
(anim) |
(anim) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 1,257: | Line 1,257: | ||
This implementation will accept an array of elements to use as its throbber frames, or as a scrolling marquee and optionally a delay before it returns the next element. |
This implementation will accept an array of elements to use as its throbber frames, or as a scrolling marquee and optionally a delay before it returns the next element. |
||
<lang |
<syntaxhighlight lang="raku" line>class throbber { |
||
has @.frames; |
has @.frames; |
||
has $.delay is rw = 0; |
has $.delay is rw = 0; |
||
Line 1,300: | Line 1,300: | ||
print $scroll.next for ^95; |
print $scroll.next for ^95; |
||
END { print "\e[?25h\n" } # clean up on exit</ |
END { print "\e[?25h\n" } # clean up on exit</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 1,311: | Line 1,311: | ||
::* ROO REXX |
::* ROO REXX |
||
::* Regina REXX (see the programming note below.) |
::* Regina REXX (see the programming note below.) |
||
< |
<syntaxhighlight lang="rexx">/*REXX program displays a "spinning rod" (AKA: trobbers or progress indicators). */ |
||
if 4=='f4'x then bs= "16"x /*EBCDIC? Then use this backspace chr.*/ |
if 4=='f4'x then bs= "16"x /*EBCDIC? Then use this backspace chr.*/ |
||
Line 1,324: | Line 1,324: | ||
end /*j*/ |
end /*j*/ |
||
halt: say bs ' ' /*stick a fork in it, we're all done. */</ |
halt: say bs ' ' /*stick a fork in it, we're all done. */</syntaxhighlight> |
||
Programming note: this REXX program makes use of '''DELAY''' BIF which delays (sleeps) for a specified amount of seconds. |
Programming note: this REXX program makes use of '''DELAY''' BIF which delays (sleeps) for a specified amount of seconds. |
||
<br>Some REXXes don't have a '''DELAY''' BIF, so one is included here ──► [[DELAY.REX]]. |
<br>Some REXXes don't have a '''DELAY''' BIF, so one is included here ──► [[DELAY.REX]]. |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring">load "stdlib.ring" |
||
rod = ["|", "/", "-", "\"] |
rod = ["|", "/", "-", "\"] |
||
for n = 1 to len(rod) |
for n = 1 to len(rod) |
||
Line 1,335: | Line 1,335: | ||
sleep(0.25) |
sleep(0.25) |
||
system("cls") |
system("cls") |
||
next</ |
next</syntaxhighlight> |
||
Output: |
Output: |
||
| |
| |
||
Line 1,343: | Line 1,343: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">def spinning_rod |
||
begin |
begin |
||
printf("\033[?25l") # Hide cursor |
printf("\033[?25l") # Hide cursor |
||
Line 1,358: | Line 1,358: | ||
puts "Ctrl-c to stop." |
puts "Ctrl-c to stop." |
||
spinning_rod |
spinning_rod |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust">fn main() { |
||
let characters = ['|', '/', '-', '\\']; |
let characters = ['|', '/', '-', '\\']; |
||
let mut current = 0; |
let mut current = 0; |
||
Line 1,374: | Line 1,374: | ||
std::thread::sleep(std::time::Duration::from_millis(250)); // Sleep 250 ms. |
std::thread::sleep(std::time::Duration::from_millis(250)); // Sleep 250 ms. |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
< |
<syntaxhighlight lang="scala">object SpinningRod extends App { |
||
val start = System.currentTimeMillis |
val start = System.currentTimeMillis |
||
Line 1,393: | Line 1,393: | ||
print("\033[?25h") // restore the cursor |
print("\033[?25h") // restore the cursor |
||
}</ |
}</syntaxhighlight> |
||
=={{header|ScratchScript}}== |
=={{header|ScratchScript}}== |
||
< |
<syntaxhighlight lang="scratchscript">print "|" |
||
delay 0.25 |
delay 0.25 |
||
clear |
clear |
||
Line 1,406: | Line 1,406: | ||
clear |
clear |
||
print "\" |
print "\" |
||
delay 0.25</ |
delay 0.25</syntaxhighlight> |
||
=={{header|SimpleCode}}== |
=={{header|SimpleCode}}== |
||
<syntaxhighlight lang="simplecode">dtxt |
|||
<lang SimpleCode>dtxt |
|||
| |
| |
||
wait |
wait |
||
Line 1,430: | Line 1,430: | ||
\ |
\ |
||
wait |
wait |
||
0.25</ |
0.25</syntaxhighlight> |
||
=={{header|Wee Basic}}== |
=={{header|Wee Basic}}== |
||
Since the "|" character isn't built into Wee Basic on the Nintendo DS, and it looks the part in Wee Basic on the Nintendo DS, the character "l" is used as a substitute. Also, since no working delay command has been found yet, a for loop is used to work around this problem. |
Since the "|" character isn't built into Wee Basic on the Nintendo DS, and it looks the part in Wee Basic on the Nintendo DS, the character "l" is used as a substitute. Also, since no working delay command has been found yet, a for loop is used to work around this problem. |
||
< |
<syntaxhighlight lang="wee basic">let loop=1 |
||
sub delay: |
sub delay: |
||
for i=1 to 10000 |
for i=1 to 10000 |
||
Line 1,450: | Line 1,450: | ||
gosub delay: |
gosub delay: |
||
wend |
wend |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="ecmascript">import "io" for Stdout |
||
import "timer" for Timer |
import "timer" for Timer |
||
Line 1,478: | Line 1,478: | ||
if (now * 1000 + asleep - start * 1000 >= 20000) break |
if (now * 1000 + asleep - start * 1000 >= 20000) break |
||
} |
} |
||
System.print("%(ESC)[?25h") // restore the cursor</ |
System.print("%(ESC)[?25h") // restore the cursor</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">char I, Rod; |
||
[Rod:= "|/-\ "; |
[Rod:= "|/-\ "; |
||
loop for I:= 0 to 3 do |
loop for I:= 0 to 3 do |
||
Line 1,489: | Line 1,489: | ||
if KeyHit then quit; |
if KeyHit then quit; |
||
]; |
]; |
||
]</ |
]</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|C Shell}} |
{{trans|C Shell}} |
||
< |
<syntaxhighlight lang="zkl">foreach n,rod in ((1).MAX, T("|", "/", "-", "\\")){ |
||
print(" %s\r".fmt(rod)); |
print(" %s\r".fmt(rod)); |
||
Atomic.sleep(0.25); |
Atomic.sleep(0.25); |
||
}</ |
}</syntaxhighlight> |
||
A loop foreach a,b in (c,d) translates to |
A loop foreach a,b in (c,d) translates to |
||
foreach a in (c) foreach b in (d). n.MAX is a 64 bit int (9223372036854775807). |
foreach a in (c) foreach b in (d). n.MAX is a 64 bit int (9223372036854775807). |
||
Line 1,503: | Line 1,503: | ||
A more useful example would be a worker thread showing a "I'm working" display |
A more useful example would be a worker thread showing a "I'm working" display |
||
(in another thread) and turning it off when that work is done. |
(in another thread) and turning it off when that work is done. |
||
< |
<syntaxhighlight lang="zkl">fcn spin{ // this will be a thread that displays spinner |
||
try{ |
try{ |
||
foreach n,rod in ((1).MAX, "\\|/-"){ |
foreach n,rod in ((1).MAX, "\\|/-"){ |
||
Line 1,510: | Line 1,510: | ||
} |
} |
||
}catch{} // don't complain about uncaught exception that stops thread |
}catch{} // don't complain about uncaught exception that stops thread |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang="zkl">// main body of code |
||
spinner:=spin.launch(); // start spinner thread, returns reference to thread |
spinner:=spin.launch(); // start spinner thread, returns reference to thread |
||
Atomic.sleep(10); // do stuff |
Atomic.sleep(10); // do stuff |
||
vm.kick(spinner.value); // stop thread by throwing exception at it</ |
vm.kick(spinner.value); // stop thread by throwing exception at it</syntaxhighlight> |
||
=={{header|ZX Spectrum Basic}}== |
=={{header|ZX Spectrum Basic}}== |
||
< |
<syntaxhighlight lang="zx basic">10 LET A$="|/-\" |
||
20 FOR C=1 TO 4 |
20 FOR C=1 TO 4 |
||
30 PRINT AT 0,0;A$(C) |
30 PRINT AT 0,0;A$(C) |
||
Line 1,523: | Line 1,523: | ||
50 NEXT C |
50 NEXT C |
||
60 GOTO 20 |
60 GOTO 20 |
||
</syntaxhighlight> |
|||
</lang> |