วันพฤหัสบดีที่ 3 กันยายน พ.ศ. 2558

Lab03 : Delivery Charge

// packagetype -> letter=1 , box=2
// service type -> NextDayPriority=1 , NextDayStandard=2 , 2-DAY=3

void setup() {
  size(350, 150); 
  background(51);
  textSize(15);
  int packagetype=2;
  int servicetype=1;
  int weight=1;
  String charge="";
  if (packagetype==1) {
    charge="Package Type : Letter\n";
  } else if (packagetype==2) {
    charge="Package Type : Box\n";
  }
  if (servicetype==1) {
    charge+="Service Type : Next Day Priority\n";
  } else if (servicetype==2) {
    charge+="Service Type : Next Day Standard\n";
  } else if (servicetype==3) {
    charge+="Service Type : 2-Day\n";
  }
  if (packagetype == 1 && servicetype==3) {
    //do noting
  } else if (packagetype==1) {
    charge+="Weight : " + weight +" oz\n";
  } else if (packagetype==2) {
    charge+="Weight : " + weight +" pound\n";
  }
  charge+=delivery_charge(packagetype, servicetype, weight);
  text(charge, (width-textWidth(charge))/2, 50);
}

String delivery_charge (int pktype, int svtype, int weight) {
  float chargebox=0;
  String text1="";
  //================== start package 1 ==================//
  if (pktype==1) {
    if (svtype==1) { //service type 1
      if (weight<=8 && weight>0) {
        fill(#49E34A);
        text1="CHARGE :$ 12.00";
      } else {
        fill(255, 0, 0);
        text1="Not Avaliable - incorrect weight";
      }
    } else if (svtype==2) { // service type 2
      if (weight<=8 && weight>0) {
        fill(#49E34A);
        text1="CHARGE :$ 10.50";
      } else {
        fill(255, 0, 0);
        text1="Not Avaliable - incorrect weight";
      }
    } else if (svtype==3) { // service type 3
      fill(255, 0, 0);
      text1="Not Avaliable";
    }
  }
  // end package1
  //================== start package 2 ==================//
  if (pktype==2) {
    if (svtype==1) {
      if (weight>0) {
        fill(#49E34A);
        chargebox=15.75+(weight-1)*1.25;
        text1="CHARGE :$ "+chargebox;
      } else {
        fill(255, 0, 0);
        text1="Not Avaliable - incorrect weight";
      }
    } else if (svtype==2) {
      if (weight>0) {
        fill(#49E34A);
        chargebox=13.75+weight-1;
        text1="CHARGE :$ "+chargebox;
      } else {
        fill(255, 0, 0);
        text1="Not Avaliable - incorrect weight";
      }
    } else if (svtype==3) {
      if (weight>0) {
        fill(#49E34A);
        chargebox=7.00+(weight-1)*0.5;
        text1="CHARGE :$ "+chargebox;
      } else {
        fill(255, 0, 0);
        text1="Not Avaliable - incorrect weight";
      }
    }
  }
  // end package2 


  return text1;
}

Lab03 : Power of ten

void setup() {
  size(350, 150); 
  background(51);
  textSize(15);
  int year=12;
  String power="   " + year + "\n10      = " + powerof_ten(year);
  text(power, (width-textWidth(power))/2, 75);
}

String powerof_ten(int number) {
  String texts;
  fill(#49E34A);
  if (number==6) {
    texts="Million";
  } else if (number==9) {
    texts="Billion";
  } else if (number==12) {
    texts="Trillion";
  } else if (number==15) {
    texts="Quadrillion";
  } else if (number==18) {
    texts="Quintillion";
  } else if (number==21) {
    texts="Sextillion";
  } else if (number==30) {
    texts="Nomillion";
  } else if (number==100) {
    texts="Googol";
  } else {
    fill(255,0,0);
    texts="No Name";
  }
  return texts;
}


Lab03 : Leap year

void setup() {
  size(350, 150); 
  background(51);
  textSize(15);
  int yearr=1976;
  String leapyear_t=yearr + " is " + leapyear(yearr);
  text(leapyear_t, (width-textWidth(leapyear_t))/2, 75);
  for (int i=0;i<401;i++){
   println(1804+i +" is " +leapyear(1804+i)); 
  }
}

String leapyear(int number) {
  String texts;
  if ((number%4==0 && number%100!=0) || (number%4==0 && number%100==0 && number%400==0)) {
    fill(#49E34A);
    texts="a Leap Year";
  } else {
    fill(#E50505);
    texts="not a Leap Year";
  }
  return texts;
}


วันพุธที่ 2 กันยายน พ.ศ. 2558

Lab03 : Calc_Grade

void setup() {
  size(250, 250);
  background(33);
  calc_grade(80);
}

void calc_grade(int score) {
  String grade="";
  if (score<=100) {
    grade="A";
    if (score<80) {
      grade="B";
      if (score<70) {
        grade="C";
        if (score<60) {
          grade="D";
          if (score<50) {
            grade="F";
            if (score<0) {
              grade="score below 0";
            }
          }
        }
      }
    }
  } else {
    grade="score over 100";
  }
  textSize(20);
  fill(#16AA03);
  String texts="Score : " + score + "\nGrade : " + grade;
  text(texts, 75, 120);
}



Problem
1.ใช้ตัวแปรชื่อ text แล้วตัวหนังสือไม่ขึ้น
    how to fix : เปลี่ยน text เป็น texts

Lab03 : Song

void setup() {
  size(450, 300); //(450,300)
  background(#FA3F58);
  smooth();
}

void draw()
{
  if (frameCount%60>=59) {
    tobu(int(random(0,255)), int(random(0,170)), 255, 130);
  } else {
    fill(#FA3F58, 50);
    rect(0, 0, width, height);
  }
}

void tobu(int x, int y, int w, int h) {
  fill(255);
  noStroke();
  fill(100, 100, 100, 150);
  quad(x+w*0.0314, y+h*0.731, x+w*0.876, y+h*0.731, x+w*0.882, y+h*0.78, x+w*0.047, y+h*0.78);

  //T
  fill(255);
  quad(x, y, x+w*0.43, y, x+w*0.35, y+h*0.154, x+w*0.078, y+h*0.154);
  quad(x+w*0.196, y+h*0.154, x+w*0.294, y+h*0.154, x+w*0.118, y+h*0.731, x+w*0.02, y+h*0.731);
  stroke(#FA3F58);
  strokeWeight(4);
  line(x+w*0.36, y, x+w*0.314, y+h*0.154);

  //B
  fill(255);
  ellipse(x+w*0.53, y+h*0.5, w*0.263, h*0.5);
  fill(#FA3F58);
  ellipse(x+w*0.53, y+h*0.5, w*0.098, h*0.1923);
  fill(255);
  noStroke();
  triangle(x+w*0.416, y+h*0.423, x+w*0.416, y+h*0.0769, x+w*0.51, y+h*0.3);


  //O
  stroke(#FA3F58);
  ellipse(x+w*0.314, y+h*0.5, w*0.263, h*0.5);
  fill(#FA3F58);
  ellipse(x+w*0.314, y+h*0.5, w*0.098, h*0.1923);

  //U
  stroke(#FA3F58);
  fill(255);
  ellipse(x+w*0.745, y+h*0.5, w*0.263, h*0.5);
  fill(#FA3F58);
  ellipse(x+w*0.745, y+h*0.5, w*0.098, h*0.1923);
  rect(x+w*0.635, y+h*0.28, w*0.220, h*0.1);
}


Lab03 : Movie

int c=-1;
int count=0;
void setup() {
  background(51); 
  size(600, 600);
  show_tab();
}
void draw()
{
  if (keyPressed && (key=='c' || key=='C')) {
    background(51);
    show_tab();
    count=0;
  }
}
void mousePressed() {
  c=(c+1)%3;
  doraemon(mouseX, mouseY, 250, 250, c, color(random(255), random(255), random(255)));
  count++;
  show_tab();
}

void show_tab() {
  textSize(15);
  fill(255);
  rect(0, 550, 600, 50);
  fill(51);
  text(count, 580, height-10);
  text("CLICK MOUSE TO DRAW DORAEMON | PRESS 'C' TO CLEAR", 2, height-10);
}
void doraemon(int posX, int posY, int w, int h, int eye, color colors) {
  strokeWeight(4);
  //face
  fill(colors);
  ellipse(posX, posY, w, h);
  fill(255);
  ellipse(posX, posY+h*0.0875, 0.82*w, 0.825*h);

  //eye
  ellipse(posX-w*0.11, posY-h*0.3, w*0.175, h*0.2125);
  ellipse(posX+w*0.11, posY-h*0.3, w*0.175, h*0.2125);
  fill(0);
  noFill();
  if (eye==0) {
    arc(posX-w*0.11, posY-h*0.3, 0.05*w, 0.05*h, PI, 2*PI);
    arc(posX+w*0.11, posY-h*0.3, 0.05*w, 0.05*h, PI, 2*PI);
  } else if (eye==1)
  {
    fill(0);
    ellipse(posX-w*0.11, posY-h*0.3, 0.03*w, 0.05*h);
    ellipse(posX+w*0.11, posY-h*0.3, 0.03*w, 0.05*h);
    fill(255);
    ellipse(posX-w*0.11, posY-h*0.3, 0.02*w, 0.03*h);
    ellipse(posX+w*0.11, posY-h*0.3, 0.02*w, 0.03*h);
  } else if (eye==2)
  {
    fill(0);
    rectMode(CENTER);
    rect(posX-w*0.11, posY-h*0.3, 0.03*w, 0.001*h);
    rect(posX+w*0.11, posY-h*0.3, 0.03*w, 0.001*h);
    rectMode(CORNER);
  }
  //nose
  fill(204, 51, 0);
  ellipse(posX, posY-0.175*h, 0.0875*w, 0.0875*h);
  line(posX, posY-0.1325*h, posX, posY+w*0.075);

  //mus left
  line(posX-w*0.05, posY-h*0.0875, posX-w*0.25, posY-h*0.125);
  line(posX-w*0.05, posY-h*0.0375, posX-w*0.25, posY-h*0.0375);
  line(posX-w*0.05, posY+h*0.0125, posX-w*0.25, posY+h*0.0375);

  //mus right
  line(posX+w*0.05, posY-h*0.0875, posX+w*0.25, posY-h*0.125);
  line(posX+w*0.05, posY-h*0.0375, posX+w*0.25, posY-h*0.0375);
  line(posX+w*0.05, posY+h*0.0125, posX+w*0.25, posY+h*0.0375);

  //mouth
  noFill();
  arc(posX-w*0.1, posY+h*0.1125, 0.075*w, 0.075*h, PI/2, PI+PI/2);
  fill(255);
  arc(posX, posY+h*0.15, w*0.2, w*0.2, 0, PI);
  line (posX-w*0.1, posY+h*0.15, posX+w*0.1, posY+h*0.15);
}


Lab03 : Book

int sty;
int alpha=255;
int dx=1;
void setup() {
  size (400, 500);
  textSize(30);
}
void draw() {
  background(0);
  if (frameCount%120>=60) {
    sty=1;
  } else
  {
    sty=0;
  }
  keroro(0, 0, width, height, sty);
}

void keroro(int x, int y, int w, int h, int style) {
  //book
  strokeWeight(3);
  fill(#1ED36E);
  rect(x, y, w, h);
  //face
  fill(255);
  rect(x, y, w, h*3/4);

  //yellow cap 
  fill(#F5FF6A);
  rect(x, y, w, h*0.125);
  //star
  fill(#F50529);
  noStroke();
  quad(x+w*0.5, y, x+w*0.55, y+h*0.1, x+w*0.5, y+h*0.075, x+w*0.45, y+h*0.1);
  triangle(x+w*0.42, y+h*0.0375, x+w*0.58, y+h*0.0375, x+w*0.5, y+h*0.075);

  //green face
  stroke(0);
  strokeWeight(3);
  fill(#33AF47);
  rect(x, y+h*0.125, w, h*0.46);

  //white arc
  fill(255);
  arc(x+w*0.5, y+h*0.725, w*1.4, h*0.375, QUARTER_PI+PI, 2*PI-QUARTER_PI);
  //mouth + eye
  if (style==0) {
    fill(#FA7474);
    arc(x+w*0.5, y+h*0.54, w*0.25, h*0.125, 0, PI);
    //eye
    fill(255);
    ellipse(x+w*0.23, y+h*0.35, w/3, h/4);
    fill(0);
    ellipse(x+w*0.23, y+h*0.35, w/6, h/8);
    fill(255);
    ellipse(x+w*0.77, y+h*0.35, w/3, h/4);
    fill(0);
    ellipse(x+w*0.77, y+h*0.35, w/6, h/8);
  } else
  {
    fill(#FA7474);
    arc(x+w*0.5, y+h*0.54, w*0.15, h*0.21, 0, PI);
    //eye
    fill(255);
    ellipse(x+w*0.23, y+h*0.35, w/3, h/4);
    fill(0);
    line(x+w*0.15, y+h*0.30, x+w*0.29, y+h*0.35);
    line(x+w*0.15, y+h*0.40, x+w*0.29, y+h*0.35);
    //ellipse(x+w*0.23,y+h*7/20,w/6,h/8);
    fill(255);
    ellipse(x+w*0.77, y+h*0.35, w/3, h/4);
    fill(0);
    ellipse(x+w*0.77, y+h*0.35, w/6, h/8);
  }
  //TEXT
  textSize(w*0.1);
  if (alpha<=0 || alpha>=255)
  {
    dx*=-1;
  }
  alpha+=dx;
  fill(255, alpha);
  text("KERORO", x+w*0.3, y+h-20);
}


วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558

Lab03 : Battery Charge/Uncharge

int wide=270, high=75;
float batt=225; //PERCENT TAB LENGTH
float percentB; //PERCENT
int dx=1; //DIRECTION OF PERCENT TAB -> '1' + , '0' -
void setup() {
  size(350, 250);
}
void draw() {
  int x=70;
  int y=110;
  String status;
  background(51);
  strokeWeight(4);
  stroke(0);
  // make battery charge/uncharge
  if (dx==1) {
    batt++;
    if (batt>225)batt=225;
  }
  if (dx==0) {
    batt--;
    if (batt<=0)batt=0;
  }
  percentB=batt/225*100;

  //Drawing
  draw_battery(x, y, wide, high);
  //INDICATE COLOR AND STATUS TEXT
  status="OK";
  if (percentB<=100) {
    fill(#3BC149);
    status="OK";  
    if (percentB<=80) {
      fill(#95FF03);
      status="Below 80%";
      if (percentB<=50) {
        fill(255, 0, 0); 
        status="Please Charge";
      }
    }
  }
  //DRAW PERCENTAB
  rect(x+(wide/12), y, batt, high); 
  textSize(30);
  text(int(percentB) + "% " + status, x, y-30); //PERCENT TEXT
  //DRAW + AND - SIGNS
  positive_sign(x+0.1*wide, y+0.4*high, 5);
  negative_sign(x+0.8*wide, y+0.4*high, 5);
}

void mousePressed() {
  if (mouseButton==LEFT) {
    dx=1;
  } else
  {
    dx=0;
  }
}



void draw_battery(int posX, int posY, int wide, int high) {
  fill(255); 
  //HEAD
  rect(posX, posY+(0.2*high), wide/12, high*3/5);
  //Body Battery
  rect(posX+(wide/12), posY, wide*5/6, high);
}

void positive_sign(float x, float y, int sizebox) {
  noStroke();
  fill(51, 0, 0);
  rect(x+sizebox, y, sizebox, sizebox);
  rect(x+2*sizebox, y+sizebox, sizebox, sizebox);
  rect(x+sizebox, y+sizebox, sizebox, sizebox);
  rect(x+sizebox, y+2*sizebox, sizebox, sizebox);
  rect(x, y+sizebox, sizebox, sizebox);
}

void negative_sign(float x, float y, int sizebox) {
  noStroke();
  fill(51, 0, 0);
  rect(x+2*sizebox, y+sizebox, sizebox, sizebox);
  rect(x+sizebox, y+sizebox, sizebox, sizebox);
  rect(x, y+sizebox, sizebox, sizebox);
}


Balloon

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

void draw() {
  background(51);
  strokeWeight(5);
  stroke(#FF760D);
  int x=250;
  int y=mouseY;
  if (y<40) {
    y=40; 
    fill(#E0A171);
  } else if (y>460) {
    y=460;
    fill(#365189);
  } else {
    fill(255);
  }

  draw_balloon(x, y);
}

void draw_balloon(int x, int y) {
  int radius=80;
  line(x, y, x, y+120);
  ellipse(x, y, radius, radius);
}


Lab03 : Bird

int wing_original;
int dx=1;
void setup() {
  size(500, 500);
  strokeWeight(5);
}

void draw() {
  background(51);
  wing_original=mouseY;
  if (frameCount%30>=15) {
    wing_original+=30;
  } else
  {
    wing_original-=30;
  }
  dx=(dx+1)%200;
  stroke(255);
  draw_bird(mouseX, mouseY);
  cloud(dx, 50, 50);
  cloud(170+dx*0.8, 50, 70);
  cloud(350+dx*0.9, 80, 60);
  cloud(dx*1.2, 130, 40);
  cloud(230+dx*1.2, 150, 40);
  cloud(100+dx*1.2, 170, 40);
}

void draw_bird(int x, int y) {
  line(x, y, x-50, wing_original); //left
  line(x, y, x+50, wing_original); //right
  fill(0);
  ellipse(x, y, 30, 30);
  noStroke();
  fill(255,255,0);
  triangle(x-5, y, x+5, y, x, y+9);
}
void cloud(float x, float y, int size) { //100 width   noStroke();   fill(#02F0D2);   ellipse(x, y, size, size);   x+=size/2;   ellipse(x, y, size, size);   ellipse(x, y-size/4, size, size);   ellipse(x, y+size/4, size, size);   x+=size/2;   ellipse(x, y, size, size);   ellipse(x, y-size/4, size, size);   ellipse(x, y+size/4, size, size);   x+=size/2;   ellipse(x, y, size, size); }

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...