Spinning rod animation/Text: Difference between revisions
Added Easylang
m (→{{header|REXX}}: added the R4 and ROO REXXes that can be used with this program.) |
(Added Easylang) |
||
(38 intermediate revisions by 22 users not shown) | |||
Line 40:
<br />
<br />
=={{header|11l}}==
{{trans|Python}}
<syntaxhighlight lang="11l">L
L(rod) ‘\|/-’
print(rod, end' "\r")
sleep(0.25)</syntaxhighlight>
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN
PROC Main()
CHAR ARRAY spin="|/-\"
BYTE i,
CH=$02FC, ;Internal hardware value for last key pressed
CRSINH=$02F0 ;Controls visibility of cursor
Print("Press any key to exit...")
CRSINH=1 ;hide cursor
i=1
WHILE CH=$FF
DO
Put(spin(i))
Put(30) ;move cursor left
i==+1
IF i>spin(0) THEN
i=1
FI
Wait(5)
OD
CH=$FF
CRSINH=0 ;show cursor
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Spinning_rod_animation_text.png Screenshot from Atari 8-bit computer]
<pre>
Press any key to exit.../
</pre>
=={{header|Ada}}==
{{trans|Go}}
<
procedure Spinning_Rod is
Line 65 ⟶ 108:
end loop;
Put (ASCII.ESC & "[?25h"); -- Restore the cursor
end Spinning_Rod;</
=={{header|ALGOL 68}}==
{{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.
<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 #
print( ( CASE 1 + i MOD 4 IN "/", "-", "\", "|" ESAC, REPR 8 ) )
OD</syntaxhighlight>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f SPINNING_ROD_ANIMATION_TEXT.AWK
@load "time"
Line 78 ⟶ 129:
exit(0)
}
</syntaxhighlight>
=={{header|BaCon}}==
<
PRINT CR$, TOKEN$("🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘", x);
x = IIF(x>7, 1, x+1)
SLEEP 250
WEND</
=={{header|Bash}}==
<
for rod in \| / - \\ ; do printf ' %s\r' $rod; sleep 0.25; done
done</
(Added an indent in the printf to better see the spinning rod).
=={{header|BASIC256}}==
<syntaxhighlight lang="freebasic">spinning$ = "|/-" + chr(92)
c = 1
while key = ""
cls
print chr(10) + " hit any key to end program "; mid(spinning$,c,1)
c += 1
pause .250 # in milliseconds
if c = 4 then c = 1
end while</syntaxhighlight>
=={{header|C}}==
{{trans|Go}}
<
#include <time.h>
Line 123 ⟶ 186:
printf("\033[?25h"); // restore the cursor
return 0;
}</
=={{header|C Shell}}==
<
foreach rod ('|' '/' '-' '\')
printf ' %s\r' $rod; sleep 0.25
end
end</
(Added an indent in the printf to better see the spinning rod).
=={{header|Caché ObjectScript}}==
<
; spin 10 times with quarter-second wait
for i = 1:1:10 {
Line 145 ⟶ 208:
}
}
quit</
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(while t
(dolist (char (string-to-list "\\|/-"))
(message "%c" char)
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
procedure SpinningRod(Memo: TMemo);
var I: integer;
const CA: array [0..3] of char = ('|','/','-','\');
begin
LastKey:=#0;
for I:=0 to 1000 do
begin
Memo.SetFocus;
Memo.Lines.Clear;
Memo.Lines.Add(CA[I mod 4]+' - Press Any Key To Stop');
Sleep(250);
if (LastKey<>#0) or Application.Terminated then break;
Application.ProcessMessages;
end;
end;
</syntaxhighlight>
{{out}}
<pre>
/ - Press Any Key To Stop
Elapsed Time: 12.251 Sec.
</pre>
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=Lc09CgIxEAXgfk7xWCwUYcmuaOdJxEKyAwZMAkkQ8Qw2/tt5RY9gHtp8w4M3M3a0WmOJXJLdblJG83mfzqhcyJXcyJ08yJO8Gil6KNkdFQsjPu4VvcHMSAwozmsSAC4M9faYY4puAh+HDjsNsPUrC7zBUBu/zE2Ytp9LK/8gXw== Run it]
<syntaxhighlight>
c$[] = strchars "🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘"
textsize 60
move 20 30
on timer
ind = (ind + 1) mod1 len c$[]
text c$[ind]
timer 0.25
.
timer 0
</syntaxhighlight>
=={{header|Factor}}==
<
threads ;
[
"\\|/-" [ "%c\r" printf flush 1/4 seconds sleep ] each
] forever</
=={{header|Forth}}==
Tested in gforth 0.7.9
<
: rod
cr
Line 178 ⟶ 286:
;
rod
</syntaxhighlight>
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}}
<syntaxhighlight lang="text">
include lib/yield.4th
: spin 8 emit emit sync ; ( c --)
: spinner ( --)
begin
[char] | spin yield [char] / spin yield
[char] - spin yield [char] \ spin yield
again
;
( n -- n+1 f)
: payload 10000000 0 do loop dup 1+ swap 100 < ;
\ dummy task
: test
." Wait for it.. " spinner 0 \ start coroutine
begin payload while yield repeat \ show spinner while doing it
drop grab bl spin cr \ grab control, finish spinner
." Done!" cr \ all done
;
test
</syntaxhighlight>
=={{header|FreeBASIC}}==
<
' compile with: fbc -s console
Dim As String spinning_rod = "|/-
Dim As UInteger c
Line 197 ⟶ 330:
Wend
End</
=={{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.
<
wait 250 ms
debug="/"
Line 208 ⟶ 341:
wait 250 ms
debug="\"
wait 250 ms</
=={{header|Go}}==
{{works with|Ubuntu 16.04}}
<
import (
Line 237 ⟶ 370:
}
fmt.Print("\033[?25h") // restore the cursor
}</
=={{header|Haskell}}==
Uses the terminfo library to make the cursor invisible, if possible.
<
import Control.Exception (bracket_)
import Control.Monad (forM_)
Line 268 ⟶ 401:
putStrLn "Spinning rod demo. Hit ^C to stop it.\n"
term <- setupTermFromEnv
bracket_ (cursorOff term) (cursorOn term) spin</
=={{header|J}}==
Assuming linux as the host:
<syntaxhighlight lang=J>cout=: 1!:2&(<'/proc/self/fd/1')
dl=: 6!:3
spin=: {{ while. do. for_ch. y do. dl x [ cout 8 u:ch,CR end. end. }} 9 u:"1 ]</syntaxhighlight>
The initial task example becomes:
<syntaxhighlight lang=J>0.25 spin '|/-\'</syntaxhighlight>
Assuming you have terminal support for the hour wingdings, this would also work:
<syntaxhighlight lang=J>0.25 spin '🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛🕜🕝🕞🕟🕠🕡🕢🕣🕤🕥🕦🕧'</syntaxhighlight>
or
<syntaxhighlight lang=J>0.25 spin a.{~240 159 149&,&>144+i.24</syntaxhighlight>
Note also that you could animate lines of text rather than individual characters. For example, converting words to lines:
<syntaxhighlight lang=J>0.5 spin >;:'this is a test'</syntaxhighlight>
However, anything which takes multiple lines wouldn't work here. For that you'd need to clear the screen instead of using a simple carriage return. (Clearing the screen is completely doable, but the easy approaches are either embedded in gui mechanisms which sort of defeats the purpose of ascii art animation, or are not supported by some "purely textual" terminals.)
=={{header|Java}}==
{{trans|Go}}
<
{
public static void main(String[] args) throws InterruptedException {
Line 293 ⟶ 449:
System.out.print("\033[?25h"); // restore the cursor
}
}</
=={{header|Javascript}}==
Node JS:
<
const rod = (function rod() {
const chars = "|/-\\";
Line 308 ⟶ 464:
})();
setInterval(rod, 250);
</syntaxhighlight>
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]] and [[#Python|Python]]'''
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq, and with fq.'''
'''Generic Utilities'''
Invocation:
<pre>
jq --unbuffered -nrf spinning-rod-animation.jq
gojq -nrf spinning-rod-animation.jq
fq -nrf spinning-rod-animation.jq
</pre>
''' spinning-rod-animation.jq'''
<syntaxhighlight lang=jq>
def pause($seconds):
(now + $seconds)
| until( now > . ; .);
# Specify $n as null for an infinite spin
def animation($n):
def ESC: "\u001b";
def hide: "\(ESC)[?25l"; # hide the cursor
def restore: "\(ESC)[?25h"; # restore the cursor;
def a: "🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘";
hide,
"\(ESC)[2J\(ESC)[H", # clear, place cursor at top left corner
(range(0; $n // infinite) as $_
| a as $a
| pause(0.05)
| "\r\($a)" ),
restore;
animation(10)
</syntaxhighlight>
=={{header|Julia}}==
{{trans|Python}}
<
for rod in "\|/-" # this needs to be a string, a char literal cannot be iterated over
print(rod,'\r')
Line 318 ⟶ 510:
end
end
</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|Go}}
<
const val ESC = "\u001b"
Line 344 ⟶ 536:
}
print("$ESC[?25h") // restore the cursor
}</
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{pre
{@ id="spin"
style="text-align:center;
font:bold 3.0em arial;"}
|}
{script
var i = 0,
c = "|/─\\";
var spin = function() {
document.getElementById("spin").innerHTML = c[i];
i = (i+1) % c.length;
};
setTimeout(spin,1);
setInterval(spin,250)
}
</syntaxhighlight>
=={{header|Lua}}==
<syntaxhighlight lang="lua">
--
-- Simple String Animation - semi-hard-coded variant - you can alter the chars table - update the count and run it...
Line 438 ⟶ 651:
_data.anim, _data.count, _data.index, _data.expiry = _tab, nil, nil, nil;
end
</syntaxhighlight>
Usage:
<syntaxhighlight lang="lua">
-- 1 second delay, going backwards.
print( string.BasicAnimation( 1, true ) );
Line 453 ⟶ 666:
-- 1 second delay going backwards
print( string.BasicAnimation( 1 ) );
</syntaxhighlight>
==
<syntaxhighlight lang="lua">
--
-- Simple String Animation - Josh 'Acecool' Moser under modified ACL - Free to use, modify and learn from.
Line 800 ⟶ 1,013:
return _char, _has_frame_advanced;
end
</syntaxhighlight>
<br />
Line 806 ⟶ 1,019:
<br />
<syntaxhighlight lang="lua">
--
-- In some HUD element, or where text is output... such as 'Loading' ... try:
Line 822 ⟶ 1,035:
-- In this example print would be draw.Text or something along those lines.
print( 'Loading' .. string.SimpleAnimation( STRING_ANIMATION_DOTS ) );
</syntaxhighlight>
<br />
Line 828 ⟶ 1,041:
<br />
<syntaxhighlight 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
Line 871 ⟶ 1,084:
end
end
</syntaxhighlight>
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Module Checkit {
n$=lambda$ n=1, a$="|/-\" -> {
Line 896 ⟶ 1,102:
CheckIt
</syntaxhighlight>
<syntaxhighlight lang="m2000 interpreter">
Module Checkit {
n=1
Line 910 ⟶ 1,116:
CheckIt
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">chars = "|/\[Dash]\\";
pos = 1;
Dynamic[c]
While[True,
pos = Mod[pos + 1, StringLength[chars], 1];
c = StringTake[chars, {pos}];
Pause[0.25];
]</syntaxhighlight>
=={{header|MelonBasic}}==
<
Delete:1
Say:/
Line 924 ⟶ 1,140:
Wait:0.25
Delete:1
Goto:1</
=={{header|Microsoft Small Basic}}==
<
a[2]="/"
a[3]="-"
Line 938 ⟶ 1,154:
Program.Delay(250)
EndFor
EndWhile</
=={{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]:
<
while true
for c in "|/-\"
Line 948 ⟶ 1,164:
wait 0.25
end for
end while</
And here's a version that will work with command-line MiniScript, running on a terminal that interprets standard VT100 escape sequences:
<
for c in "|/-\"
print c
Line 957 ⟶ 1,173:
print char(27) + "[2A" // move cursor up 2 lines
end for
end while</
=={{header|Nim}}==
{{trans|Kotlin}}
With some modifications.
<syntaxhighlight lang="nim">import std/monotimes, times, os
const A = ["|", "/", "—", "\\"]
stdout.write "$\e[?25l" # Hide the cursor.
let start = getMonoTime()
while true:
for s in A:
stdout.write "$\e[2J" # Clear terminal.
stdout.write "$\e[0;0H" # Place cursor at top left corner.
for _ in 1..40:
stdout.write s & ' '
stdout.flushFile
os.sleep(250)
let now = getMonoTime()
if (now - start).inSeconds >= 5:
break
echo "$\e[?25h" # Restore the cursor.</syntaxhighlight>
=={{header|NS-HUBASIC}}==
The 0.25 second delay assumes the program is running at 60 frames per second.
<
20 A(1)=236
30 A(2)=234
Line 971 ⟶ 1,208:
90 PAUSE 15
100 NEXT
110 GOTO 60</
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let rec sym = '-' :: '\\' :: '|' :: '/' :: sym
let () = List.iter (fun c -> Printf.printf "%c%!\b" c; Unix.sleepf 0.25) sym</syntaxhighlight>
=={{header|Perl}}==
The statement <code>$| =1</code> is required in order to disable output buffering.
<
while () {
Line 982 ⟶ 1,224:
printf "\r ($_)";
}
}</
Extending it for moon phases:
<syntaxhighlight lang="perl">$|=1;
binmode STDOUT, ":utf8";
while () {
for (map { $_ + 1 } 0x1F310 .. 0x1F317) {
# creating array of sequential Unicode codepoints for the emoji;
# it's equal to qw[🌕 🌖 🌗 🌘 🌑 🌒 🌓 🌔 🌕 ] but comes handy for
# implementing clock faces or any other codepoint ranges.
select undef, undef, undef, 0.25;
# all the magic of this thing; switches between three file handles every 0.25s
print "\r @{[chr]}"
# string/variable interpolation;
# (1) chr without param works on `$_`
# (2) `[]` creates a singleton list
# (3) `@{}` dereferences the created list.
}
}</syntaxhighlight>
=={{header|Phix}}==
=== 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: #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;">cursor</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NO_CURSOR</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">10</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (approx 10 seconds)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">4</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" \b%c\b"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`|/-\`</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">])</span>
<span style="color: #7060A8;">sleep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0.25</span><span style="color: #0000FF;">)</span>
<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>
<!--</syntaxhighlight>-->
=== GUI version ===
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
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;">--
-- demo\rosetta\Spinning_rod_animation.exw
-- =======================================
--</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> <span style="color: #000080;font-style:italic;">-- just about works under pwa/p2js, but
-- layout/re-sizing is a bit naff [DEV]
-- A trailing '!' makes it a "ping/pong":</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">animations</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #008000;">`Dots`</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">`.`</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`..`</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`...`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">'!'</span><span style="color: #0000FF;">}},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">`Pipes`</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`|/─\`</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">`Stars`</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`⁎⁑⁂!`</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">`Clock`</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`🕛🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚`</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">`Arrows`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`⬍⬈➞⬊⬍⬋⬅⬉`</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">`Bird`</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`︷︵︹︺︶︸!`</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">`Plants`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`☘❀❁!`</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #008000;">`Eclipse`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`🌑🌒🌓🌔🌕🌖🌗🌘`</span><span style="color: #0000FF;">}}</span>
<span style="color: #004080;">sequence</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">anames</span><span style="color: #0000FF;">,</span><span style="color: #000000;">anims</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #000000;">animations</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">-- convert anims to "single chars" in utf8 if needed</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anims</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #004080;">string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anims</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">ai</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">utf8_to_utf32</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anims</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #004080;">string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ai</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ai</span><span style="color: #0000FF;">)-(</span><span style="color: #000000;">ai</span><span style="color: #0000FF;">[$]==</span><span style="color: #008000;">'!'</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">ai</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">utf32_to_utf8</span><span style="color: #0000FF;">({</span><span style="color: #000000;">ai</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">anims</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">ai</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">andx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- index to anames/anims</span>
<span style="color: #000000;">adx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- index within anims[andx]</span>
<span style="color: #000000;">direction</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">state</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">label</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">radios</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">stopstart</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">timer</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">timer_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*timer*/</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">anim</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">anims</span><span style="color: #0000FF;">[</span><span style="color: #000000;">andx</span><span style="color: #0000FF;">]</span>
<span style="color: #004080;">bool</span> <span style="color: #000000;">bounce</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">anim</span><span style="color: #0000FF;">[$]=</span><span style="color: #008000;">'!'</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anim</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">bounce</span>
<span style="color: #000000;">adx</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">direction</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">adx</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">adx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">direction</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">adx</span><span style="color: #0000FF;">></span><span style="color: #000000;">l</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">bounce</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">direction</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span>
<span style="color: #000000;">adx</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">adx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</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>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">state</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">anim</span><span style="color: #0000FF;">[</span><span style="color: #000000;">adx</span><span style="color: #0000FF;">]&</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CONTINUE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">radiochanged_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ih</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- (ignore "unsets")</span>
<span style="color: #000000;">andx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ih</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">anames</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">adx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">direction</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">cb_radiochanged</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"radiochanged_cb"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">stopstart_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">title</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ih</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">titles</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Start"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Stop"</span><span style="color: #0000FF;">}</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">tdx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">title</span><span style="color: #0000FF;">,</span><span style="color: #000000;">titles</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">timer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"RUN"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">tdx</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ih</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">titles</span><span style="color: #0000FF;">[</span><span style="color: #000000;">3</span><span style="color: #0000FF;">-</span><span style="color: #000000;">tdx</span><span style="color: #0000FF;">])</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">state</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"asleep"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CONTINUE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupSetGlobal</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"UTF8MODE"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"YES"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">state</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"asleep"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">radioset</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anames</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">radiobtn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupToggle</span><span style="color: #0000FF;">(</span><span style="color: #000000;">anames</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span>
<span style="color: #000000;">radioset</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">radioset</span><span style="color: #0000FF;">,</span><span style="color: #000000;">radiobtn</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">IupSetCallback</span><span style="color: #0000FF;">(</span><span style="color: #000000;">radioset</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUECHANGED_CB"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cb_radiochanged</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">radios</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupRadio</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">(</span><span style="color: #000000;">radioset</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">stopstart</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupButton</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Start"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"stopstart_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">IupVbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"state: "</span><span style="color: #0000FF;">),</span><span style="color: #000000;">state</span><span style="color: #0000FF;">},</span><span style="color: #008000;">"ALIGNMENT=ACENTER"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">radios</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">stopstart</span><span style="color: #0000FF;">})},</span><span style="color: #008000;">"MARGIN=10x10"</span><span style="color: #0000FF;">),</span>
<span style="color: #008000;">`TITLE="Spinning rod animation", MINSIZE=400x200`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttributeHandle</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"STARTFOCUS"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">stopstart</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (DEV not p2js, just yet)</span>
<span style="color: #000000;">timer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupTimer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"timer_cb"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">250</span><span style="color: #0000FF;">,</span><span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</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>
<!--</syntaxhighlight>-->
=={{header|PicoLisp}}==
<syntaxhighlight lang="lisp">
(de rod ()
(until ()
Line 1,003 ⟶ 1,374:
(prin R (wait 250) "\r")(flush) ) ) )
(rod)
</syntaxhighlight>
=={{header|Python}}==
<
while True:
for rod in r'\|/-':
print(rod, end='\r')
sleep(0.25)</
=={{header|Racket}}==
<
#lang racket
(define (anim)
Line 1,021 ⟶ 1,392:
(anim))
(anim)
</syntaxhighlight>
=={{header|Raku}}==
Line 1,030 ⟶ 1,401:
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.
<syntaxhighlight lang="raku"
has @.frames;
has $.delay is rw = 0;
Line 1,073 ⟶ 1,444:
print $scroll.next for ^95;
END { print "\e[?25h\n" } # clean up on exit</
=={{header|REXX}}==
Line 1,083 ⟶ 1,454:
::* R4 REXX
::* ROO REXX
::* Regina REXX (see the programming note below.)
<
if 4=='f4'x then bs= "16"x /*EBCDIC? Then use this backspace chr.*/
Line 1,094 ⟶ 1,465:
call charout , bs || substr($, 1 + j//length($), 1)
call delay .25 /*delays a quarter of a second. */
if result==1 then leave /*see if HALT was issued during DELAY*/
end /*j*/
halt: say bs ' ' /*stick a fork in it, we're all done. */</
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]].
=={{header|Ring}}==
<
rod = ["|", "/", "-", "\"]
for n = 1 to len(rod)
Line 1,107 ⟶ 1,479:
sleep(0.25)
system("cls")
next</
Output:
|
Line 1,115 ⟶ 1,487:
=={{header|Ruby}}==
Chars taken from the Raku example.
<syntaxhighlight lang="ruby">def spinning_rod
begin
printf("\033[?25l") # Hide cursor
print rod
sleep 0.25
print "\
end
ensure
Line 1,130 ⟶ 1,503:
puts "Ctrl-c to stop."
spinning_rod
</syntaxhighlight>
=={{header|Rust}}==
<
let characters = ['|', '/', '-', '\\'];
let mut current = 0;
Line 1,146 ⟶ 1,519:
std::thread::sleep(std::time::Duration::from_millis(250)); // Sleep 250 ms.
}
}</
=={{header|Scala}}==
<
val start = System.currentTimeMillis
Line 1,165 ⟶ 1,538:
print("\033[?25h") // restore the cursor
}</
=={{header|ScratchScript}}==
<
delay 0.25
clear
Line 1,178 ⟶ 1,551:
clear
print "\"
delay 0.25</
=={{header|SimpleCode}}==
<syntaxhighlight lang="simplecode">dtxt
|
wait
Line 1,202 ⟶ 1,575:
\
wait
0.25</
=={{header|True BASIC}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">DEF Inkey$
LOCAL t_arg1
IF key input then
GET KEY t_arg1
IF t_arg1 <= 255 then
LET inkey$ = chr$(t_arg1)
ELSE
LET inkey$ = chr$(0) & chr$(t_arg1-256)
END IF
ELSE
LET inkey$ = ""
END IF
END DEF
LET spinning$ = "|/-" & chr$(92)
DO while inkey$ = ""
CLEAR
PRINT
PRINT " hit any key to end program ";
PRINT (spinning$)[c:c+1-1]
LET c = c+1
PAUSE .25 ! in milliseconds
IF c = 4 THEN LET c = 1
LOOP
END</syntaxhighlight>
=={{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.
<
sub delay:
for i=1 to 10000
Line 1,222 ⟶ 1,625:
gosub delay:
wend
end</
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="wren">import "io" for Stdout
import "timer" for Timer
var a = "|/-\\"
System.write("\e[?25l") // hide the cursor
var start = System.clock
var asleep = 0
while (true) {
for (i in 0..3) {
System.write("\e[2J") // clear terminal
System.write("\e[0;0H") // place cursor at top left corner
for (j in 0..79) { // 80 character terminal width, say
System.write(a[i])
}
Stdout.flush()
Timer.sleep(250) // suspends both current fiber & System.clock
asleep = asleep + 250
}
var now = System.clock
// stop after 20 seconds, say
if (now * 1000 + asleep - start * 1000 >= 20000) break
}
System.print("\e[?25h") // restore the cursor</syntaxhighlight>
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">char I, Rod;
[Rod:= "|/-\ ";
loop for I:= 0 to 3 do
[ChOut(0, Rod(I));
DelayUS(250_000);
ChOut(0, $08\BS\);
if KeyHit then quit;
];
]</syntaxhighlight>
=={{header|zkl}}==
{{trans|C Shell}}
<
print(" %s\r".fmt(rod));
Atomic.sleep(0.25);
}</
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).
Line 1,236 ⟶ 1,676:
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.
<
try{
foreach n,rod in ((1).MAX, "\\|/-"){
Line 1,243 ⟶ 1,683:
}
}catch{} // don't complain about uncaught exception that stops thread
}</
<
spinner:=spin.launch(); // start spinner thread, returns reference to thread
Atomic.sleep(10); // do stuff
vm.kick(spinner.value); // stop thread by throwing exception at it</
=={{header|ZX Spectrum Basic}}==
<
20 FOR C=1 TO 4
30 PRINT AT 0,0;A$(C)
Line 1,256 ⟶ 1,696:
50 NEXT C
60 GOTO 20
</syntaxhighlight>
|