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

Pencil in Array & Function & Loop



int [] highPen = {
  75, 150
};
int [] colorr = {
  51, 102, 25
};
int a = 150;
void setup () {
  size (350, 300);
}
void draw () {
  background (204, 255, 0);
  text ("Pess Down or UP Arrow to control them",(width/2)-100 ,height-50 );
  int highPenY= a;
  for (int i=0; i<highPen.length; i++) {
    draw_pencil (highPen[i], colorr[i]);
  }
  draw_pencil (highPenY, colorr[2]);

  if (keyCode == DOWN) {
    a = a +1;
  }
  else {
    a = a -1;
    if (a <= 0) {
      a =height-50;
    }
  }
}

void draw_pencil (int highPen, int colorr) {
  noStroke ();
  fill (153, colorr, 0);
  triangle (20, highPen, 70, (highPen-20), 70, (highPen+20));
  rect (70, highPen-20, 200, 40);
  fill (255);
  rect (270, highPen-20, 30, 40);
  fill (0);
  triangle (20, highPen, 40, (highPen-7), 40, (highPen+7));
}

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

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