วันเสาร์ที่ 29 สิงหาคม พ.ศ. 2558

Problems Encountered

Error: missing semicolon
Cause: ลืมใส่ semicolon
How to fix: ใส่ semicolon
Error: function does not exist
Cause: ใส่ชื่อฟังก์ชั่นผิด
How to fix: ใส่ชื่อฟังก์ชั่นให้ถูก
Error: missing parameters
            Cause: ใส่ parameter ในฟังก์ชั่นไม่ครบ
            How to fix: ใส่ parameter ให้ครบทุกตัว
Error: {blankets}
            Cause: ลืมใส่ } ปิดท้าย 
            How to fix: ใส่ } ปิดท้าย
Error : missing right parenthesis
            Cause: ลืมใส่ )
            How to fix: ใส่ ) ปิดท้าย
Error : The variable "sizeox" does not exist
            Cause: ไม่มีตัวแปรชื่อ sizeox อยู่
            How to fix: ประกาศตัวแปรนี้ , เขียนชื่อตัวแปรผิด
Error : Type mismatch,"void" does not match with "int"
            Cause: ประกาศตัวแปรประเภท int = ฟังก์ชั่น void
            How to fix: ตัวแปร int จะต้องเก็บค่า int เท่านั้น เช่น ใส่ฟังก์ชั่นที่ส่งค่ากลับเป็น int

วันพุธที่ 26 สิงหาคม พ.ศ. 2558

Point the box 10 second countdown

int point=0;
int timelimit=11000;
int enable=1;
int boX=300,boY=300;
int previousM=0;
int m; //millisecond
void setup(){
  size(500,500);
  background(0);
  rectMode(CENTER);
  textSize(30);
}


void draw(){
  background(0);


if (enable==1){
  m=millis()-previousM;
  rect(boX,boY,30,30);
  text("Point : "+point,10,30); //show point
   if (mouseX<=boX+15 && mouseX>=boX-15 && mouseY>=boY-15 && mouseY<=boY+15){
     point+=1;
     boX=int(random(width-50));
     boY=int(random(30,height-50));
   }
   text("TIME : "+(timelimit-m)/1000,width-150,30); //SHOW TIME LIMIT
   if (timelimit-m<0){
       enable=0;
       timelimit=11000;
       previousM = millis();
    }

}
else if (enable==0)
{
   text("YOUR POINT IS : "+point,width/2-150,height/2+50);
  text("PRESS R TO RESTART",width/2-150,height/2);
  if (keyPressed && (key=='r' || key=='R')){
    enable=1;
    point=0;

  }
}
}

key & keyCode & point

int x=50,y=50,point=0;
int boX=300,boY=300;
void setup(){
  size(500,500);
  background(0);
  rectMode(CENTER);
}


void draw(){
  background(0);
  rect(boX,boY,30,30);
  text(point,10,20);
  if (keyPressed) {
    if (key == 'w' || keyCode == UP){
      y=(y-5);
      if (y==0)
       y=height;
    }  
    if (key == 's' || keyCode == DOWN){
      y=(y+5)%height;
    }
    if (key == 'a' || keyCode == LEFT){
      x=x-5;
       if (x==0)
       x=width;
    }
    if (key == 'd' || keyCode == RIGHT){
      x=(x+5)%width;
    }
  }
   ellipse(x,y,20,20);
   if (x<=boX+15 && x>=boX-15 && y>=boY-15 && y<=boY+15){
     point+=1;
     boX=int(random(width-50));
     boY=int(random(height-50));
   }
}

วันอังคารที่ 25 สิงหาคม พ.ศ. 2558

Lab02 : Circle

void setup(){
 size(400,150);
 circle_calc(3);

 
}

void circle_calc(float diameter)
{
 float cir=diameter*PI;
 float area=PI*(diameter/2)*(diameter/2);
 textSize(30);
 fill(0);
 background(#FFFCFC);
 text("R = " + diameter/2,0,30);
 text("Circumference = " + cir,0,60);
 text("Area = " + area,0,90);
 println("Circumference of " + diameter + " diameter circle is : " + area);
 println("Area of " + diameter + " diameter circle is : " + area);
}

Lab02 : BMI

void setup(){
  size(400,120);
  background(#7DED65);
  fill(#48A733);
  BMI_CALC(60,175);
}

void BMI_CALC (float weight,float h){
 float d=h/100;
 float BMI=weight/(d*d);
 textSize(30);
 text("BMI : " + BMI,0,30);
 text("Weight : " + weight + " kg",0,60);
 text("Height : " + h + " cm",0,90);
}



Lab02 : Movie

int c=1; //for eye type "1" smile "-1" normal

void setup() {
  background(0,255,255); 
  size(400, 400);
  frameRate(2);

}
void draw()
{
  doraemon(200,200,400,400,c);
  c*=-1;


}

void doraemon(int posX,int posY,int w,int h,int eye){
   strokeWeight(4);
  //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);

}



Lab02 : Song

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

}

void draw()
{
 background(#FA3F58);
 tobu(110+int(random(-2,2)),135,255+int(random(-5,5)),130+int(random(-5,5)));
}

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);
}



Lab02 : Book

int w=260;
int inc=-1;
void setup(){
  size (500,500);

}
void draw(){
  background(0);
  keroro(0,0,w,height);
  if (w==500 || w==250)
  {
    inc*=-1;
  }
  if (mousePressed){
   w+=inc; 
  }
  
}


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);
}



