Try writing a program to generate for simple cases and check that your output agrees with the example cases; this will confirm you've understood the problem and are heading in the right direction.
The "current" location is then incremented by the specified length towards the right of the image, and the process is repeated. After writing out the image, the program finishes, producing this output