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

Lab 3 : Calculate grade from score

void setup(){
  size(300,200);
  background(255);
}

void draw(){
  draw_score(90,100);
}

void draw_score(int x,int y){
  int score=85;

  fill(0);
  textSize(20);
  text("Your score = "+score,50,50);

    if(score>=80 && score<=100){
      text("Grade A",x,y);
    }else if(score>=70 && score<=79){
      text("Grade B",x,y);
    }else if(score>=60 && score<=69){
      text("Grade C",x,y);
    }else if(score>=50 && score<=59){
      text("Grade D",x,y);
    }else if(score<=49 && score>=0){
      text("Grade F",x,y);
    }else{
      text("Error",x,y);
    }
}

Before Lab 3 : Balloon (follow mouse)

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

void draw(){
  background(255);
  int x=mouseX;
  int y=mouseY;

    if(y<50){
    y=50;
    fill(#9B00FC);
    }else if(y>200){
      fill(#00FCB3);
    }else{
      fill(#FC004C);
    }
   
  draw_balloon(x,y);
  draw_balloon(x-100,y-100);

}

void draw_balloon(int x,int y){

  strokeWeight(5);
  ellipse(x,y,100,100);
  line(x,y+50,x,y+150);
}

Lab 2 : Syntax Error

1. Missing a semicolon  เป็นการลืมใส่สัญลักษณ์ semicolon (;) หลังประโยคคำสั่ง
     วิธีแก้ : ใส่ semicolon (;) ในบรรทัดที่ไม่มี

2. The variable "..." does not exist  เป็นการที่เราใส่ชื่อตัวแปรไม่ตรงตามที่เราได้กำหนดไว้
     วิธีแก้ : แก้ชื่อตัวแปรให้ตรงตามที่เรากำหนดไว้

3. String literal is not properly closed by a double-quote  เป็นการที่เวลาพิมพ์ text แล้วใส่เครื่องหมายคำพูด ("...") ไม่ครบ
     วิธีแก้ : ใส่เครื่องหมายคำพูด ("...") ให้ครบ

4. The function "..." does not exist  เป็นการที่เราใส่ชื่อฟังก์ชันไม่ตรงตามชื่อฟังก์ชันของ Processing
     วิธีแก้ : แก้ชื่อฟังก์ชันให้ตรงตามโปรแกรม Processing

Lab 2 : Book (use function + move)

float posX=10;
float posY=20;

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

void draw(){
background(255);

fill(0);                                          //hair
quad(280+posX, 70+posY, 300+posX, 80+posY,280+posX, 100+posY, 280+posX, 90+posY);

fill(0);
ellipse(280+posX, 100+posY, 25, 25);

fill(0);
ellipse(270+posX, 125+posY, 35, 35);

fill(0);
ellipse(260+posX, 150+posY, 40, 40);

fill(0);
ellipse(250+posX, 180+posY, 50, 50);

stroke(0);                                     //face
fill(#FFEDB9);
ellipse(250+posX, 300+posY, 200, 250);

noFill();                                            //mouth
stroke(0);
curve(320+posX,250+posY,220+posX,350+posY,280+posX,350+posY,180+posX,250+posY);

noFill();                                            //eye l
stroke(0);
curve(100+posX,270+posY,190+posX,275+posY,230+posX,290+posY,200+posX,320+posY);

noFill();                                            //eye r
stroke(0);
curve(300+posX,320+posY,270+posX,290+posY,310+posX,275+posY,400+posX,270+posY);

stroke(0);                                           //nose
fill(0);
ellipse(250+posX,320+posY,3,3);

stroke(#FCA88A);                                     //cheek l
fill(#FCA88A);
ellipse(185+posX, 335+posY, 30, 30);

stroke(#FCA88A);                                     //cheek r
fill(#FCA88A);
ellipse(315+posX, 335+posY, 30, 30);

stroke(0);                                          //hand l
fill(#FFEDB9);
ellipse(180+posX, 410+posY, 60, 60);

stroke(0);                                          //hand r
fill(#FFEDB9);
ellipse(320+posX, 410+posY, 60, 60);

textSize(60);                                       //name book
fill(#1104B4);
text("REBORN!",130+posX,60+posY);

posX = (posX+5)%width;
posY = (posY+5)%width;
}

Lab 2 : Song (use function + move)

int posX=50;
int posW=500;
int posY=0;

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

void draw(){
  draw_song(50,10);
    posX = (posX+20)%width;
    posW = (-posW+250)%width;
    posY = (posY+50)%height;

}

void draw_song(int x,int y){
background(#FCECB5);

fill(0);                               //in door
stroke(0);
rect(150+x,300+posY+y,200,250);

fill(#D36A06);                        //l door
stroke(#D36A06);
rect(135+x,300+posY+y,15,250);

fill(#D36A06);                        //r door
stroke(#D36A06);
rect(350+x,300+posY+y,15,250);

fill(#D36A06);                       //on door
stroke(#D36A06);
rect(135+x,285+posY+y,230,15);

fill(#FF0B03);                       //open
stroke(#FF0B03);
ellipse(180+x,450+posY+y,20,20);

/////word on door WELCOME////

fill(#E9FF03);
textSize(20);
text("W",180+x,360+posY+y);

fill(#03F9FF);
textSize(20);
text("E",200+x,360+posY+y);

fill(#05FF03);
textSize(20);
text("L",220+x,360+posY+y);

fill(#FF9F03);
textSize(20);
text("C",240+x,360+posY+y);

fill(#AC6BF7);
textSize(20);
text("O",260+x,360+posY+y);

fill(#6BF7CA);
textSize(20);
text("M",280+x,360+posY+y);

fill(#FF0000);
textSize(20);
text("E",300+x,360+posY+y);

/////name of song/////

fill(#0D08A5);
textSize(80);
text("Pra",posX+x,140+y);

fill(#08A50E);
textSize(80);
text("Tu",150+posX+x,140+y);

fill(#BC0606);
textSize(80);
text("Jai",300+posX+x,140+y);

/////name of singer/////

fill(#AC39F5);
textSize(40);
text("Sao Sao Sao",posW+x,210+y);

}

Lab 2 : Game (use function + move)

int posX=10;
int xx=-40;
int yy=170;

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

void draw(){
  draw_brown(150,150);
    posX = (posX+5)%width;
}

void draw_brown(int x,int y){
background(#58D1F4);

fill(#6A3205);                              //ear l
stroke(#6A3205);
ellipse(posX-150,330,120,120);

fill(#6A3205);                              //ear r
stroke(#6A3205);
ellipse(posX+50,330,120,120);

fill(#4C2404);                              //in ear l
stroke(#4C2404);
ellipse(posX-150,330,75,75);

fill(#4C2404);                              //in ear r
stroke(#4C2404);
ellipse(posX+50,330,75,75);

fill(#6A3205);                              //head
stroke(#6A3205);
ellipse(posX-50,470,340,320);

fill(#EFF804);                              //petal1
stroke(#EFF804);
ellipse((posX-85)+x,165+y,50,50);

fill(#EFF804);                              //petal2
stroke(#EFF804);
ellipse((posX-115)+x,190+y,50,50);

fill(#EFF804);                              //petal3
stroke(#EFF804);
ellipse((posX-55)+x,190+y,50,50);

fill(#EFF804);                              //petal4
stroke(#EFF804);
ellipse((posX-65)+x,225+y,50,50);

fill(#EFF804);                              //petal5
stroke(#EFF804);
ellipse((posX-105)+x,225+y,50,50);

fill(#522F03);                              //pollen
stroke(#522F03);
ellipse((posX-85)+x,200+y,30,30);


fill(0);                                        //eye l
stroke(0);
ellipse((posX-70),440,25,25);

fill(0);                                        //eye r
stroke(0);
ellipse((posX-20),440,25,25);

fill(#FDCF86);                            //mouth
stroke(#FDCF86);
ellipse((posX-45),500,80,95);

fill(0);                                        //nose
stroke(0);
ellipse((posX-45),485,15,15);

noFill();                                     //continue nose
stroke(0);
strokeWeight(2);
line((posX-45),485,(posX-45),500);

fill(#FEAF04);                            //sun
stroke(#FEAF04);
ellipse(posX,30,250,250);

}


Lab 2 : My Clock

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

}

void draw(){
  draw_clock(100,100);
}

void draw_clock(int posX,int posY){
background(0);

  int s=second();
  int m=minute();
  int h=hour();
  int d=day();
  int mo=month();
  int y=year();

fill(255);
textSize(50);
text(nf(h,2)+" : "+nf(m,2)+" : "+nf(s,2),posX,posY+80);

fill(#FF0000);
textSize(30);
text(nf(d,2)+" / "+nf(mo,2)+" / "+y,posX+30,posY);

}

Lab 2 : Battery (use function + move)

int posX=100;
int posY=100;
int y=25;

void setup(){
 size(300,300);
 frameRate(50);
}

void draw(){
  background(#FF0000);
  draw_battery(posX,posY);
    posX = (posX+1)%width;
}

void draw_battery(int posX,int posY){

rect(posX+10,posY-25,40,15);

noStroke();
rect(posX-10,posY-10,80,140);

fill(0);
rect(posX-5,posY-5,70,130);
rect(posX-20,posY-30,20,5);
rect(posX+60,posY-30,20,5);
rect(posX+68,posY-37,5,20);

fill(255);
rect(posX,posY,60,20);
rect(posX,posY+y,60,20);
rect(posX,posY+2*y,60,20);
rect(posX,posY+3*y,60,20);
rect(posX,posY+4*y,60,20);

textSize(20);
text("100%",posX,posY+160);
}

Lab 2 : Positive (use function + move)

int posX=200;
int posY=50;

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

void draw(){
  draw_positive(posX,posY);
  posY = (posY+5)%height;
}

void draw_positive(int posX,int posY){
  background(255);
  noStroke();
  fill(#FF0000);
  rect(posX,posY,100,100);
  rect(posX-100,posY+100,300,100);
  rect(posX,posY+200,100,100);
}
 

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

Lab 2 : Calculate body mass index (BMI) (use function)



void setup() {
 size(400,100);
 background(255);

  float w=40;
  float h=160;

  textSize(15);
  fill(0);
  text("Value of a BMI = "+BMI(w,h)+" kg/cm*cm",40,40);

}

///// calculate BMI/////

float BMI(float w,float h){

   float BMI;
   float Divisor;
   Divisor = h/100;
   BMI = w/(Divisor*Divisor);
   return BMI;

}

Lab 2 : Calculate circumference and area of a circle (use function)

void setup() {
 size(400,200);
 background(255);

   float r=10;

  textSize(15);
  fill(0);
  text("Value of a Area = "+area(r)+" cm*cm",40,40);
  text("Value of a Circumference = "+circum(r)+" cm.",40,80);

}

///// calculate area of circle/////

 float area(float r){

   float area;
   area = PI*r*r;
   return area;

}

/////calculate circum of circle/////

  float circum(float r){

   float circum;
   circum = TWO_PI*r;
   return circum;

}

Lab 2 : Calculate circumference and area of a rectangle (use function)


void setup() {
 size(400,200);
 background(255);

  int w=70;
  int h=150;
 
  textSize(15);
  fill(0);
  text("Value of a Area = "+area(w,h)+" cm*cm",40,40);
  text("Value of a Circumference = "+circum(w,h)+" cm.",40,80);
}

///// calculate area of rectangle /////

int area(int w,int h){

   int area;
   area = w*h;
   return area;

}

///// calculate circum of rectangle /////

int circum(int w,int h){

   int circum;
   circum = (2*w)+(2*h);
   return circum;

}

Lab 1 : Calculate circumference and area of a rectangle



void setup(){
size(400,200);

float w;
float h;
float Area;
float Circumference;

//////////calculate area of a rect//////////

w=100;
h=150;
Area=w*h;

//////////calculate circumference of a rect/////////

Circumference=(2*w)+(2*h);

textSize(20);
fill(0);
text("Value of Area = "+Area+" cm*cm",20,120);
text("Value of Circumference = "+Circumference+" cm.",20,160);
text("Height = "+h+" cm.",20,40);
text("Wide = "+w+" cm.",20,80);

}

Lab 1 : Calculate circumference and area of a circle



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

int r;
float Area;
float Circumference;

//////////calculate area of a circle//////////

r=10;
Area=PI*r*r;

//////////calculate circumference of a circle//////////

Circumference=TWO_PI*r;

textSize(20);
fill(0);
text("Radius = "+r+" cm.",20,50);
text("Value of Circumference = "+Circumference+" cm.",20,90);
text("Value of Area = "+Area+" cm*cm",20,130);

}

Lab 1 : Game from Lab 0 (resize -)



void setup(){
size(500,500);
background(#58D1F4);
int x=0;
int y=20;
int w=-20;
int h=-20;

fill(#6A3205);                                                          //ear l
stroke(#6A3205);
ellipse(150,330+y,120+w,120+h);

fill(#6A3205);                                                         //ear r
stroke(#6A3205);
ellipse(350,330+y,120+w,120+h);

fill(#4C2404);                                                         //in ear l
stroke(#4C2404);
ellipse(150,330+y,75+w,75+h);

fill(#4C2404);                                                        //in ear r
stroke(#4C2404);
ellipse(350,330+y,75+w,75+h);

fill(#6A3205);                                                       //head
stroke(#6A3205);
ellipse(250,470+y,340+w,320+h);

fill(#EFF804);                                                      //petal1
stroke(#EFF804);
ellipse(175,305+y,50,50);

fill(#EFF804);                                                     //petal2
stroke(#EFF804);
ellipse(145,330+y,50,50);

fill(#EFF804);                                                    //petal3
stroke(#EFF804);
ellipse(205,330+y,50,50);

fill(#EFF804);                                                   //petal4
stroke(#EFF804);
ellipse(195,365+y,50,50);

fill(#EFF804);                                                   //petal5
stroke(#EFF804);
ellipse(155,365+y,50,50);

fill(#522F03);                                                  //pollen
stroke(#522F03);
ellipse(175,340+y,30,30);


fill(0);                                                              //eye l
stroke(0);
ellipse(230,440+y,25,25);

fill(0);                                                             //eye r
stroke(0);
ellipse(280,440+y,25,25);

fill(#FDCF86);                                                 //mouth
stroke(#FDCF86);
ellipse(255,500+y,80+w,95+h);

fill(0);                                                               //nose
stroke(0);
ellipse(255,485+y,15+w,15+h);

noFill();                                                          //continue nose
stroke(0);
strokeWeight(2);
line(255,485+y,255,500+y);

fill(#FEAF04);                                              //sun
stroke(#FEAF04);
ellipse(460,30,250+w,250+h);

}

Lab 1 : Book From Lab 0 (move)



void setup() {
size(500, 500);
background(#FF0303);

int x=50;
int y=50;

fill(0);                                                                                                             //hair
quad(280+x, 70+y, 300+x, 80+y,280+x, 100+y, 280+x, 90+y);

fill(0);
ellipse(280+x, 100+y, 25, 25);

fill(0);
ellipse(270+x, 125+y, 35, 35);

fill(0);
ellipse(260+x, 150+y, 40, 40);

fill(0);
ellipse(250+x, 180+y, 50, 50);

stroke(0);                                                                                                         //face
fill(#FFEDB9);
ellipse(250+x, 300+y, 200, 250);

noFill();                                                                                                         //mouth
stroke(0);
curve(320+x,250+y,220+x,350+y,280+x,350+y,180+x,250+y);

noFill();                                                                                                         //eye l
stroke(0);
curve(100+x,270+y,190+x,275+y,230+x,290+y,200+x,320+y);

noFill();                                                                                                          //eye r
stroke(0);
curve(300+x,320+y,270+x,290+y,310+x,275+y,400+x,270+y);

stroke(0);                                                                                                       //nose
fill(0);
ellipse(250+x,320+y,3,3);

stroke(#FCA88A);                                                                                        //cheek l
fill(#FCA88A);
ellipse(185+x, 335+y, 30, 30);

stroke(#FCA88A);                                                                                       //cheek r
fill(#FCA88A);
ellipse(315+x, 335+y, 30, 30);

stroke(0);                                                                                                      //hand l
fill(#FFEDB9);
ellipse(180+x, 410+y, 60, 60);

stroke(0);                                                                                                      //hand r
fill(#FFEDB9);
ellipse(320+x, 410+y, 60, 60);

textSize(60);                                                                                                //name book
fill(#1104B4);
text("REBORN!",130+x,60+y);

}

Lab 1 : Song from Lab 0 (reize +)



void setup(){
size(500,500);
background(#FCECB5);

int w=30;
int h=30;
int b=15;

fill(#D36A06);                                                              //l door
stroke(#D36A06);
rect(135,300,15+w,250+h);

fill(#D36A06);                                                              //r door
stroke(#D36A06);
rect(350,300,15+w,250+h);

fill(#D36A06);                                                               //on door
stroke(#D36A06);
rect(135,285,230+w,15+h);

fill(0);                                                                             //in door
stroke(0);
rect(150,300,200+w,250+h);

fill(#FF0B03);                                                                 //open
stroke(#FF0B03);
ellipse(180,450,20+w,20+h);

/////word on door WELCOME////

fill(#E9FF03);
textSize(20+b);
text("W",180,360);

fill(#03F9FF);
textSize(20+b);
text("E",200,360);

fill(#05FF03);
textSize(20+b);
text("L",220,360);

fill(#FF9F03);
textSize(20+b);
text("C",240,360);

fill(#AC6BF7);
textSize(20+b);
text("O",260,360);

fill(#6BF7CA);
textSize(20+b);
text("M",280,360);

fill(#FF0000);
textSize(20+b);
text("E",300,360);

/////name of song/////

fill(#0D08A5);
textSize(80+b);
text("Pra",50,140);

fill(#08A50E);
textSize(80+b);
text("Tu",200,140);

fill(#BC0606);
textSize(80+b);
text("Jai",350,140);

/////name of singer/////

fill(#AC39F5);
textSize(40+b);
text("Sao Sao Sao",120,210);

}

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

Lab 1 : Calculate body mass index (BMI)



void setup(){
size(400,200);

float w;
float h;
float d;
float BMI;

w=70;
h=150;
d=h/100;

BMI=w/(d*d);

textSize(25);
fill(0);
text("Height = "+h+" cm.",20,50);
text("Weight = "+w+" kg.",20,90);
text("Value of BMI = "+BMI+" cm.",20,130);

}

Lab 1 : Positive Sign


void setup(){
 size(500,500);
background(255);

  int posX=200;
  int posY=50;


  noStroke();
  fill(#FF0000);
  rect(posX,posY,100,100);
  rect(posX-100,posY+100,300,100);
  rect(posX,posY+200,100,100);

  stroke(0);
  fill(0);
  textSize(50);
  text("Positive Sign",posX-100,posY+360);

}

Lab 1 : Battery



void setup(){
size(300,300);
background(0);

int posX=120;
int posY=70;
int y=25;

rect(posX+10,posY-25,40,15);

noStroke();
rect(posX-10,posY-10,80,140);

fill(0);
rect(posX-5,posY-5,70,130);


fill(255);
rect(posX,posY,60,20);
rect(posX,posY+y,60,20);
rect(posX,posY+2*y,60,20);
rect(posX,posY+3*y,60,20);
rect(posX,posY+4*y,60,20);

textSize(20);
text("100%",posX,posY+160);

}

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

Lab 0 : My Favorite 3 (Book)


void setup() {
size(500, 500);
background(255);

fill(0);                                          //hair
quad(280, 70, 300, 80,280, 100, 280, 90);

fill(0);
ellipse(280, 100, 25, 25);

fill(0);
ellipse(270, 125, 35, 35);

fill(0);
ellipse(260, 150, 40, 40);

fill(0);
ellipse(250, 180, 50, 50);

stroke(0);                                     //face
fill(#FFEDB9);
ellipse(250, 300, 200, 250);

noFill();                                            //mouth
stroke(0);
curve(320,250,220,350,280,350,180,250);

noFill();                                            //eye l
stroke(0);
curve(100,270,190,275,230,290,200,320);

noFill();                                            //eye r
stroke(0);
curve(300,320,270,290,310,275,400,270);

stroke(0);                                           //nose
fill(0);
ellipse(250,320,3,3);

stroke(#FCA88A);                                     //cheek l
fill(#FCA88A);
ellipse(185, 335, 30, 30);

stroke(#FCA88A);                                     //cheek r
fill(#FCA88A);
ellipse(315, 335, 30, 30);

stroke(0);                                          //hand l
fill(#FFEDB9);
ellipse(180, 410, 60, 60);

stroke(0);                                          //hand r
fill(#FFEDB9);
ellipse(320, 410, 60, 60);

textSize(60);                                       //name book
fill(#1104B4);
text("REBORN!",130,60);

}

Lab 0 : My Favorite 2 (Song)



void setup(){
size(500,500);
background(#FCECB5);

fill(0);                               //in door
stroke(0);
rect(150,300,200,250);

fill(#D36A06);                        //l door
stroke(#D36A06);
rect(135,300,15,250);

fill(#D36A06);                        //r door
stroke(#D36A06);
rect(350,300,15,250);

fill(#D36A06);                       //on door
stroke(#D36A06);
rect(135,285,230,15);

fill(#FF0B03);                       //open
stroke(#FF0B03);
ellipse(180,450,20,20);

/////word on door WELCOME////

fill(#E9FF03);
textSize(20);
text("W",180,360);

fill(#03F9FF);
textSize(20);
text("E",200,360);

fill(#05FF03);
textSize(20);
text("L",220,360);

fill(#FF9F03);
textSize(20);
text("C",240,360);

fill(#AC6BF7);
textSize(20);
text("O",260,360);

fill(#6BF7CA);
textSize(20);
text("M",280,360);

fill(#FF0000);
textSize(20);
text("E",300,360);

/////name of song/////

fill(#0D08A5);
textSize(80);
text("Pra",50,140);

fill(#08A50E);
textSize(80);
text("Tu",200,140);

fill(#BC0606);
textSize(80);
text("Jai",350,140);

/////name of singer/////

fill(#AC39F5);
textSize(40);
text("Sao Sao Sao",120,210);

}

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

Lab 0 : My Favorite 1 (Game)



void setup(){
size(500,500);
background(#58D1F4);
int x=-40;
int y=170;

fill(#6A3205);                              //ear l
stroke(#6A3205);
ellipse(150,330,120,120);

fill(#6A3205);                              //ear r
stroke(#6A3205);
ellipse(350,330,120,120);

fill(#4C2404);                              //in ear l
stroke(#4C2404);
ellipse(150,330,75,75);

fill(#4C2404);                              //in ear r
stroke(#4C2404);
ellipse(350,330,75,75);

fill(#6A3205);                              //head
stroke(#6A3205);
ellipse(250,470,340,320);

fill(#EFF804);                              //petal1
stroke(#EFF804);
ellipse(215+x,165+y,50,50);

fill(#EFF804);                              //petal2
stroke(#EFF804);
ellipse(185+x,190+y,50,50);

fill(#EFF804);                              //petal3
stroke(#EFF804);
ellipse(245+x,190+y,50,50);

fill(#EFF804);                              //petal4
stroke(#EFF804);
ellipse(235+x,225+y,50,50);

fill(#EFF804);                              //petal5
stroke(#EFF804);
ellipse(195+x,225+y,50,50);

fill(#522F03);                              //pollen
stroke(#522F03);
ellipse(215+x,200+y,30,30);


fill(0);                                        //eye l
stroke(0);
ellipse(230,440,25,25);

fill(0);                                        //eye r
stroke(0);
ellipse(280,440,25,25);

fill(#FDCF86);                            //mouth
stroke(#FDCF86);
ellipse(255,500,80,95);

fill(0);                                        //nose
stroke(0);
ellipse(255,485,15,15);

noFill();                                     //continue nose
stroke(0);
strokeWeight(2);
line(255,485,255,500);

fill(#FEAF04);                            //sun
stroke(#FEAF04);
ellipse(460,30,250,250);

}