Make a hammer animation

5

1

The goal is to make a two frame animation with ASCII art of a hammer smacking a table.

Trailing white-space is allowed and the frames need to repeat continuously. The program should iterate over both frames with a time of 0.5 seconds between frames.

Lowest byte count wins for each language!

Sample:

Animation Frames:

Frame 1:
 -------------------
|                   |
|                   |
|                   |
 -------------------         
         /  /
        /  /
       /  /
      /  /
     /  /
    /  /
   /  /
  /  /
 /  /
 \ /                              


                        ---------------------------
                       |                           |


Frame 2:

                                        ----------
                                       |          |
                                       |          |
                                       |          |
 --------------------------------------|          |
|                                      |          |
 --------------------------------------|          |
                                       |          |
                                       |          |
                                       |          |
                                        ----------
                                  -------------------------------
                                |                                |

user78881

Posted 2018-03-11T16:51:50.750

Reputation:

9Welcome to the site! This sounds like a good idea, but you need to be way more specific, and spell out what the anination should be like. See other challenges in the [tag:ascii-art] or [tag:animation] tags for reference – Luis Mendo – 2018-03-11T16:54:43.030

@LuisMendo Is This Better? – None – 2018-03-11T17:23:26.580

1@PythonDude29 If the answer needs to be a program/function which takes a number (say 1/2 or 0/1) and produces the appropriate frame, then you need to state so. If frame 1 needs to be displayed and then exchanged for frame 2 after a predetermined time or event, you need to state so. – Adám – 2018-03-11T17:29:56.633

You also need to clarify if trailing whitespace is acceptable. – Adám – 2018-03-11T17:31:12.790

I think I am Done. – None – 2018-03-11T17:39:25.173

@Scrooble Is that everything? Or is there more specifics I need – None – 2018-03-11T18:10:53.217

1I'm not a fan of these line controllers—it is my understanding that languages like Charcoal don't operate that way. I'd refer to other [tag:ascii-art] and [tag:kolmogorov-complexity] questions. However, this challenge does now fall within this site's requirements (IMO), so I'm voting to reopen. – Khuldraeseth na'Barya – 2018-03-11T20:23:36.480

@Scrooble Hmm I only know a couple languages. I know Python, A Bit Of JavaScript And A bit Of C#. I used the line controllers when I did my own(Where I got the idea) – None – 2018-03-11T20:28:41.140

Must the font be monospace? Is graphical output allowed? – user202729 – 2018-03-12T11:33:00.040

2Also please don't write in title case. – user202729 – 2018-03-12T11:33:35.973

Doesn't this pretty much end up as run length encoding in just about every language? – fəˈnɛtɪk – 2018-05-01T01:42:36.053

This is kinda a combination of this and most ascii art with high repetition/run length, but i'm not sure if it should be considered a duplicate.

– fəˈnɛtɪk – 2018-05-01T01:48:22.167

@fəˈnɛtɪk I think it's more like this one, then the one you linked. That one also replaces the current ASCII art at every iteration.

– Kevin Cruijssen – 2018-05-01T08:11:26.743

Answers

1

Perl 5, 391 355 293 286 296 bytes

Whack whack whack, golfing those chars off, down to 296 b :) .5s sleep as per the question specs.

This also requires perl -E

$r="| 19|n"x 3;$p="| 10|n";$R=" 39$p"x 3;$T=" -38$p";$t=" 40-10n";$m=" -19n$r -19n 9H 8H 7H 6H 5H 4H 3H 2H 2\\ /n3 24-27n 23| 27|n";$M="$t$R$T| 38$p$T$R$t 34-30n 33| 30|n";for($m){say"\033[2J";map{s:H:/  /n:;y!n!\n!;print$1x($2?$2:1)if/(\D+)(\d*)/}(split/(.\d*)/);($m,$M)=($M,$m);select$v,$V,$v,.5;redo}

Explanation/comments:

# initial vars build strings that the print will understand later
$r="| 19|n"x 3;
$p="| 10|n";
$R=" 39$p"x 3;
$T=" -38$p";
$t=" 40-10n";

# set $_ to first frame
$_=" -19n$r -19n 9H 8H 7H 6H 5H 4H 3H 2H 2\\ /n3 24-27n 23| 27|n";

