Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Spinning_rod_animation/Text
note: Spinning rod animation/Text

View file

@ -0,0 +1,40 @@
;Task:
An animation with the following frames in the following order (if certain characters aren't available or can't be used correctly in the programming language, alternate characters can replace any of these frames) must animate with a delay of 0.25 seconds between each frame, with the previous frame being cleared before the next frame appears: <big>
:* &nbsp; |
:* &nbsp; /
:* &nbsp; - or ─
:* &nbsp; \
</big>
<br />
A stand-alone version that loops and/or a version that doesn't loop can be made. These examples can also be converted into a system used in game development which is called on a HUD or GUI element requiring it to be called each frame to output the text, and advance the frame when the frame delay has passed. You can also use alternate text such as the . animation ( . | .. | ... | .. | repeat from . ) or the logic can be updated to include a ping/pong style where the frames advance forward, reach the end and then play backwards and when they reach the beginning they start over ( technically, you'd stop one frame prior to prevent the first frame playing twice, or write it another way ).<br />
<br />
There are many different ways you can incorporate text animations. Here are a few text ideas - each frame is in quotes. If you can think of any, add them to this page! There are 2 examples for several of these; the first is the base animation with only unique sets of characters. The second consists of the primary set from a - n and doubled, minus the first and last element ie: We only want the center. This way an animation can play forwards, and then in reverse ( ping ponging ) without having to code that feature. For the animations with 3 elements, we only add 1, the center. with 4, it becomes 6. with 10, it becomes 18.<br />
<br />
We don't need the second option for some of the animations if they connect smoothly, when animated, back to the first element. ... doesn't connect with . cleanly - there is a large leap. The rotating pipe meets the first perfectly so it isn't necessary, etc..
<br />
<br />
:* &nbsp; Dots - Option A requires ping / pong enabled script. Option B just adds the elements in the center.
:** &nbsp; '.', '..', '...'
:** &nbsp; '.', '..', '...', '..'
:* &nbsp; Pipe - This has the uniform sideways pipe instead of a hyphen to prevent non-uniform sizing.
:** &nbsp; '|', '/', '─', '\'
:* &nbsp; Stars - Option A requires ping / pong enabled script. Option B just adds the elements from the center.
:** &nbsp; '', '⁑', '⁂'
:** &nbsp; '', '⁑', '⁂', '⁑'
:* &nbsp; Clock - These need to be ordered. I haven't done this yet as the application I was testing the system in doesn't support these wingdings / icons. But this would look quite nice and you could set it up to go forward, or backward during an undo process, etc..
:** &nbsp; '🕛', '🕧', '🕐', '🕜', '🕑', '🕝', '🕒', '🕞', '🕓', '🕟', '🕔', '🕠', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚', '🕡', '🕢', '🕣', '🕤', '🕥', '🕦'
:* &nbsp; Arrows:
:** &nbsp; '⬍', '⬈', '➞', '⬊', '⬍', '⬋', '⬅', '⬉'
:* &nbsp; Bird - This looks decent but may be missing something.
:** &nbsp; '︷', '︵', '︹', '︺', '︶', '︸'
:** &nbsp; '︷', '︵', '︹', '︺', '︶', '︸', '︶', '︺', '︹', '︵'
:* &nbsp; Plants - This isn't quite complete
:** &nbsp; '☘', '❀', '❁'
:** &nbsp; '☘', '❀', '❁', '❀'
:* &nbsp; Eclipse - From Raku Throbber post author
:** &nbsp; '🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘'
<br />
<br />

View file

