วันเสาร์ที่ 12 กันยายน พ.ศ. 2558

numline 1234567

void setup(){
  int i=0;
  int n=8;
  while(i<n){
    int re=n-i;
    numline(re);
    i++;
  }
}

void numline(int n){
  int i=1;
  while (i<=n){
   print(i+" "); 
   i++;
  }
  println();
}

วันศุกร์ที่ 11 กันยายน พ.ศ. 2558

Error Encountered

Error : Infinite loop
Cause : ลืมใส่ x++; ทำให้ เงื่อนไขเป็นจริงตลอดแล้วค้าง
Fix : ใส่ x++ ใน loop;
Error : the variable may not have been initialized
Cause : ไม่ได้กำหนดค่าให้ตัวแปร
Fix : กำหนดค่าให้ตัวแปร

Lab04 : Song

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

void draw()
{
  background(#FA3F58);
  int y=0;
  if (mouseX>=width/2) {
    while (y<mouseY) {
      tobu(mouseX, y, 255, 130);
      y+=130;
    }
  } else {
    tobu(mouseX, mouseY, 255, 130);
  }
}

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.627, y+h*0.231, w*0.235, h*0.16);
}


Lab04 : Book

int w=500, shown=0;
void setup() {
  size (500, 500);
  frameRate(30);
}
void draw() {
  fill(100, 50);
  rect(0, 0, width, height);
  if (w>250) {
    keroro(0, 0, w, w);
    w-=1;
    if (w==250)shown=1;
  }
  if (shown==1) {
    int i=0, j=0, dx=0, dy=0;
    while (i<2) {
      while (j<2) {
        keroro(dx, dy, w, w);
        dx+=w;
        j++;
      }
      j=0;
      dx=0;
      dy+=w;
      i++;
    }
  }

  if (mousePressed) {
    shown=0;
    w=500;
  }
}


void keroro(int x, int y, int w, int h) {
  //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);

  //mouth1
  fill(255);
  arc(x+w*0.5, y+h*0.725, w*1.4, h*0.375, QUARTER_PI+PI, 2*PI-QUARTER_PI);
  //mouth2
  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*7/20, w/3, h/4);
  fill(0);
  ellipse(x+w*0.23, y+h*7/20, w/6, h/8);
  fill(255);
  ellipse(x+w*0.77, y+h*7/20, w/3, h/4);
  fill(0);
  ellipse(x+w*0.77, y+h*7/20, w/6, h/8);

  //TEXT
  textSize(w*0.1);
  text("KERORO", x+w*0.3, y+h-20);
}


Lab04 : Movie

int x=0, z=30;
void setup() {
  background(0, 255, 255); 
  size(500, 500);
}
void draw()
{
  fill(x, 50);
  rect(0, 0, width, height);
  if (x<=255) {
    x++; 
    if (x>=255)
      x=255;
  }
  while (z<width && mousePressed) {
    if (mouseButton==RIGHT)
      doraemon(mouseX+30+z, mouseY+30, 30, 30, (z+1)%2);
    else
      doraemon(mouseX+30-z, mouseY+30, 30, 30, (z+1)%2);
    z+=30;
  }
  if (!mousePressed)
    z=0;
  doraemon(mouseX+30, mouseY+30, 30, 30, 1);
}

void doraemon(int posX, int posY, int w, int h, int eye) {
  strokeWeight(0);
  //face
  fill(0, 153, 255);
  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==1) {
    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
  {
    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);
  }
  //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);
}


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

Lab04 : Loan

//nf(variable ,left digit , right digit)
void setup(){
  loan(5000,0.12,1); //5000baht 12percent 1year
}

void loan(float amt,float rate,int yr){
  int month=yr*12;
  float ratepm=rate/12; // rate per month per year
  float ppm=amt * ( ratepm / (1 - pow(1 + ratepm,-month))); //pay per month  (pri+interest)
  float pri=ppm; // principal
  float unpaid=amt; // unpaid
  float total_interest=0;
  int i=1;
  println("No. Interest Principal  Unpaid   total interest");
  while (i<=month){
   print(nf(i,2));//NO.
   print("    "+nf(ratepm*unpaid, 2,2));//interest 
   total_interest+=ratepm*unpaid; 
   pri=ppm-(ratepm*unpaid); 
   unpaid-=pri; 
   if (unpaid<0)unpaid=0;
   print("   "+nf(pri,3,2)); // principal 
   print("    "+nf(unpaid,4,2)); // unpaid 
   print("      "+nf(total_interest ,3,2)); //total_interest
   println();
   i++;
  }
}


วันจันทร์ที่ 7 กันยายน พ.ศ. 2558

Lab04 : Multiplication Table

void setup() {
  multable(0, 12, 5);
}

void multable(int i, int row, int N) {
  while (i<=row) {
    int mul = N * i ; 
    println( +N+ " * " + i + " = " +mul) ;
    i += 1 ;
  }
}


Lab04 : Prime Sum

void setup() {
  println(prime_sum(30));
}

int prime_sum(int n) {

  int i=2, sum=0;
  while (i<=n) {
    if (is_prime(i)) {
      sum+=i;
    }
    i++;
  }
  print("=");
  return sum;
}

boolean is_prime(int num) {
  boolean prime=true;
  int i=2;
  while (i<num) {
    if (num%i==0)
      prime=false;
     i++; 
  }
  if (num==1)
    prime=false;
  return prime;
}


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

Lab04 : Flocks of Birds

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);
  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);
  draw_bird(mouseX, mouseY, 2, 2);
}

void draw_bird(int x, int y, int amount, int flocks) {
  int z=1, i=0, dx=0, dy=0, con=70;
  while (z=<flocks) {
    while (i<amount) {
      stroke(255);
      line(x+dx, y+dy, x-50+dx, wing_original+dy); //left
      line(x+dx, y+dy, x+50+dx, wing_original+dy); //right
      fill(0);
      ellipse(x+dx, y+dy, 30, 30);
      noStroke();
      fill(255, 255, 0);
      triangle(x-5+dx, y+dy, x+5+dx, y+dy, x+dx, y+9+dy);
      i++;
      dx+=120;
    }
    i=0;
    dx=z*70;
    z++;
    dy+=120;
  }
}

void cloud(float x, float y, int size) {  
  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);
}


Lab04 : Balloons

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

void draw() {
  background(51);
  strokeWeight(5);
  stroke(#FF760D);
  int x=40;
  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;
  int i=0;
  while (i<6) {
    line(x, y, x, y+120);
    ellipse(x, y, radius, radius);
    x+=90;
    i++;
  }
}


Lab04 : Summation

void setup() {
  println(summ(10));
}


int summ(int i) {
  int sum=0;
  for (int x=1;x<=i;x++){
    sum+=x;
  }
  return sum;
}


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

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