# M is second frame
$M="$t$R$T| 38$p$T$R$t 34-30n 33| 30|n";

# main loop
{

# clear screen
say"\033[2J";

# or windows, -1b
# system"cls";

# start map...
map{

# sed replace H for /  /n
s:H:/  /n:;

# tr replace n for newline
y!n!\n!;

# parens around ?: necessary due to x operator precedence
# if/regex/ prints $1 $2 times 
print$1x($2?$2:1)if/(\D+)(\d*)/

# map runs on char followed by a number or not
}(split/(.\d*)/);

# rotate frames
($_,$M)=($M,$_);

# sleep for 1 second would be shorter, but perl does
# not deal with integer sleep without time::hires
# sleep 1;

# select for decimal second sleep
select$v,$v,$v,.5;

# do the current block again
redo
}

GIF of original in action: https://i.imgur.com/w3e2JQS.gifv

whofferbert

Posted 2018-03-11T16:51:50.750

Reputation: 186

Welcome to PPCG! It's common courtesy to have a header with the language name and byte count. Hope you stick around! – Jo King – 2018-07-24T06:07:48.383

Thanks, I missed adding the title the first time through. – whofferbert – 2018-07-24T06:31:07.190

2

Python 3, 337 331 319 bytes

-12 bytes thanks to Amphibological

import os,time
t,e,q,p='- \n|'
j=e+t*19+q
L=p+e*19+p+q
l=j+3*L+j
for i in range(9):l+=e*(9-i)+'/  /'+q
l+=' \\ /'+3*q+e*24+t*27+q+e*23+p+27*e+p+q
c=39*e
C=p+10*e+p+q
m=10*t+q
R=e+38*t+C
f=(c+C)*3
r=q+c+e+m+f+R+p+38*e+C+R+f+c+e+m+34*e+31*t+q+32*e+p+32*e+q
b=0
while 1:print([r,l][b]);time.sleep(.5);os.system('cls');b=~b

Try it online!

It uses 'cls', so will only work on Windows, use 'clear' for Linux with +2 bytes.

Will add a gif later.

frosqh

Posted 2018-03-11T16:51:50.750

Reputation: 321

Nice! You could change r if b else l to [r,l][b] and import os\nimport time to import os,time to save some bytes. – Amphibological – 2018-07-25T00:11:18.800

1

Python 3.6, 413 bytes

from os import*
from time import*
s,y=' -';b=y*19;d=b+b;f=y*10;i=y*26;g=s*9;c=s+g;h=s*26;j=s*32;a=c+g;e=a+a;p=print;k=f'\n|{a}|';t,v=system,sleep;z='cls'
while 1:
 t(z);p(f' {b} {k*3}\n {b}')
 for x in range(9):p(f'{g[x:]}/  /')
 p(f' \\ /\n {a} {i}\n {a}|{h}|');v(1);t(z);p(f' {e} {f}')
 for w in range(7):p(f' {e}|{c}|')if w!=3else p(f' {d}|{c}|\n|{e}|{c}|\n {d}|{c}|')
 p(f' {e} {f}\n {j} {i}\n {j}|{h}|');v(1)

Doesn't work on TIO, so here's a GIF:

Hammer ASCIIMation

Not the prettiest thing in the world, but I'm pretty proud of it. Suggestions on golfing it further are welcome!

P.S.: I used a 1 second delay because it looked better to me, but you can replace 1 with .5 to change that, at +2 bytes.

P.P.S: This will only work on Windows, to try on Unix, change cls to clear at +2 bytes.

Amphibological

Posted 2018-03-11T16:51:50.750

Reputation: 1 394

That's as amazing how does it work how long did it take you – None – 2018-07-20T21:42:37.207

@PythonDude29 thanks. It didn't take too long, maybe about 45 mins. It works mostly by substituting variables into strings with the new python f-strings. I'll post a more detailed explanation when I get a chance. – Amphibological – 2018-07-20T21:48:39.487

Ok it's really cool – None – 2018-07-20T21:49:36.810

@PythonDude29 thanks. I really appreciate it! – Amphibological – 2018-07-20T21:50:25.257