วันพุธที่ 1 ตุลาคม พ.ศ. 2557

Balloon in Array & Loop & Function


int [] y = {
  500, 400, 300
};

int [] x = {
  100, 200, 300
};

int [] R = {
  255, 153, 0
};

int [] G = {
  0, 255, 51
};

int [] B = {
  153, 0, 255
};
int [] size = {
  75, 100, 150
};
void setup() {
  size(400, 400);
}
void draw() {
  background(255);
  for (int i=0; i<y.length; i++) {
    fill (R[i], G[i], B[i]);
    draw_balloon(x[i], y[i], size[i]);
    y[i]=y[i]-1;
    if (y[i] <= 0) {
      y[i] = height;
    }
  }
}
void mousePressed () {
  for (int i=0; i<y.length; i++) {
    if (mouseButton==LEFT&&mouseX>=(x[i])&&mouseX<=(x[i]+size[i]))
    {
      y[i] = height+100;
    }
  }
}
void draw_balloon(int x, int y, int size) {
  strokeWeight(3);
  stroke (0);
  line(x, y, x, y+size);
  noStroke();
  ellipse(x, y, size, size);
}

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

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