ascii art is awesome but like there's no videos on how to animate it in this
video I'm gonna show you how to write a Java program to make a stick person look
like it's running what's up guys my name is Alex welcome back to another Java for
beginner video on this channel I do a lot of fun and easy computer science
videos just like this one so if you're new here consider subscribing ascii art is a
form of displaying images using the 95 displayable characters on the keyboard I
mean another animation similar to this one but I animated a roflcopter I'll
have that on the screen now and in the description if you'd like to check that
out and today we're doing an animated stick person so go to your new Java
project by doing file new Java project we'll call it stick animation finish and
we can write a Java file by going a new class and this will be our stick
animation take this box and hit finish now a Java project set up for us our
running animation is going to be four lines tall and seven characters wide so
to print to the screen is really easy you just type this code and we want four
lines so copy and paste that three more times for a total of four lines tall and
seven characters wide so we'll do that
seven whitespace and this is like our canvas for our stick person first he has
a head which will be a capital o he has a body so we'll do that pipe and he's
running his arms like this so his left arm is down like a forward
slash and his right arm is sort of like a V so we'll go down and up again now
this line has an error because the backslash is funky you have to type two
of them now we have to make its legs and so his legs are kind of like in that V
shape too and one of his legs is like down that's sticking up so let's make
that sticking up leg here and then have his thighs connecting each
of his legs just like that and remember for each backslash we have to do two of
them so do two and two it looks kind of confusing but it'll look it'll look fine
once it's printed out and lastly since this leg is up just do that other leg
right here okay save it and run and let's see what it looks like okay not
too bad he's a little off so we'll just move his legs over and see how that went
okay that's a little better now let's bring him to life animation works just
like animation in a movie so a movie is just a bunch of frames or pictures that
get played really fast so movies will be like 24 frames per second or 30 frames
per second our running man is going to be two frames so to make two frames just
copy what we did so far and we'll have one frame up here and the second frame
down here and to make it look like he's running we'll take that that leg that's
high up and bring it down like that and we'll change the bent leg to a straight
leg now save run and that looks pretty good I think it's a little off let's fix
it yeah I think that's good let's make some white space just to separate the
two out a little because our running manner that claustrophobic oh my light
is like freaking out it attacked by slender's okay just space it out a
little after the first one and then after the second one too and this guy's
gonna run forever I feel really sorry for him because he's gonna be he's not
gonna get a break and so to make him run forever type this while true and the
curly braces this is an infinite loop so it'll run forever
so copy this both of your frames cut it by typing command X or ctrl X or you
could right click and press cut and then paste it here we have command V
or control V I'll have all the shortcuts down below in the red box below me okay
we have our two frames repeating forever but to make it look a little nicer we
have to add a little delay in here so to do that type thread that's sleep and
then type in 100 and that's 100 milliseconds so it's one tenth of a
second so it's still really fast but it's gonna make our animation look a
little nicer there's a red line underneath here because pausing the
program can make some weird things happen so we just gotta tell Java to
watch out for them and to do that we just hit add throws declaration okay and
then copy this weight because we want to wait after each frame so do that second
one too okay save it run it and this should make our running animation oh
okay I messed something up let's move the
window okay I messed something up this is a good life lesson to change the
perspective or the windows if they mess up just go to window perspective reset
perspective and that'll change it to how it first started so let's look at our
running animation again it has to be at the very bottom to see it so I think
something's messing up so I just stopped the program I'm gonna run it again and I
think this is messing up because we put the weights in the wrong place so let's
add that that little delay after the running man instead of after the space
between and let's see if that fixed it now we have a running man if you're
running man's freaking out like it looks like he's going crazy or his heads like
cut off it might be because you're running multiple of the same time and
since we did this while true it runs forever so in order to stop it we have
to press this red square to stop it so if you ran this three times you'd have
to stop it three times and then run it once and then that should work so I hope
this was fun if you like videos like this please tell
in the comments and like down below I challenge you to customize your running
man maybe like add a hat to him maybe he's
holding something maybe he's running on a track or maybe he even has more than
two friends try it out for yourself this is like I love computer science like
this I don't like the syntax and the rules as much what's really fun is just
making programs like this question of the day how did you customize your
running animation let me know in the comments and connect with this community
of new programmers make sure to subscribe so you see all my videos the
day they come out if this was helpful and you enjoyed it smash that like
button and share it if you think you might help someone you know you could be
anywhere in the world that you're here programming with me
and I appreciate it catch it
you