วันศุกร์ที่ 26 กรกฎาคม พ.ศ. 2556

^O^ Binary Calculate Plus & Display ^O^



//define Array of  is Gobal variable
boolean [] A = {
  true, false, true, true
};//put in first number to you want calculate
boolean [] B = {
  true, false, true, false
}; //put in second number to you want calculate
boolean [] C= new boolean [5]; //show the result and define count of index in boolean
boolean [] note = {
  false, false
}; //show the number to note
int index = 0;
int start = 65;
int r = 100;
void setup () {
  size (550, 250);
  background (102, 051, 000);
  index = A.length-1;
    while (index >= 0) {
    if (A[index] == true && B[index] == true) {
      note [0] = true;
      C[index] = false;
      if (note[1] == true) {
        C[index] = true;
      } //clear old note
      else {
        C[index] = false;
      }
      note[1] = note [0]; //move the number note to new column
    }
    else if (A[index] == false && B[index] == false) {
      note[0] = false; //set value of note is zero or clear note[0]
      C[index] = false;
      if (note[1] == true) {
        C[index] = true;
      }
      else {
        C[index] = false;
      } //maybe accidence
      note[1] = note [0]; //move the number note to new column
    }
    else { //cotinue frist up
      note[0] = false; // just expain and nothing all right
      C[index] = true;
      if (note [1] == true) {
        C[index] = false;
        note[0] = true;  //use in case 11 + 01 = 100 or next number is 1 + 0 , 0+1 from 1 + 1
      }
      else {
        C[index] = true; //if other case is all true such as 1+1 , 0+0
      }
      note[1] = note[0];
    }
    index = index - 1; //define for stop loop by do lower value
  } //finished loop (just do one time)
 
  if (A[0] == true && B[0] == true) { //new order to print result
    print ("1");
  }
  index = 0; //define new value of index
  while (index < A.length && index < B.length) { //normaly index must lesser than length of Array
    if (C[index] == true) {
      print ("1");
    }
    if (C[index] == false) {
      print ("0");
    }
    index = index + 1;
  }
  index = 0;
   while (index < C.length) {
    if (C[index] == true) {
      fill (255, 000, 102);
      stroke (255, 255, 000);
      strokeWeight (2);
      ellipse (start, 125, r, r);
      start = (start + r)+5;
    }
    else {
    fill (153, 255, 000);
    ellipse (start, 125, r, r);
    start = (start + r)+5;
    }
    index = index + 1;
  }
}

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

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