Jump to content

Spinning rod animation/Text: Difference between revisions

→‎{{header|Perl 6}}: Add a scrolling "marquee" option and a demo
(Add Python)
(→‎{{header|Perl 6}}: Add a scrolling "marquee" option and a demo)
Line 113:
=={{header|Perl 6}}==
{{works with|Rakudo|2018.05}}
Traditionally thisthese isare know as a [[wp:throbber|throbberthrobbers]] or progress indicatorindicators.
 
This implementation will accept an array of elements to use as its throbber frames, or as a scrolling marquee and optionally a delay before it returns the next element.
 
<lang perl6>class throbber {
has @.membersframes;
has $.delay is rw = 0;
has $!index = 0;
has Bool $.marquee = False;
method next {
$!index = ($!index + 1) % +@.membersframes;
sleep $.delay if $.delay;
"\b"if ~ @.members[$!index];marquee {
("\b" x @.frames) ~ @.frames.rotate($!index).join;
}
else {
"\b" ~ @.frames[$!index];
}
}
}
 
my $rod = throbber.new( :membersframes(< | / - \ >), :delay(.25) );
print "\e[?25lLong running process... ";
print $rod.next for ^20;
 
my $clock = throbber.new( :membersframes("🕐" .. "🕛") );
 
my $clock = throbber.new( :members("🕐" .. "🕛") );
print "\b \nSomething else with a delay... ";
until my $done {
# do something in a loop;
sleep 1/12; # simulate processing delay
print $clock.next;
$done = True if $++ >= 60;
}
 
my $scroll = throbber.new( :frames('PLEASE STAND BY... '.comb), :delay(.1), :marquee );
END { print "\b \e[?25h\n" } # clean up on exit</lang>
print "\b \nEXPERIENCING TECHNICAL DIFFICULTIES: { $scroll.frames.join }";
print $scroll.next for ^95;
 
END { print "\b \e[?25h\n" } # clean up on exit</lang>
 
=={{header|Python}}==
10,351

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.