Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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);
    }
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote