วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558

LAB 4 PrimeNumber

void setup() {
  size(600, 400);
  background(0);
  int count = 0; // is start count to finish
  int finish = 100;
  text_sum(20, 20, count, finish, sum(count, finish));
}





//function for text
void text_sum(int X, int Y, int start, int finish, int sum) {
  textSize(20);
  text(" Sum Prime Number of      "+start, X, Y);
  text(" To "+finish, X+300, Y);
  text(" Sum is "+sum, X, Y+40);
  draw_prim(X,Y,start,finish);
}




//function for fine sum
int sum(int count, int finish) {
  int sum=0;
  while (count<=finish) {
    if (fineBoolean(count)) {
      sum = sum+count;
    }
    count++;
  }
  return sum;
}





// function for cheack boolean
boolean fineBoolean(int count) {
  if ((count!=2&&count%2==0)||count==1||(count!=3&&count%3==0)||(count!=5&&count%5==0)||(count!=7&&count%7==0)) {
    return false;
  }
  return true;
}




//function draw number that is prim
void draw_prim(int X,int Y,int count,int finish){
  text(" Prime number set is", X , Y+70);
  Y +=100;
  X +=20;
  while (count<=finish) {
    if (fineBoolean(count)) {
      if(X<530){
        X += 40;
        text(+count,X,Y);
      }else{
        X = 20;
        Y += 50;
        text(+count,X,Y);
      }
    }
    count++;
  }
}


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

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