CS 231 Lab 6: Drawing line patterns

Drawing line segments under modified orientations

The idea for this lab was kindly suggested by Alex Leighton, a current CS major (thanks, Alex!), based on a project he did earlier in his schooling (on a calculator, no less!). The lab is meant to give you some further experience with loops and arrays, some first lab experience with scanner-based input, and also to give you some more freedom (and responsibility) for overall program and class design.

The basic idea behind the lab is to draw certain specific patterns of lines under user control. The user inputs a series of numbers (let's assume they are non-negative integers) via a scanner input box. After the user hits "enter", the program will use the integers to draw a pattern of lines in a draeing panel as follows: each integer is interpreted as the length of a line segment to be drawn from the current position, but with successive "right-hand" turns after each segment is drawn.

To get a better idea of the idea, imagine that you are standing on the screen yourself, prepared to do the drawing. You begin facing toward the right ("east"): after drawing the first segment, you turn right (clockwise when viewed from above), so now you're facing down ("south"). Then you draw another line segment, and now turn to face "west". You repeat the process of drawing a segment and turning 90 degrees for each of the integers you read in; when you reach the end of the list, you continue again from the front, re-using the numbers as you go.

(The idea of imagining yourself, or some other being, as doing the drawing under various commands was popularized in the Logo language, which was developed for teaching children. The Logo version used a turtle (its tail raised and lowered the pen to the paper), so these are often called "turtle graphics". Typical turtle commands include movement, rotation, and raising or lowering a pen chosen from several different colors or line styles. Our "turtle" is pretty limited, in that it only draws and turns 90 degrees, and always in that order.)

Your job is to write a program which will do this sort of drawing, based on the numbers entered into scanner input. You should repeatedly read in numbers, redrawing the line pattern each time, until the user enters an empty input. This will allow the user to modify the numbers to see the effect on the pattern drawn.

Overall program design

Most of the programming we have done so far has been either simple class-less expression evaluation in the interactions pane or class-based programming. Lately, we have been "driving" the overall program through a main() method in a Main class. This lab can be approached in a couple of ways:

There is no right or wrong answer to the issue of program design, but you should start thinking about these issues and be prepared to implement your approach.

The basic process, plus some tips

As you can tell from the description above, and somewhat independently of your object or main class design, your program will need to go through the following steps each time it re-draws the pattern:

Some sample pictures

Here are some sample snapshots from the sample implementation I did myself to test out the idea for the lab (in the last one, I also drew colored "dots" every time the pen "stopped"):