Lab02 : Clock

float intsec;

void setup(){
 size(300,300);
 textSize(20);
 intsec=second()*1000;
}
void draw() {
  background(255);
  int s = second();  
  int m = minute();  
  int h = hour();    
  int hou=h%12;
  float mrad=map((intsec+millis())%60000,0,60000,0,360); //Map mills between 0 to 360 angle
  noFill();
  strokeWeight(4);
  draw_arc(width/2,height/2,50,0,radians(mrad));//MilliSecond
  draw_arc(width/2,height/2,120,0,m*radians(6));//Minute
  draw_arc(width/2,height/2,200,0,hou*radians(30));//Hour
  //TEXT  INSIDE
  fill(#18AA31);
  text(addzero(s),(width/2)-13,(height/2)+6);
  text(addzero(m),137,195);
  text(addzero(h),137,233);
  //LABEL
  pushMatrix();
  translate(198,233);
  rotate(radians(310));
  text("Hours", 0,0);
  popMatrix();
  pushMatrix();
  translate(175,195);
  rotate(radians(310));
  text("Min.", 0,0);
  popMatrix();
  
  //DIGITAL
  fill(#0F39FF);
  String tex=addzero(h) + ":" + addzero(m) + ":" + addzero(s);
  text(tex,(width/2)-textWidth(tex)/2,30);
}

void draw_arc(int x,int y,int size,float start,float stop){
  stroke(#96BF9D); //bg
  ellipse(x,y,size,size);
  stroke(#18AA31); 
  arc(width/2,height/2,size,size,PI+HALF_PI+start,PI+HALF_PI+stop);
}
String addzero(int timein){
  String textime=str(timein);
  if (timein<10)
    textime= "0" + timein;
  return textime;
}



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

Lab02 : Battery with signs

int dx=1;
int dy=1;
int x=70;
int y=110;
int wide=270,high=75;
void setup(){
  size(350,250);

}
void draw(){
  background(51);
  strokeWeight(4);
  stroke(0);
  draw_battery(x,y,wide,high);
  positive_sign(x+0.092*wide,y+0.2*high,5);
  negative_sign(x+0.8*wide,y+0.2*high,5);
  if (x+wide-20>width || x<0)
   dx*=-1;
  if (y+high-(0.2*high)>height || y-(0.2*high)<0)
   dy*=-1;
  
  x+=dx;
  y+=dy;
}


void draw_battery(int posX,int posY,int wide,int high){
  fill(255); //HEAD
  rect(posX,posY,wide/12,high*3/5);
 
  fill(#E5C81E); //Body Battery
  rect(posX+(wide/12),posY-(0.2*high),wide*5/6,high);
 
  //blue
  fill(#3531C1);
  rect(posX+(wide/6),posY,wide*0.75,0.6*high);
 
  //Line
  line(posX+(wide/6),posY-(0.2*high),posX+(wide/6),posY+(0.78*high));
 
  //Text
  fill(255);
  textSize(15);
  text("Panasonic",posX+0.22*wide,posY+0.4*high);
}

void positive_sign(float x,float y,int sizebox){
  noStroke();
  fill(255,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(255,0,0);
  rect(x+2*sizebox,y+sizebox,sizebox,sizebox);
  rect(x+sizebox,y+sizebox,sizebox,sizebox);
  rect(x,y+sizebox,sizebox,sizebox);
}


Lab02 : Positive Moving

int x=0;
void setup(){
size(350,250);

background(255);

}

void draw(){
  background(255);
  positive_sign(x,50,50);
  x=(x+2)%width;
}


void positive_sign(int x,int y,int sizebox){
  noStroke();
  fill(255,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);
 
}

Random sin waves

int x=0,y=50;

void setup(){
size(800,500);
background(255);
frameRate(10);
smooth();
}

void draw(){
background(0);
draw_snow();

}

void draw_snow()
{
 int i,size=4;
  for (i=0;i<width;i+=size){
    y=y+int(random(-10,10));
    size=int(random(2,5));
    ellipse(x+i,y,size,size);
  }
  fill(random(255),random(100,255),0);
   x=int(random(x-size/4,x+size/4)); //wiggle
   y=(y+10)%height;
}

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

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