Classwork 13: Animated ASCII Art, Revisited
To practice using for loops and to play with printing to the terminal screen.
In Classwork 5, we played with printing escape sequences to the screen, which allowed us to "animate" and inch worm crawling across the screen.
In lecture, we saw how this program can be shortened using for loops and functions. Your assignment is to extend the "animation" so the inch worm continues to crawl across the screen after eating the food pellet. The inch worm should leave a trail of . characters (periods) behind for 20 steps. (See demo in this movie clip: eat2.avi.)
You should use inch4.c as a starting point. This already shows the inch worm eating the food pellet.
- See Classwork 5 for a brief discussion on VT100 escape sequences that clears the screen and puts the cursor in the top-left (home) position.
- Classwork 5 also talks about the usleep() function.
- You must print a newline character \n after each step of the animation! The operating system does not actually send the characters from the printf() statement until it sees a newline. If you don't print a newline before each call to usleep(), the operating system will simply queue up all the characters and send them all at once when it finally sees a newline. This completely ruins the effect we are trying to get from calls to usleep().
Don't bother with the script command for this assignment since it doesn't record the pauses from usleep() so the output won't have the desired effect. Just submit your C source code:
submit cs104_chang cw13 inchworm.c
Be sure to logout completely when you have finished!