Spinning rod animation/Text: Difference between revisions

Added Easylang
(add lambdatalk code)
(Added Easylang)
 
(11 intermediate revisions by 6 users not shown)
Line 215:
(message "%c" char)
(sit-for 0.25)))</syntaxhighlight>
 
=={{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}}==
Line 355 ⟶ 402:
term <- setupTermFromEnv
bracket_ (cursorOff term) (cursorOn term) spin</syntaxhighlight>
 
=={{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}}==
Line 1,139 ⟶ 1,209:
100 NEXT
110 GOTO 60</syntaxhighlight>
 
=={{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}}==
Line 1,412 ⟶ 1,487:
 
=={{header|Ruby}}==
Chars taken from the Raku example.
<syntaxhighlight lang="ruby">def spinning_rod
begin
printf("\033[?25l") # Hide cursor
%w[| / - \\]'🌑🌒🌓🌔🌕🌖🌗🌘'.chars.cycle do |rod|
print rod
sleep 0.25
print "\br"
end
ensure
Line 1,553 ⟶ 1,629:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdout
import "timer" for Timer
 
var ESC = "\u001b"
 
var a = "|/-\\"
System.write("%(ESC)\e[?25l") // hide the cursor
var start = System.clock
var asleep = 0
while (true) {
for (i in 0..3) {
System.write("%(ESC)\e[2J") // clear terminal
System.write("%(ESC)\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
}
Line 1,577 ⟶ 1,651:
if (now * 1000 + asleep - start * 1000 >= 20000) break
}
System.print("%(ESC)\e[?25h") // restore the cursor</syntaxhighlight>
 
=={{header|XPL0}}==
2,069

edits