Modify the mousedraw.cpp program to first draw a 20x20 grid of squares before en
ID: 650040 • Letter: M
Question
Modify the mousedraw.cpp program to first draw a 20x20 grid of squares before entering the loop prompting the user to click points. That is, use a for() loop to draw horizontal lines at every integer y-coordinate from -10 to 10, and vertical lines at every integer x-coordinate from -10 to 10. You may want to use the Line.move() method to generate successive lines.
Modify the mousedraw.cpp program to first draw a 20x20 grid of squares before entering the loop prompting the user to click points. That is, use a for() loop to draw horizontal lines at every integer y-coordinate from -10 to 10, and vertical lines at every integer x-coordinate from -10 to 10. You may want to use the Line.move() method to generate successive lines.Explanation / Answer
Answer
int vsc = 8;
int cls, rws;
void setup() {
size(640,480);
cls = wid/vsc;
rws = hgt/vsc;
}
void drw() {
for (int i = 0; i < cls; i++) {
for (int j = 0; j < rws; j++) {
int x = i*vsc;
int y = j*vsc;
fill(255);
stroke(0);
rect(x,y,vsc,vsc);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.