I need to draw dots using nested for loops. The actual function that creates the dot is not important. The point of this assignment is to figure out how to draw the image shown using a maximum of 3 nested for loops and a maximum of two calls to the bigDot function, which places a dot and connects it to the last dot drawn. For example:  This is one of the images we must recreate. This one is done with the following loops: | CODE | for (row = 0; row < ROWS; row++) for (col = 0, col < COLS; col++) board.bigDot(row,col); break;
|
This one is simple enough. ROWS = 8, which is the max number of rows. COLS = 8, which is the max number of columns. row is the current row number and col is the current column number. This one goes through each row, and places a dot in each column. The one I'm having trouble with is this:  First we needed to do just one diagonal line. I did this with the following code: | CODE | for (row = 0; row <= ROWS; row++) for (col = row; col == row; col++) board.bigDot(row,col); break;
|
I want to know how I can change this code so that it somehow resets itself and starts over, or a new way of doing this. You can see the path of the line which shows the order that the dots are being made.
The rules are that I'm only allowed to use nested for loops and a call to the bigDot function. No more than 3 nested loops and no more than two calls for the method. Nothing else is allowed.
EDIT: Actually I figured it out finally using this code:
| CODE | for (k = 0; k <= ROWS; k = k + ROWS) for (row = 0; row <= ROWS; row++) for (col = row; col == row; col++) board.bigDot(row,Math.abs(col - k)); break;
|
Now I need help with another picture:  Again, I did the first half (left side) with this code: | CODE | for (col = 0; col < COLS; col++) for (row = col; row < (ROWS - col); row++) board.bigDot(row,col); break;
|
too lazy to explain what the code does as I'm assuming I'm going to get help from someone who can read it. Again, I want to know how I can modify this code to sort of repeat the image, or some brand new code that can get it done. Also, I know the paragraphs are all screwy in the code block, it's not like that in the actual code.
This post has been edited by BubbleMan on Sep 29 2009, 04:47 PM
--------------------
|