import processing.core.*; 
import processing.xml.*; 

import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 
import java.util.regex.*; 

public class drawing extends PApplet {

/**
 * megaboring roberttwomey 
 * 
 */
 
PImage a;
int x, y;

boolean drawnext;
int blockscale;

public void setup()
{
  //a = loadImage("eames.jpg");
  a = loadImage("six.jpg");
  //a = loadImage("six_160_10levels.jpg");
  //size(a.width*5, a.height*5);
  size(640, 480);
  noStroke();
  background(255);
  smooth();
  x=0;
  y=0;  
  drawnext=false;
  blockscale=3;
  tint(0, 32);
  a.draw(0, 0, width, height);
}

public void keyPressed() {
  drawnext = true;
}

public void draw()
{ 
  if(drawnext) {
    int pix = a.get(x, y);
    fill(brightness(pix), 194);
    rect(x, y, blockscale, blockscale);
    x+=blockscale;
    if(x>=640) {
      x=0;
      y+=blockscale;
      if(y>=480) y=0;
    };  
    drawnext=false;
  }
}

class DrillBlock {
  DrillPt[] points = new DrillPt[25];
  int value;
  int numpoints;
  boolean transpose;

  DrillBlock() {
    this.points = new DrillPt[25];
    for(int i=0; i<10; i++) {
      this.points[i] = new DrillPt();
      this.points[i].set(0.0f,0.0f);
    }
    this.numpoints=0;
    this.value=-1;
    this.transpose=false;
  }

  DrillBlock(int _val) {
    this.points = new DrillPt[25];
    for(int i=0; i<10; i++)
      this.points[i].set(0.0f,0.0f);
    
    this.numpoints=0;
    this.set(_val);
    this.transpose=false;
  }

  public void set(int _val) {
    this.value = (int)map(_val, 0, 255, 5, 0);
    this.numpoints=this.value;
    //println(_val+" "+this.value);  
    /*for(int i=0; i<this.numpoints; i++) {
      for(int
      this.points[i].set(
    
    switch(this.value) {
      case 0:
        break;
      case 1:
        this.points[0].set(0.5, 0.5);
        break;
      case 2:
        this.points[0].set(0.25, 0.25);
        this.points[1].set(0.75, 0.75);
        break;
      case 3:
        this.points[0].set(0.5, 0.25);
        this.points[1].set(0.25, 0.75);
        this.points[2].set(0.75, 0.75);
        break;
      case 4:
        this.points[0].set(0.25, 0.25);
        this.points[1].set(0.75, 0.25);
        this.points[2].set(0.75, 0.75);
        this.points[3].set(0.25, 0.75);
        break;
      case 5:
        this.points[0].set(0.25, 0.25);
        this.points[1].set(0.75, 0.25);
        this.points[2].set(0.75, 0.75);
        this.points[3].set(0.25, 0.75);
        this.points[4].set(0.5, 0.5);
        break;
      case 6:
        this.points[0].set(0.25, 0.25);
        this.points[1].set(0.25, 0.5);
        this.points[2].set(0.25, 0.75);
        this.points[3].set(0.75, 0.25);
        this.points[4].set(0.75, 0.5);
        this.points[5].set(0.75, 0.75);
        break;
      case 7:
        this.points[0].set(0.25, 0.25);
        this.points[1].set(0.25, 0.5);
        this.points[2].set(0.25, 0.75);
        this.points[3].set(0.75, 0.25);
        this.points[4].set(0.75, 0.5);
        this.points[5].set(0.75, 0.75);
        this.points[6].set(0.5, 0.5);
        break;
      case 8:
        this.points[0].set(0.25, 0.25);
        this.points[1].set(0.25, 0.5);
        this.points[2].set(0.25, 0.75);
        this.points[3].set(0.75, 0.25);
        this.points[4].set(0.75, 0.5);
        this.points[5].set(0.75, 0.75);
        this.points[6].set(0.5, 0.33);
        this.points[7].set(0.5, 0.67);
        break;
      case 9:
        this.points[0].set(0.25, 0.25);
        this.points[1].set(0.25, 0.5);
        this.points[2].set(0.25, 0.75);
        this.points[3].set(0.75, 0.25);
        this.points[4].set(0.75, 0.5);
        this.points[5].set(0.75, 0.75);
        this.points[6].set(0.5, 0.25);
        this.points[7].set(0.5, 0.5);
        this.points[8].set(0.5, 0.75);
        break;
      default:
        this.numpoints=0;
        break;
    }*/
  }

  public void draw(int x, int y) {
    fill(this.value*25.5f);
    rect(x, y, 5, 5);
  }

  public void draw(int x, int y, int w, int h, int r) {
    //println(this.value*25.5+" "+this.numpoints);
    ellipse(x, y, r, r);
  }
}


class DrillPt {
  float x;
  float y;

  DrillPt() {
    this.x = 0;
    this.y = 0;
  }
  
  DrillPt(float _x, float _y) {
    set(_x, _y);
  }
  
  public void set(float _x, float _y) {
    this.x=_x;
    this.y=_y;
  } 

  public float getx() {
    return x;
  }
  public float gety() {
    return y;
  }
}


  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#FFFFFF", "drawing" });
  }
}
