In his book, The Armchair Universe, computer scientist A.K. Dewdney reprints 5 Easy Pieces, one of his Computer Recreations columns published in Scientific American. The first easy piece was to program a moving, segmented caterpillar.
I first programmed this easy piece in the BASIC programming language. In BASIC, the coordinates of each segment were stored in a 1-dimensional array. To compute the next cycle, the new position for the head was computed and then every segment was moved up one element of the array. Only one new movement computation had to be made per cycle of animation!
In Scratch, I used the point towards block to simplify the animation.
Here’s a screenshot of showing how the caterpillar starts in 11 segments.
The segments soon fit loosely together since they are all travelling at the same speed but after a few reflections off the sides, the segments fit together as is shown in this screenshot.
The project can be viewed and downloaded by clicking on this link.