Knitting.java

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_HT = 40;        // num stitches per column

    private static final Color SCARF_COLOR = Color.blue;
    
    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 x = point.getX();
        double y = point.getY();    // x and y positions of the next "stitch"
        
        int numRows = 0;                 
        int numCols = 0;
        
        while (numRows < SCARF_T) {      
          while (numCols < SCARF_WIDTH) {
              new FramedOval(x, y, DIAMETER, DIAMETER, 
                             canvas).setColor(Color.green);
              x = x + X_DISP;
             numCols = numCols + 1;
          }
            
          x = point.getX();           
          y = y + Y_DISP;             
          numCols = 0;                
          numRows = numRows + 1;      
        }
    }