
import javax.swing.*;
import objectdraw.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;

import cs134lib.*;

/*
 * A program to illustrate how to access and modify the
 * pixel array for an image.
 */
public class SimpleImages extends WindowController {

  private static final int WINDOW_WIDTH = 640;
  private static final int WINDOW_HEIGHT = 560;

  private VisibleImage display;

  public void begin() {
    this.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    
    Image original = getImage("gray-1.jpg");
    display = new VisibleImage(original, 0, 0, canvas);
  }

  public void onMouseClick(Location pt) {
    // get the Image from the displayed VisibleImage
    Image image = display.getImage();
    
    // convert the Image to a 2-d pixel array
    int[][] pixels = Images.imageToPixelArray(image);
    
    // create a black line across the image
    for (int x = 0; x < 500; x++) {
      pixels[x][100] = 0;
    }
    
    // convert pixel array back to Image and put it on the canvas.
    Image newImage = Images.pixelArrayToImage(pixels);
    display.setImage(newImage);
    
  }
}
