I am trying to color a grid in Java program to match a certain country flag. (Je
ID: 643447 • Letter: I
Question
I am trying to color a grid in Java program to match a certain country flag. (Jersey)
The program works by asking the user for a height/size (9 in the picture) and the width is automatically equal to (height * 2). (this is already done)
so far I have the diagonal line that goes from top to bottom as shown below:
private static void Jersey(MyGrid grid){
int height = grid.getHt();
int width = grid.getWd();
for (int row = 0; row <= height - 1; row++){
for (int col = 0; col <= width - 1; col++){
if(col == row * 2 || col == row * 2 + 1){
grid.setColor(row, col, Color.RED);
}
}
}
}
What I need help with is drawing the reverse diagonal line from bottom to top.
I tried:
for (int row = 0; row <= height - 1; row++){
for (int col = width - 1; col >= 0; col--){
if(col == row * 2 || col == row * 2 + 1){
grid.setColor(row, col, Color.RED);
}
}
}
but it's not working!
I am trying to color a grid in Java program to match a certain country flag. (Jersey) The program works by asking the user for a height/size (9 in the picture) and the width is automatically equal to (height * 2). (this is already done) so far I have the diagonal line that goes from top to bottom as shown below: What I need help with is drawing the reverse diagonal line from bottom to top. I tried: but it's not working!Explanation / Answer
for (int row = 0; row <= height - 1; row++){
for (int col = width - 1; col >= 0; col--){
//if(col == row * 2 || col == row * 2 + 1){
if(col == (width - 2*row - 1) || col ==(width - 2*row - 2)){
grid.setColor(row, col, Color.RED);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.