@ -0,0 +1,4 @@
L
L(rod) \|/-
print(rod, end' "\r")
sleep(0.25)

View file

@ -0,0 +1,4 @@
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

View file

@ -0,0 +1,9 @@
# syntax: GAWK -f SPINNING_ROD_ANIMATION_TEXT.AWK
@load "time"
BEGIN {
while (1) {
printf(" %s\r",substr("|/-\\",x++%4+1,1))
sleep(.25)
}
exit(0)
}

View file

@ -0,0 +1,28 @@
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

View file

@ -0,0 +1,23 @@
with Ada.Text_IO;
procedure Spinning_Rod is
use Ada.Text_IO;
type Index_Type is mod 4;
Rod : constant array (Index_Type) of Character := ('|', '/', '-', '\');
Index : Index_Type := 0;
Char : Character;
Avail : Boolean;
begin
Put (ASCII.ESC & "[?25l"); -- Hide the cursor
loop
Put (ASCII.ESC & "[2J"); -- Clear Terminal
Put (ASCII.ESC & "[0;0H"); -- Place Cursor at Top Left Corner
Get_Immediate (Char, Avail);
exit when Avail;
Put (Rod (Index));
Index := Index_Type'Succ (Index);
delay 0.250;
end loop;
Put (ASCII.ESC & "[?25h"); -- Restore the cursor
end Spinning_Rod;

View file

@ -0,0 +1,10 @@
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

View file

@ -0,0 +1,5 @@
WHILE TRUE
PRINT CR$, TOKEN$("🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘", x);
x = IIF(x>7, 1, x+1)
SLEEP 250
WEND

View file

@ -0,0 +1,5 @@
while 1
foreach rod ('|' '/' '-' '\')
printf ' %s\r' $rod; sleep 0.25
end
end

View file

@ -0,0 +1,29 @@
#include <stdio.h>
#include <time.h>
int main() {
int i, j, ms = 250;
const char *a = "|/-\\";
time_t start, now;
struct timespec delay;
delay.tv_sec = 0;
delay.tv_nsec = ms * 1000000L;
printf("\033[?25l"); // hide the cursor
time(&start);
while(1) {
for (i = 0; i < 4; i++) {
printf("\033[2J"); // clear terminal
printf("\033[0;0H"); // place cursor at top left corner
for (j = 0; j < 80; j++) { // 80 character terminal width, say
printf("%c", a[i]);
}
fflush(stdout);
nanosleep(&delay, NULL);
}
// stop after 20 seconds, say
time(&now);
if (difftime(now, start) >= 20) break;
}
printf("\033[?25h"); // restore the cursor
return 0;
}

View file

@ -0,0 +1,15 @@
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;

View file

@ -0,0 +1,4 @@
(while t
(dolist (char (string-to-list "\\|/-"))
(message "%c" char)
(sit-for 0.25)))

View file

@ -0,0 +1,6 @@
USING: calendar combinators.extras formatting io sequences
threads ;
[
"\\|/-" [ "%c\r" printf flush 1/4 seconds sleep ] each
] forever

View file

@ -0,0 +1,12 @@
: rod
cr
begin
[char] \ emit 250 ms
13 emit [char] | emit 250 ms
13 emit [char] - emit 250 ms
13 emit [char] / emit 250 ms
13 emit
key?
until
;
rod

View file

@ -0,0 +1,21 @@
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

View file

@ -0,0 +1,17 @@
' version 13-07-2018
' compile with: fbc -s console
Dim As String spinning_rod = "|/-" + Chr(92)
Dim As UInteger c
While InKey <> "" : Wend
While InKey = ""
Cls
Print
Print " hit any key to end program "; Chr(spinning_rod[c And 3])
c += 1
Sleep(250) ' in milliseconds
Wend
End

View file

@ -0,0 +1,8 @@
debug="|"
wait 250 ms
debug="/"
wait 250 ms
debug="-"
wait 250 ms
debug="\"
wait 250 ms

View file

@ -0,0 +1,26 @@
package main
import (
"fmt"
"time"
)
func main() {
a := `|/-\`
fmt.Printf("\033[?25l") // hide the cursor
start := time.Now()
for {
for i := 0; i < 4; i++ {
fmt.Print("\033[2J") // clear terminal
fmt.Printf("\033[0;0H") // place cursor at top left corner
for j := 0; j < 80; j++ { // 80 character terminal width, say
fmt.Printf("%c", a[i])
}
time.Sleep(250 * time.Millisecond)
}
if time.Since(start).Seconds() >= 20.0 { // stop after 20 seconds, say
break
}
}
fmt.Print("\033[?25h") // restore the cursor
}

View file

@ -0,0 +1,28 @@
import Control.Concurrent (threadDelay)
import Control.Exception (bracket_)
import Control.Monad (forM_)
import System.Console.Terminfo
import System.IO (hFlush, stdout)
-- Use the terminfo database to write the terminal-specific characters
-- for the given capability.
runCapability :: Terminal -> String -> IO ()
runCapability term cap =
forM_ (getCapability term (tiGetOutput1 cap)) (runTermOutput term)
-- Control the visibility of the cursor.
cursorOff, cursorOn :: Terminal -> IO ()
cursorOff term = runCapability term "civis"
cursorOn term = runCapability term "cnorm"
-- Print the spinning cursor.
spin :: IO ()
spin = forM_ (cycle "|/-\\") $ \c ->
putChar c >> putChar '\r' >>
hFlush stdout >> threadDelay 250000
main :: IO ()
main = do
putStrLn "Spinning rod demo. Hit ^C to stop it.\n"
term <- setupTermFromEnv
bracket_ (cursorOff term) (cursorOn term) spin

View file

@ -0,0 +1,3 @@
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 ]

View file

@ -0,0 +1 @@
0.25 spin '|/-\'

View file

@ -0,0 +1 @@
0.25 spin '🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛🕜🕝🕞🕟🕠🕡🕢🕣🕤🕥🕦🕧'

View file

@ -0,0 +1 @@
0.25 spin a.{~240 159 149&,&>144+i.24

View file

@ -0,0 +1 @@
0.5 spin >;:'this is a test'

View file

@ -0,0 +1,22 @@
public class SpinningRod
{
public static void main(String[] args) throws InterruptedException {
String a = "|/-\\";
System.out.print("\033[2J"); // hide the cursor
long start = System.currentTimeMillis();
while (true) {
for (int i = 0; i < 4; i++) {
System.out.print("\033[2J"); // clear terminal
System.out.print("\033[0;0H"); // place cursor at top left corner
for (int j = 0; j < 80; j++) { // 80 character terminal width, say
System.out.print(a.charAt(i));
}
Thread.sleep(250);
}
long now = System.currentTimeMillis();
// stop after 20 seconds, say
if (now - start >= 20000) break;
}
System.out.print("\033[?25h"); // restore the cursor
}
}

View file

@ -0,0 +1,10 @@
const rod = (function rod() {
const chars = "|/-\\";
let i=0;
return function() {
i= (i+1) % 4;
// We need to use process.stdout.write since console.log automatically adds a \n to the end of lines
process.stdout.write(` ${chars[i]}\r`);
}
})();
setInterval(rod, 250);

View file

@ -0,0 +1,20 @@
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)

View file

@ -0,0 +1,6 @@
while true
for rod in "\|/-" # this needs to be a string, a char literal cannot be iterated over
print(rod,'\r')
sleep(0.25)
end
end

View file

@ -0,0 +1,23 @@
// Version 1.2.50
const val ESC = "\u001b"
fun main(args: Array<String>) {
val a = "|/-\\"
print("$ESC[?25l") // hide the cursor
val start = System.currentTimeMillis()
while (true) {
for (i in 0..3) {
print("$ESC[2J") // clear terminal
print("$ESC[0;0H") // place cursor at top left corner
for (j in 0..79) { // 80 character terminal width, say
print(a[i])
}
Thread.sleep(250)
}
val now = System.currentTimeMillis()
// stop after 20 seconds, say
if (now - start >= 20000) break
}
print("$ESC[?25h") // restore the cursor
}

View file

@ -0,0 +1,17 @@
{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)
}

View file

@ -0,0 +1,88 @@
--
-- Simple String Animation - semi-hard-coded variant - you can alter the chars table - update the count and run it...
--
-- The basic animation runtime controller. This is where you assign the active animation ( you could create a simple function to replace the animation table and nil count, index and expiry to extend this system to allow multiple animations -
-- and since you can replace after a previous has been output, it would appear as though you were running different animations at the same time - that wouldn't be async compatible though )...
-- So you can either activate the animation you want permanently, or create a simple function to update the animation table and reset the control variables... ie: ( function string.SetBasicAnimation( _tab_of_chars ) string.__basic_anim_runtime.anim = _tab_of_chars; string.__basic_anim_runtime.index = nil; string.__basic_anim_runtime.count = nil; string.__basic_anim_runtime.expiry = nil; end )
string.__basic_anim_runtime = {
-- The animation - can not ping pong... requires full sequence. Resets to first after full sequence. Dots animation.. Requires center segment because of ping / pong
anim = { '.', '..', '...', '..' };
-- Pipes animation - This performs a complete rotation, no need to add extra segments.
-- anim = { '|', '/', '─', '\\' };
-- Stars - This is reversible so requires the center segments..
-- anim = { '', '⁑', '⁂', '⁑' };
-- Clock - This still needs to be ordered...
-- anim = { '🕛', '🕧', '🕐', '🕜', '🕑', '🕝', '🕒', '🕞', '🕓', '🕟', '🕔', '🕠', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚', '🕡', '🕢', '🕣', '🕤', '🕥', '🕦' };
-- Arrows - This does a complete circle and doesn't need to reverse
-- anim = { '⬍', '⬈', '➞', '⬊', '⬍', '⬋', '⬅', '⬉' };
-- Bird Flying - this is reversible so it requires all.. 1 2 3 4 5 6 5 4 3 2
-- anim = { '︷', '︵', '︹', '︺', '︶', '︸', '︶', '︺', '︹', '︵' };
-- Plants - Set as reversible, requires all..
-- anim = { '☘', '❀', '❁', '❀' };
-- Eclipse - From Raku Throbber post author
-- anim = { '🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘' };
};
--
-- The basic animator function - accepts a numerical delay and a boolean backwards switch.. It only accepts a single animation from the helper local table above..
--
-- Argument - _delay - <Number> - Accepts a time, in seconds with fraction support, that designates how long a frame should last. Optional. If no number given, it uses the default value of 1 / 8 seconds.
-- Argument - _play_backwards - <Boolean> - Toggles whether or not the animation plays backwards or forwards. Default is forwards. Optional.
--
-- RETURN: <String> - Character( s ) of the current animation frame - if the frame is invalid, it returns an empty string.
-- RETURN: <Boolean> - Has Advanced Frame Controller - set to true if this call resulted in a new frame / index being assigned with new character( s )
--
function string.BasicAnimation( _delay, _play_backwards )
-- Setup delay - make sure it is a number and Reference our runtime var
local _delay = ( ( type( _delay ) == 'number' ) and _delay or 1 / 8 ), string.__basic_anim_runtime, os.clock( );
-- cache our count so we count once per refresh.
_data.count = ( type( _data.count ) == 'number' ) and _data.count or #_data.anim;
-- Setup our helpers...
local _expiry, _index, _chars, _count, _has_advanced_frame = _data.expiry, ( _data.index or ( _play_backwards and _data.count or 1 ) ), _data.anim, _data.count, false;
-- If expiry has occurred, advance... Expiry can be nil the first call, this is ok because it will just use the first character - or the last if playing backwards.
if ( _expiry and _expiry < _time ) then
-- Advance..
_index, _has_advanced_frame = ( ( _index + ( 1 * ( _play_backwards and -1 or 1 ) ) ) % ( _count + 1 ) ), true;
-- If 0, add 1 otherwise keep the same.
_index = _index < 1 and ( _play_backwards and _count or 1 ) or _index;
-- Update the index
_data.index = _index;
end
-- Update the trackers and output the char. -- Note: This is best done in the loop, but since we are checking the expiry above I decided to integrate it here.
_data.expiry = ( not _data.expiry or _has_advanced_frame ) and _time + _delay or _data.expiry;
-- Return the character at the index or nothing.
return _chars[ _index ] or '', _has_advanced_frame;
end
--
-- Helper / OPTIONAL FUNCTION - Updates the animation and resets the controlling variables
--
-- Argument: _tab - <Table> - This is the table containing the animation characters... ie: { '.', '..', '...', '..' } would be a valid entry. Requires at least 2 entries.
--
function string.SetBasicAnimation( _tab )
-- Prevent non tables, empty tables, or tables with only 1 entry.
if not ( type( _tab ) == 'table' and #_tab > 1 ) then return error( 'Can not update basic animation without argument #1 as a table, with at least 2 entries...' ); end
-- Helper
local _data = string.__basic_anim_runtime;
-- Update the animation table and Clear the controllers...
_data.anim, _data.count, _data.index, _data.expiry = _tab, nil, nil, nil;
end

View file

@ -0,0 +1,11 @@
-- 1 second delay, going backwards.
print( string.BasicAnimation( 1, true ) );
-- Default delay going backwards
print( string.BasicAnimation( nil, true ) );
-- Default delay, moving forwards
print( string.BasicAnimation( ) );
-- 1 second delay going backwards
print( string.BasicAnimation( 1 ) );

View file

@ -0,0 +1,342 @@
--
-- Simple String Animation - Josh 'Acecool' Moser under modified ACL - Free to use, modify and learn from.
--
--[[
This set of helpers is meant to be called every frame / render.. It can either be used this way and output via means of drawing the text directly, or by updating a panel and invalidating the layout, when the animation changes as a return allows you to do this.
A few recommendations:
Alter and add in an advance frame function - then you can have a separate system advance the frame of the unique id and make the clock tell time to the best of its limitations, or make the clock go backwards during an undo action..
You can set up a direction override so you can make the animation go in reverse and only in reverse for the undo action...
With the advance frame function you can advance the frame based on user interactions..
You can also improve the __anim_data table by making a single table within: [ _id ] = { dir = 1, pos = 1, paused = false, and_extend_it = true, cooldown = 0 }
etc.. etc.. etc...
I do hope this has been easy to understand and educational.
]]
--
-- Enumeration
-- Here, we are simply setting up variable names with meaning where the value means nothing - the value must be unique for the table. This lets us reference the animation we want without having to remember 0, 1, 2, or some other number which makes code look messy.
--
-- This is for the pipe animation | / ─ \
STRING_ANIMATION_PIPE = 0;
-- This is for the dot animation . .. ... .. and stacked stars
STRING_ANIMATION_DOTS = 1;
-- Stacking stars
STRING_ANIMATION_STAR_DOTS = 2;
-- This is for the clock animation
STRING_ANIMATION_CLOCK = 3;
-- Arrow
STRING_ANIMATION_ARROW = 4;
-- Bird in flight
STRING_ANIMATION_BIRD = 5;
-- Flower
STRING_ANIMATION_FLOWER = 6;
-- Eclipse - From Raku Throbber post author
STRING_ANIMATION_ECLIPSE = 7;
-- Add more... You can also create a function to create enums quickly.. I may include that example at some point in the future.
--
-- Configuration
-- Basic configuration
--
-- The default delay between frames - the function used allows you to override this, as does the table which lets you set up a delay for that particular animation - this is just the default in case a delay has not been set for either location. As this value is only used as a fallback, it is set as local.
local CFG_STRING_ANIMATION_DEFAULT_DELAY = 1 / 8;
-- The animation map which defines each animation, if it ping / pongs ( starts at beginning, animates through to end, animates through to start and repeats ) or not ( animates from start to end and resets ).
-- Note: Count is set to -1 ( can also be 0 ) so that if you are working in an environment with live-update support the table will be recreated and the entries can be recounted ( this is really only needed if you remove local from the declaration, and do X = X or { } to allow re-using a pre-existing element in a live-update supported application.. Otherwise, count can be completely removed from this map and have it generated the first time string.Animate is called )
local MAP_TIME_ANIMATIONS = {
[ STRING_ANIMATION_DOTS ] = { anim = { '.', '..', '...' }; reversible = true; delay = 1 / 3; count = -1; };
[ STRING_ANIMATION_PIPE ] = { anim = { '|', '/', '', '\\' }; reversible = false; delay = 1 / 3; count = -1; };
[ STRING_ANIMATION_STAR_DOTS ] = { anim = { '', '', '' }; reversible = true; delay = 1 / 8; count = -1; };
[ STRING_ANIMATION_CLOCK ] = { anim = { '🕛', '🕧', '🕐', '🕜', '🕑', '🕝', '🕒', '🕞', '🕓', '🕟', '🕔', '🕠', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚', '🕡', '🕢', '🕣', '🕤', '🕥', '🕦' }; reversible = false; delay = 1 / 8; count = -1; };
[ STRING_ANIMATION_ARROW ] = { anim = { '', '', '', '', '', '', '', '' }; reversible = false; delay = 1 / 8; count = -1; };
[ STRING_ANIMATION_BIRD ] = { anim = { '', '', '', '', '', '' }; reversible = true; delay = 1 / 8; count = -1; };
[ STRING_ANIMATION_FLOWER ] = { anim = { '', '', '' }; reversible = true; delay = 1 / 8; count = -1; };
[ STRING_ANIMATION_ECLIPSE ] = { anim = { '🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘' }; reversible = false; delay = 1 / 8; count = -1; };
};
-- The default animation type if type isn't set, or if the animation doesn't exist in the table...
MAP_TIME_ANIMATIONS.default = MAP_TIME_ANIMATIONS[ STRING_ANIMATION_DOTS ];
--
-- Runtime data - this table structure keeps track of the direction, which frame it is on, etc..
--
-- Animation data - We are extending the string library with an internal table using my notation.
string.__anim_data = {
-- Runtime animation data
runtime = {
-- Cooldown management - we only need time started and duration; from which we can calculate everything else. Another option for this simple system is to simply set the expiry.
cooldowns = {
-- default = { started = -1, duration = 0 }
-- Expiry only variant... So the time which the cooldown expires goes here.
default = 0;
};
-- The current index for a set id... IE: Which character we are currently showing.
index = {
default = 1;
};
-- The current direction of travel for the animation ( moving forward through animation = 1, or moving backwards = -1 ).
dir = {
default = 1;
};
-- Whether or not the animation is paused.
paused = {
default = false;
};
}
};
--
-- Runtime data - this table structure keeps track of the direction, which frame it is on, etc..
--
-- Animation data - We are extending the string library with an internal table using my notation.
string.__anim_data = {
-- Runtime animation data
runtime = {
-- Cooldown management - we only need time started and duration; from which we can calculate everything else. Another option for this simple system is to simply set the expiry.
cooldowns = {
-- default = { started = -1, duration = 0 }
-- Expiry only variant... So the time which the cooldown expires goes here.
default = 0;
};
-- The current index for a set id... IE: Which character we are currently showing.
index = {
default = 1;
};
-- The current direction of travel for the animation ( moving forward through animation = 1, or moving backwards = -1 ).
dir = {
default = 1;
};
-- Whether or not the animation is paused.
paused = {
default = false;
};
}
};
--
--Updates the pause state of the animation
--
function string.SetTextAnimationPauseState( _type, _id, _value )
string.__anim_data.runtime.paused[ _id || 'default' ] = ( isbool( _value ) && _value || false );
end
--
-- Returns the pause state, or returns false if nil
--
function string.GetTextAnimationPauseState( _type, _id )
return string.__anim_data.runtime.paused[ _id || 'default' ] || false;
end
--
-- Pauses the animation
--
function string.PauseTextAnimation( _type, _cycle_delay, _id )
string.SetTextAnimationPauseState( _type, _id, true );
end
--
-- Unpauses the animation
--
function string.UnPauseTextAnimation( _type, _cycle_delay, _id )
string.SetTextAnimationPauseState( _type, _id, false );
end
--
-- Toggles the pause state of the animation
--
function string.ToggleTextAnimation( _type, _cycle_delay, _id )
string.SetTextAnimationPauseState( _type, _id, !string.GetTextAnimationPauseState( _type, _id ) )
end
--
-- This keeps track of the animation by setting up the time tracking, checking it, etc..
-- It returns whether or not a cooldown exists. Basic time management. If a cooldown doesn't exist, and the delay argument is assigned, then it will create a new cooldown for that amount of time but it will return false so the frame can advance.
--
function string.HasAnimationCooldown( _id, _delay )
-- Fetch the animation data table..
local _data = string.__anim_data.runtime;
-- Fetch the cooldowns
local _cooldowns = _data.cooldowns;
-- Fetch our cooldown, if it exists.. use default if no id given as this can be called outside the scope of the other function...
local _cooldown = _cooldowns[ _id or 'default' ] or -1;
-- A helper which references the current time, in seconds, since the epoch. This should have decimal places?
-- Note: os.time( ) locks you into 1 second intervals although 0 seconds would work though meaning every call would update the frame and become illegible if rendering many frames per second..
--local _time = os.time( );
-- This returns the time since Lua / PC started with millisecond precision. Since we don't need any sort of time output, this is perfect to allow animation that isn't restricted to whole second intervals.
-- If we wanted to, we could also use this in conjunction with os.time( ) to get a more precise output by getting the current time..
--
-- There are many different options to do this...
--
-- We could use math.fmod( os.cllock( ), 1 ) which returns the decimals of a number / float.
-- We could math.floor this number and subtract it from itself, then add the remainder ( decimals ) to os.time( ) which would give us more precision in os.time.
-- Another way is to subtract math.floor of this number from os.time( ) and then add this entire value to os.time value. Either way you end up with the same result - but this option means subtracting against a larger number.
-- Another option is casting to string, exploding on ., recasting to number and dividing to put back into decimal format.
-- We could use string matching via Patterns ( similar to RegEx ).
-- There is also string.sub after finding the index of the decimal.
--
-- etc.. etc.. etc...
--
-- The best way is usually the simplest. We don't need to tell time - we just need to measure the passage of time, ie delta T. If we needed time, I'd probably use fmod, unless benchmarking showed it costs more than subtracting and adding.
--
local _time = os.clock( );
-- Setup a helper to see if we have the cooldown.. If our cooldown is a larger number than our current time, we haven't passed it yet and it exists.
local _has_cooldown = _cooldown > _time;
-- If we do not have a cooldown, but we have a delay assigned, setup a new cooldown
if ( !_has_cooldown and type( _delay ) == 'number' ) then
-- Create in the expiry format - time plus delay....
_cooldowns[ _id ] = _time + _delay;
end
-- Return whether or not we have a cooldown; ignoring if we created one this frame.
return _has_cooldown;
end
--
-- Animations a string based on our registry and registry options - we are extending the default string library. Be careful when doing this and always ensure you aren't overwriting an important function. As string.Animation doesn't exist, we can add it - but if used we must monitor updates so that if it is added to Lua that we either change the name, or use the new function.
--
-- Basic Usage: This is meant to be called every render frame. You can also micro-cache the data as I went ahead and added the second return which tells you when the character was updated for use in elements that invalidate the layout ( and may cause flickering if you invalidate too frequently ), etc.. It can only update the frame characters if it is being called.
--
-- Argument: _type - <Number> - This is the ENUMerated STRING_ANIMATION_* which lets the function know which animation to reference from the MAP_ table.
-- Argument: _id - <String> - This isn't required - defaults to 'default'. If you want to run multiple animations at the same time, use it or you will advance frames at incorrect times for the animation - the cooldown will be set to whichever delay is called.. So it would be possible to have a delay of 0.5 and a delay of .99 and the first frame advance will happen at 0.5 seconds, then 0.99 will trigger. then 1.0 and 1.5 will be skipped.
-- Argument: _cycle_delay_override - <Number> - This is the delay you wish to use for the animation to advance the frame of the current animation. This is optional. By default it uses the MAP_ table delay in the animation table. If no animation is provided in the MAP_ table, or here, then the default CFG_ animation delay will be used.
--
-- RETURNS: _char - <String> - This returns the character( s ) for the current frame of the current animation as a string. You can append them to another string, or just display them.
-- RETURNS: _has_frame_advanced - <Boolean> - Returns true if the character( s ) ha(s/ve) changed since the last time the function was called.
--
function string.SimpleAnimation( _type, _id, _cycle_delay_override )
--
-- Notes: An id isn't required - if no id is provided, 'default' will be used. If you try running 2 separate animations with the same name, one will overwrite the other and the wrong frame will be shown. You can update the internal table to make it so each type has its own id if you want. But this example lets you set a unique id period. So you can show one animation with default, be done with it, and flip to another without having to worry about adding overhead by re-using an existing id.
--
-- Ensure the type provided is a number... This prevents it from running... or, as I've chosen - we test and if it doesn't work we use our default.
-- assert( isnumber( _type ), '[ string.Animation ] _type must be a number!' );
-- Check the type and ensure it is a number. If it isn't or the map address doesn't exist, we use the default which is handled below.
local _type = ( ( type( _type ) == 'number' and MAP_TIME_ANIMATIONS[ _type ] ) and _type or nil );
-- Setup the id to identify this animation as
local _id = ( type( _id ) == 'string' and _id or 'default' );
-- The data
local _data = ( MAP_TIME_ANIMATIONS[ _type ] or MAP_TIME_ANIMATIONS.default );
-- The animation table
local _anim = _data.anim;
-- If we don't know how many elements there are to the animation, count the entries and cache the result so we don't have to do it again.
if ( !_data.count or _data.count < 1 ) then _data.count = #_data.anim; end
-- The characters.
local _count = _data.count;
-- If there is nothing to animate - output nothing.
if ( _count < 1 ) then return ''; end
-- The animation runtime data table
local _runtime = string.__anim_data.runtime;
-- This is the direction of travel - we use it to multiply against our +1 so it is + ( 1 * dir ) to make it add or subtract.
local _dir = _runtime.dir[ _id ] or 1;
-- The runtime index table for all ids
local _indexes = _runtime.index;
-- The runtime character index table for the id in question - the first character is used by default.
local _index = _indexes[ _id ] or 1;
-- Has the frame advanced?
local _has_frame_advanced = false;
-- Fetch whether or not the animation is paused... -- went ahead and added it.
local _paused = string.GetTextAnimationPauseState( _type, _id );
-- This returns whether or not the cooldown exists, or has expired. It will automatically re-create it so the next frame this will return t rue if the delay is longer than a frame.
local _has_cooldowm = string.HasAnimationCooldown( 'string_animation_' .. _id, ( type( _cycle_delay_override ) == 'number' and _cycle_delay_override or ( type( _runtime.delay ) == 'number' and _runtime.delay or CFG_STRING_ANIMATION_DEFAULT_DELAY ) ) );
-- If the text isn't paused, and there isn't a cooldown ( ie, the delay has expired and we can advance to the next frame ) then continue...
if ( !_paused and !_has_cooldowm ) then
-- If we actually have more than 1 character so that we can advance the frame and it not be a waste of time by simply advancing / reverting to the same frame - then we run the logic.... If there is only 1 frame ( why? ) then we skip this logic.
if ( _count > 1 ) then
-- Update the reference - this makes it so you can re-use ids with different animations and different count values and it will just wrap around to what it should be.
_indexes[ _id ] = ( _index + _dir ) % ( _count + 1 );
-- Debugging, if you want to see it.
-- print( '[ string.Animation ] Type: ' .. _type .. '; Delay: ' .. _cycle_delay_override .. '; ID: ' .. _id .. '; I: ' .. tostring( _index ) .. '; Char: ' .. tostring( _char ) .. '; Paused: ' .. tostring( _paused ) );
-- If we are at the limits - decide what to do based on options. This isn't necessary - we could simply use % notation
if ( _indexes[ _id ] <= 1 or _indexes[ _id ] > _count + 1 ) then
if ( _data.reversible ) then
-- ping pong;
_indexes[ _id ] = ( _indexes[ _id ] == 0 ) and _count - 1 or _indexes[ _id ];
-- Revert
_runtime.dir[ _id ] = _dir * -1;
else
-- Reset
_indexes[ _id ] = ( _indexes[ _id ] == 0 ) and 1 or _indexes[ _id ];
end
end
-- Update the _index helper so that our character will be the current instead of having to wait until the next frame.
_index = _indexes[ _id ] or 1;
-- The frame has advanced - update the var so we can use it to perform an action if necessary..
_has_frame_advanced = true;
end
end
-- The frame character( s )
local _char = _anim[ _index ] or '';
-- Return the character( s ) from the current animation frame
return _char, _has_frame_advanced;
end

View file

@ -0,0 +1,15 @@
--
-- In some HUD element, or where text is output... such as 'Loading' ... try:
-- This would be called every frame and would result in Loading., Loading.., Loading..., Loading.., Loading.
--
-- This one will use a unique id: loading_dots and have a 1 second delay between frames.
-- In this example print would be draw.Text or something along those lines.
print( 'Loading' .. string.SimpleAnimation( STRING_ANIMATION_DOTS, 'loading_dots', 1 ) );
-- or
-- This one will use id default, and use the pre-defined delay which is 1/3 because it is defined in the map. If it wasn't, it would use the default of 1/8...
-- In this example print would be draw.Text or something along those lines.
print( 'Loading' .. string.SimpleAnimation( STRING_ANIMATION_DOTS ) );

View file

@ -0,0 +1,42 @@
--
-- 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
-- the largest then save the largest segment in another key so we can, based on font size, etc.. get the width / height of the resulting output so we can ensure our elements don't have to do ugly sliding action when rendering...
--
--
-- Initialization function
--
function PANEL:Initialize( )
-- Create the button and set the base text ( assume first arg ) as the language key ( also assume it handles referencing the correct word in GetBaseText )
self.button = self:CreateButton( '#lang_loading' );
-- Ensure size is correct
self.button:SizeToContents( );
-- Give it a little additional space
-- Task: Create a helper function which returns the largest section of the animation so we can get the size and ensure we set the button to the max possible size
self.button:SetWidth( self.button:GetWidth( ) + 25 );
end
--
-- Our render panel function
--
function PANEL:Paint( _w, _h )
-- Get the animation text and let us know if it has advanced
local _anim, _has_advanced = string.SimpleAnimation( STRING_ANIMATION_DOTS, 'button_loading_dots' );
-- If the animation text has changed - update the button... If we added enough buffer room it shouldn't need to be resized ( which would look ugly anyway; hence the need for a function to get the largest size and for optimization, check when the animation is created instead of when used )...
-- OR simple check the first use - which would be too late for this example though... unless we resize to max as it happens then never shrink.
if ( _has_advanced ) then
-- Update the text - Note: Assume Set/Get BaseText is used to store text and isn't output or changed with SetText.
self.button:SetText( self.button:GetBaseText( ) .. _anim );
-- Invalidate the button as it has changed
self.button:Invalidate( );
-- Make sure the panel knows that something has changed within it.
self:InvalidateLayout( );
end
end

View file

@ -0,0 +1,13 @@
Module Checkit {
n$=lambda$ n=1, a$="|/-\" -> {
=mid$(a$, n, 1)
n++
if n>4 then n=1
}
\\ 1000 is 1 second
Every 250 {
\\ Print Over: erase line before print. No new line append.
Print Over n$()
}
}
CheckIt

View file

@ -0,0 +1,10 @@
Module Checkit {
n=1
a$="|/-\"
Every 250 {
Print Over mid$(a$, n, 1)
n++
if n>4 then n=1
}
}
CheckIt

View file

@ -0,0 +1,8 @@
chars = "|/\[Dash]\\";
pos = 1;
Dynamic[c]
While[True,
pos = Mod[pos + 1, StringLength[chars], 1];
c = StringTake[chars, {pos}];
Pause[0.25];
]

View file

@ -0,0 +1,12 @@
Wait:0.25
Delete:1
Say:/
Wait:0.25
Delete:1
Say:-
Wait:0.25
Delete:1
Say:\
Wait:0.25
Delete:1
Goto:1

View file

@ -0,0 +1,12 @@
a[1]="|"
a[2]="/"
a[3]="-"
a[4]="\"
b=0
While b=0
For c=1 To 4
TextWindow.Clear()
TextWindow.WriteLine(a[c])
Program.Delay(250)
EndFor
EndWhile

View file

@ -0,0 +1,7 @@
print "Press control-C to exit..."
while true
for c in "|/-\"
text.setCell 0, 0, c
wait 0.25
end for
end while

View file

@ -0,0 +1,7 @@
while true
for c in "|/-\"
print c
wait 0.25
print char(27) + "[2A" // move cursor up 2 lines
end for
end while

View file

@ -0,0 +1,11 @@
10 DIM A(4)
20 A(1)=236
30 A(2)=234
40 A(3)=235
50 A(4)=233
60 FOR I=1 TO 4
70 CLS
80 PRINT CHR$(A(I))
90 PAUSE 15
100 NEXT
110 GOTO 60

View file

@ -0,0 +1,17 @@
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.

View file

@ -0,0 +1,3 @@
let rec sym = '-' :: '\\' :: '|' :: '/' :: sym
let () = List.iter (fun c -> Printf.printf "%c%!\b" c; Unix.sleepf 0.25) sym

View file

@ -0,0 +1,8 @@
$|= 1;
while () {
for (qw[ | / - \ ]) {
select undef, undef, undef, 0.25;
printf "\r ($_)";
}
}

View file

@ -0,0 +1,17 @@
$|=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.
}
}

View file

@ -0,0 +1,12 @@
-->
<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>
<!--

View file

@ -0,0 +1,102 @@
(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>
<!--

View file

@ -0,0 +1,5 @@
(de rod ()
(until ()
(for R '(\\ | - /)
(prin R (wait 250) "\r")(flush) ) ) )
(rod)

View file

@ -0,0 +1,5 @@
from time import sleep
while True:
for rod in r'\|/-':
print(rod, end='\r')
sleep(0.25)

View file

@ -0,0 +1,14 @@
/*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.*/
else bs= "08"x /* ASCII? " " " " " */
signal on halt /*jump to HALT when user halts pgm.*/
$= '/\' /*the throbbing characters for display.*/
do j=1 /*perform until halted by the user. */
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. */

View file

@ -0,0 +1,7 @@
#lang racket
(define (anim)
(for ([c "\\|/-"])
(printf "~a\r" c)
(sleep 0.25))
(anim))
(anim)

View file

@ -0,0 +1,44 @@
class throbber {
has @.frames;
has $.delay is rw = 0;
has $!index = 0;
has Bool $.marquee = False;
method next {
$!index = ($!index + 1) % +@.frames;
sleep $.delay if $.delay;
if $!marquee {
("\b" x @.frames) ~ @.frames.rotate($!index).join;
}
else {
"\b" ~ @.frames[$!index];
}
}
}
my $rod = throbber.new( :frames(< | / - \ >), :delay(.25) );
print "\e[?25lLong running process... ";
print $rod.next for ^20;
my $clock = throbber.new( :frames("🕐" .. "🕛") );
print "\r\nSomething else with a delay... ";
until my $done {
# do something in a loop;
sleep 1/12;
print "\b", $clock.next;
$done = True if $++ >= 60;
}
my $moon = throbber.new( :frames('🌑🌒🌓🌔🌕🌖🌗🌘'.comb) );
print "\r\nGonna be a long night... ";
until my $end {
# do something in a loop;
sleep 1/8;
print "\b", $moon.next;
$end = True if $++ >= 60;
}
my $scroll = throbber.new( :frames('PLEASE STAND BY... '.comb), :delay(.1), :marquee );
print "\r\nEXPERIENCING TECHNICAL DIFFICULTIES: { $scroll.frames.join }";
print $scroll.next for ^95;
END { print "\e[?25h\n" } # clean up on exit

View file

@ -0,0 +1,7 @@
load "stdlib.ring"
rod = ["|", "/", "-", "\"]
for n = 1 to len(rod)
see rod[n] + nl
sleep(0.25)
system("cls")
next

View file

@ -0,0 +1,15 @@
def spinning_rod
begin
printf("\033[?25l") # Hide cursor
'🌑🌒🌓🌔🌕🌖🌗🌘'.chars.cycle do |rod|
print rod
sleep 0.25
print "\r"
end
ensure
printf("\033[?25h") # Restore cursor
end
end
puts "Ctrl-c to stop."
spinning_rod

View file

@ -0,0 +1,13 @@
fn main() {
let characters = ['|', '/', '-', '\\'];
let mut current = 0;
println!("{}[2J", 27 as char); // Clear screen.
loop {
println!("{}[;H{}", 27 as char, characters[current]); // Move cursor to 1,1 and output the next character.
current += 1; // Advance current character.
if current == 4 {current = 0;} // If we reached the end of the array, start from the beginning.
std::thread::sleep(std::time::Duration::from_millis(250)); // Sleep 250 ms.
}
}

View file

@ -0,0 +1,17 @@
object SpinningRod extends App {
val start = System.currentTimeMillis
def a = "|/-\\"
print("\033[2J") // hide the cursor
while (System.currentTimeMillis - start < 20000) {
for (i <- 0 until 4) {
print("\033[2J\033[0;0H") // clear terminal, place cursor at top left corner
for (j <- 0 until 80) print(a(i)) // 80 character terminal width, say
Thread.sleep(250)
}
}
print("\033[?25h") // restore the cursor
}

View file

@ -0,0 +1,11 @@
print "|"
delay 0.25
clear
print "/"
delay 0.25
clear
print "-"
delay 0.25
clear
print "\"
delay 0.25

View file

@ -0,0 +1,22 @@
dtxt
|
wait
0.25
ctxt
reset
dtxt
/
wait
0.25
ctxt
reset
dtxt
-
wait
0.25
ctxt
reset
dtxt
\
wait
0.25

View file

@ -0,0 +1,27 @@
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

View file

@ -0,0 +1,3 @@
while : ; do
for rod in \| / - \\ ; do printf ' %s\r' $rod; sleep 0.25; done
done

View file

@ -0,0 +1,17 @@
let loop=1
sub delay:
for i=1 to 10000
next
cls 1
return
while loop=1
print 1 "l"
gosub delay:
print 1 "/"
gosub delay:
print 1 "-"
gosub delay:
print 1 "\"
gosub delay:
wend
end

View file

@ -0,0 +1,25 @@
import "io" for Stdout
import "timer" for Timer
var ESC = "\u001b"
var a = "|/-\\"
System.write("%(ESC)[?25l") // hide the cursor
var start = System.clock
var asleep = 0
while (true) {
for (i in 0..3) {
System.write("%(ESC)[2J") // clear terminal
System.write("%(ESC)[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("%(ESC)[?25h") // restore the cursor

View file

@ -0,0 +1,9 @@
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;
];
]

View file

@ -0,0 +1,6 @@
10 LET A$="|/-\"
20 FOR C=1 TO 4
30 PRINT AT 0,0;A$(C)
40 PAUSE 4
50 NEXT C
60 GOTO 20

View file

@ -0,0 +1,5 @@
foreach n,rod in ((1).MAX, T("|", "/", "-", "\\")){
print(" %s\r".fmt(rod));
Atomic.sleep(0.25);
}

View file

@ -0,0 +1,8 @@
fcn spin{ // this will be a thread that displays spinner
try{
foreach n,rod in ((1).MAX, "\\|/-"){
print(" ",rod,"\r");
Atomic.sleep(0.25);
}
}catch{} // don't complain about uncaught exception that stops thread
}

View file

@ -0,0 +1,4 @@
// main body of code
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