import objectdraw.*;
import java.awt.*;

// program to draw a scarf upon mouse click.

public class Knitting extends WindowController {

  private static final int DIAMETER = 12; // diameter of a stitch

  // spacing between stitches -- will overlap
  private static final int X_DISP = 8;
  private static final int Y_DISP = 8;

  private static final int SCARF_WIDTH = 12; // num stitches per row
  private static final int SCARF_HEIGHT = 40; // num stitches per column

  private static final Color SCARF_COLOR = Color.blue;  // scarf color

  public void begin() {
    new Text("Click to make a scarf", 10, 10, canvas);
  }

  // draws a scarf with upper left at point of click
  public void onMouseClick(Location point) {
    double y = point.getY(); // y position of the next "stitch"
    int numRows = 0;

    // draw SCARF_HEIGHT rows 
    while (numRows < SCARF_HEIGHT) {

      double x = point.getX();  // / x position of the next "stitch"
      int numCols = 0;

      // draw one row consisting of SCARF_WIDTH circles
      while (numCols < SCARF_WIDTH) {
        FramedOval stitch = new FramedOval(x, y, DIAMETER, DIAMETER, canvas);
        stitch.setColor(SCARF_COLOR);
        x = x + X_DISP;
        numCols = numCols + 1;
      }

      y = y + Y_DISP;
      numRows = numRows + 1;
    }
  }
}
