Spinning rod animation/Text: Difference between revisions

(Spinning rod animation/Text in BASIC-256)
Line 394:
})();
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 $_
| range(0; 4) as $i
| pause(0.05)
| "\r\(a[$i:$i+1])" ),
restore;
 
animation(10)
</syntaxhighlight>
 
2,442

edits