วันอังคารที่ 1 กันยายน พ.ศ. 2558

Lab2-Positive(Function)

int resizeW;
int resizeH;
int weight = 100;
int high = 300;

void setup() {
  size(500, 500);
}

void draw() {
  background(255);
  positive(mouseX-(weight/2), mouseY-(high/2), weight, high);
  weight = weight + resizeW;
  high = high + resizeH;
  if ((weight <= 4 || high <= 12) || (weight >= 320 || high >= 960)) {
    resizeW = 0;
    resizeH = 0 ;
  }
}

void positive(int posX, int posY, int weight, int high) {
  noStroke();
  fill(#FF0000);
  rect(posX, posY, weight, high);
  rect(posX-100, posY+100, weight+200, high-200);
}

void mouseClicked() {
  if (mouseButton == LEFT) {
    resizeW = 3;
    resizeH = 3;
  } else if (mouseButton == RIGHT) {
    resizeW = -3;
    resizeH = -3;
  }
}


ไม่มีความคิดเห็น:

แสดงความคิดเห็น