<("<) Bird Dancer (>")>
Matlab, 125 117 bytes
Unfortunately this cannot be displayed in TIO as there is no "streaming" of the output. Here's a gif for an input of 1
instead:
t=input('')*.1;a='^(")vv(")^^(")^v(")v(>")><(")><("<)';while 1;n=randi(7);clc;disp(a(n*5-4:n*5));pause(t+t*(n>4));end
Thanks @LuisMendo for -8 bytes!
*><>, 103 101 bytes
<vD[3'(")'
1x<.5
S\:43_C43CdooI:o@:o@:o@Do
R!"^"x"v">
>:2* _"><"92.
x '>)">('u.02S*2:oooooodO<'<("<)'
Try it here! (write in n
on the initial stack or you'll get an error)
I decided to take a stab at my challenge since there were no sub 100 bytes answers. Place n
on the stack and away you go! This reuses the (")
characters to save some bytes.
Explanation
Initialisation
<vD[3'(")'
Here we store (")
for later usage.
< move the IP left
[3'(")' push '(")' to a new stack
D move back down to a clean stack
v move the IP down into "dance chooser"
Dance chooser
1x<.5
\
This is frequently executed to select which type of dance we're going to generate.
x generate a 100ms dance or a 200ms dance
1 .5 jump to "200ms dance"
\ mirror IP into "100ms dance"
There's a v
above the x
and a <
to the right of it too. These make the x
get re-executed if it tries to move the IP in the wrong direction.
Generate 100ms dance
S\:1*43_C43CdooI:o@:o@:o@Do
Here we generate and output one of the 100ms dance moves.
\ mirror the IP right
: copy n
43 C43C call "generate '^' or 'v'" twice
_ ignored mirror
do output a carriage return
o output the first hand of the bird
I:o@:o@:o@D select, copy, and output '(")'
o output the second hand of the bird
S sleep for previous n*100ms
\ mirror IP back to "dance chooser"
43C - Generate "^" or "v"
R!"^"x"v">
This is a simple function that generates "^" or "v" then returns. It works similarly to the dance chooser where it has instructions around x
to ensure the IP only moves left or right.
x generate "^" or "v"
R!"^" > push "^" to stack and return
R "v" push "v" to stack and return
Generate 200ms dance
This is another that begins with x
. It'll be separated into two sections: <(")>
and another (>")> and <("<)
, because they're two distinct sections and x
is the only thing they share.
<(")>
>:2* _"><"b2.
This basically does the beginning of the generate 100ms dance
routine, but populates the bird hands as ><
instead of a random ^v
combo. It multiplies n
by two this time as well. This makes it all setup to utilise the generate 100ms dance
routine to output the entire bird and wait 200ms instead.
> move IP right
:2* copy n and do n*2
_ ignored mirror
"><" push "><" to stack
b2. jump to "output carriage return" in "generate 100ms dance"
(>")>
and <("<)
x '>)">('u.02S*2:oooooodO<'<("<)'
This little explanation is about the (>")>
and <("<)
generation, though the x
can send the IP outside of it (explained below).
x move to "choose dance", generate (>")>, <("<), or <(")> (previous routine)
'>)">(' push '(>")>' to the stack
'<("<)' push '<("<)' to the stack
u O< ensure inner code block is always executed with IP moving left
od output carriage return
ooooo output bird
S*2: sleep for n*200ms
.02 jump to "dance chooser"
JavaScript (ES6) + HTML5: 118 116 + 8 = 124 bytes
Javascript: 119 bytes
f=n=>{a.innerHTML='(>")>0<(")>0<("<)0^(")v0v(")^0^(")^0v(")v'.split(0)[r=+new Date%7],setTimeout(f,(1+(r<3))*100*n,n)}
I'm using the milliseconds since epoch to generate a random-ish number. Theoretically, this would always generate the same (set of) number(s), but a test on my PC gave me a pretty random outcome (most numbers appeared more or less equally). Also using the fact that html elements with an id get added to the global window object in JavaScript, so document.getElementById()
is not needed.
HTML: 8 bytes
<b id=a>
I'm omitting the quotes here and I'm not closing the b
tag. It's not valid html, but all browsers automatically close the tag anyway. I made it bold because b
is a one-character HTML element and because my bird's dance deserves being noticed.