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

Lab 4x : Leap Year

def setup():
   year = 2012
   if(year%4==0 or year%4==0 and year%100!=0 or year%4==0 and year%100==0 and year%400==0):
      print("Year's Leap Year")
   if(year%4!=0 or year%4==0 and year%100==0 or year%4==0 and year%100==0 and year%400!=0):
      print("Year isn't Leap Year")
   
   
setup()

Lab 4x : Calculate sum of integers from 1 to N

def setup():
   print("Sum = ",number(50))
 
def number(n):
   x = 1
   sum = 0
   while(x <= n):
      sum = sum+x
      x +=1
   return sum
 
 
setup()

Lab 4x : Calculate sum of Prime number

def setup():
   print("Sum = ",prime(10))
 

def prime(num):
  x = 2
  sum = 0
  while(x<=num):
    if(prime_number(x)):
         sum +=x
    x+=1
  return sum


def prime_number(n):
   x = 2
   if(n==1):
         return False
   while(x<n):
      if(n%x==0):
         return False
      x+=1
   return True


setup()

Lab 4x : Calculate Multiplication

def setup():
  num = 2
  x = 1
  loop = 13
  while(x<loop):
    sum = num*x
    print(num," * ",x," = ",sum)
    x = x+1

   
setup()

Lab 4x : Calculate grade from score

def setup():
   score = 70
   if(score>=80 and score<=100):
      print("Grade A")
   elif(score>=70 and score<=79):
      print("Grade B")
   elif(score>=60 and score<=69):
      print("Grade C")
   elif(score>=50 and score<=59):
      print("Grade D")
   elif(score>=0 and score<=49):
      print("Grade F")
   else:
      print("Error")


setup()

Lab 4x : Calculate of BMI

def setup():
   w = 40
   h = 160
   print("Weight = ",w)
   print("Hight  = ",h)
   print("Value of a BMI = ",bmi(w,h),"kg/cm*cm")
 
def bmi(w,h):
   divisor = h/100
   bmi = w/(divisor*divisor)
   return bmi

setup()

Lab 4x : Calculate circum and area of circle

def setup():
   r = 10
   print("Radian = ",r)
   print("Value of Area = ",area(r))
   print("Value of Circumference = ",circum(r))
 
def area(r):
   area = (22/7)*r*r
   return area

def circum(r):
   circum = 2*(22/7)*r
   return circum

setup()

Lab 4x : Calculate circum and area of rectangle

def setup():
   w = 3
   h = 7
   print("Height = ",h)
   print("Weight = ",w)
   print("Value of Area = ",area(w,h))
   print("Value of Circumference = ",circum(w,h))
 
def area(w, h):
   area = w*h
   return area

def circum(w,h):
   circum = (2*w)+(2*h)
   return circum

setup()

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

Lab 4 : Balloons (while loop)

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

void draw(){
  background(255);

  if(mouseY<150){
      fill(#9B00FC);
    }else if(mouseY>300){
      fill(#00FCB3);
    }else{
      fill(#FC004C);
    }
  draw_balloon(mouseX,mouseY,100,100,1);
}

void draw_balloon(int x,int y,int w,int h,int n){

  int space=0;

  while(n<=4){
///////////////////draw balloon////////////////////
    strokeWeight(5);
    ellipse(x+space,y+space,w,h);
    line(x+space,(y+space)+(h/2),x+space,(y+space)+(h+50));
    n++;
    space = space+w;
  }
}

Lab 4 : Flock birds

int w=150;
int c;

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

void draw(){
  background(#69C2F7);
  w=mouseY;
  if(frameCount%40>20){
    w+=40;
  }else{
    w-=50;
  }
  if(mouseY<200){
    c=#FF0000;
  }else if(mouseY<350){
    c=255;
  }else{
    c=#10BF08;
  }

  draw_bird(mouseX,mouseY);
}

void draw_bird(int x,int y){
  int n=0;
  int sx=0;       //space
  int sy=0;

  while(n<5){
//////////////draw bird//////////////
    strokeWeight(5);
    fill(c);
  ellipse(x+sx,y+sy,150,150);             //head

    fill(255);
  ellipse((x-25)+sx,(y-10)+sy,30,30);               //eye l
  ellipse((x+25)+sx,(y-10)+sy,30,30);               //eye r

    fill(#FAC208);
  triangle((x-20)+sx,(y+30)+sy,x+sx,(y+15)+sy,(x+20)+sx,(y+30)+sy);     //mouse on
  triangle((x-15)+sx,(y+30)+sy,x+sx,(y+40)+sy,(x+15)+sx,(y+30)+sy);     //mouse under

    fill(0);
  ellipse((x-25)+sx,(y-10)+sy,10,10);                 //in eye l
  ellipse((x+25)+sx,(y-10)+sy,10,10);                //in eye r

  rect((x-45)+sx,(y-30)+sy,40,10);                    //eyebrow l
  rect((x+5)+sx,(y-30)+sy,40,10);                    //eyebrow r

  line((x-75)+sx,y+sy,(x-150)+sx,w+sy);                  //wing l
  line((x+75)+sx,y+sy,(x+150)+sx,w+sy);               //wing r

  n++;
  sx = sx-50;
  sy = sy+170;
  }
}

Lab 4 : Calculate Multiplication

void setup(){
  int num=2;                    //multiplicad
  int x=1;                      //multiplier
  int loop=13;
  int sum;

  while(x<loop){
    sum = num*x;
    println(num+" * "+x+" = "+sum);
    x++;
  }
}

Lab 4 : Calculate sum of integers from 1 to N

void setup() {
  int n=50;
  println("Sum = "+number(n));

}
  int number(int n) {
  int x = 1;
  int sum = 0;

  while (x <= n) {
    sum = sum+x;
  x++;
  }
return sum;
}

Lab 4 : Calculate sum of Prime number

void setup(){
  int n=10;
  println("Sum = "+prime(n));
}

int prime(int n){
  int x=1;
  int sum=0;

  while(x<=n){
    if(prime_number(x)){
    sum = sum+x;
    }
    x++;
  }
  return sum;
}

boolean prime_number(int n){
  boolean prime=true;

  int x=2;
  while(x<n){
    if(n%x==0){
      prime=false;
    }
    x++;
  }
    if(n==1){
      prime=false;
    }
  return prime;
}

Lab 4 : Loan payment

void setup(){
  loan_payment(5000,1,12);
}

void loan_payment(float amount,float year,float rate){
  int no = 1;
  float ratee = rate/100;
  float month = year*12;
  float ratepermonth = ratee/month;
  float prinper = amount*(ratepermonth/(1-pow(1+ratepermonth,-month)));
  float principal = prinper;
  float total = 0;
  println("NO.  Beginning balance   Interest   Total interest to date   Principal   Unpaid balance");

  while(no<=month){
         
    print(nf(no,2));                                     //NO.
    print("       "+nf(amount,4,2));                     //Beginning balance
    print("          "+nf(ratepermonth*amount,2,2));     //Ineterest
 
    total = total+(ratepermonth*amount);
    principal = prinper-(ratepermonth*amount);
    amount = amount-principal;
 
    if(amount<0){
      amount = 0;
    }
 
    print("            "+nf(total,3,2));                 //Total interest
    print("             "+nf(principal,3,2));            //Principal
    print("       "+nf(amount,4,2));
    println();
 
    no++;
  }
}

Lab 4 : Game


int c=#6A3205;

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

void draw(){
  draw_brown(mouseX,mouseY);
}

void draw_brown(int x,int y){
  int n=1;
  int sx=0;                          //space
  int sy=0;
  
  background(#58D1F4);
  
  while(n<5){

  fill(c);                              //ear l
  stroke(#4C2404);
    ellipse((x-50)+sx,(y+30)+sy,120,120);

  fill(c);                              //ear r
  stroke(#4C2404);
    ellipse((x+150)+sx,(y+30)+sy,120,120);

  fill(#4C2404);                              //in ear l
  stroke(#4C2404);
    ellipse((x-50)+sx,(y+30)+sy,75,75);

  fill(#4C2404);                              //in ear r
  stroke(#4C2404);
    ellipse((x+150)+sx,(y+30)+sy,75,75);

  fill(c);                              //head
  stroke(#4C2404);
    ellipse((x+50)+sx,(y+170)+sy,340,320);

  fill(#EFF804);                              //petal1
  stroke(#EFF804);
    ellipse((x-25)+sx,(y+35)+sy,50,50);

  fill(#EFF804);                              //petal2
  stroke(#EFF804);
    ellipse((x-55)+sx,(y+60)+sy,50,50);

  fill(#EFF804);                              //petal3
  stroke(#EFF804);
    ellipse((x+5)+sx,(y+60)+sy,50,50);

  fill(#EFF804);                              //petal4
  stroke(#EFF804);
    ellipse((x-5)+sx,(y+95)+sy,50,50);

  fill(#EFF804);                              //petal5
  stroke(#EFF804);
    ellipse((x-45)+sx,(y+95)+sy,50,50);

  fill(#522F03);                              //pollen
  stroke(#522F03);
    ellipse((x-25)+sx,(y+70)+sy,30,30);

  fill(0);                                        //eye l
  stroke(0);
    ellipse((x+30)+sx,(y+140)+sy,25,25);

  fill(0);                                        //eye r
  stroke(0);
    ellipse((x+80)+sx,(y+140)+sy,25,25);

  fill(#FDCF86);                            //mouth
  stroke(#FDCF86);
    ellipse((x+55)+sx,(y+200)+sy,80,95);

  fill(0);                                        //nose
  stroke(0);
    ellipse((x+55)+sx,(y+185)+sy,15,15);

  noFill();                                     //continue nose
  stroke(0);
  strokeWeight(2);
    line((x+55)+sx,(y+185)+sy,(x+55)+sx,(y+220)+sy);

  curve((x+130)+sx,(y+110)+sy,(x+30)+sx,(y+210)+sy,(x+80)+sx,(y+210)+sy,(x-20)+sx,(y+110)+sy);

  fill(#FEAF04);                            //sun
  stroke(#FEAF04);
    ellipse((x+260)+sx,(y-270)+sy,250,250);
  
  n++;
  sx = sx+200;
  sy = sy+100;

  }
}

void keyPressed(){
  c=#7808BF;
}

Lab 4 : Book

int c;

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

void draw(){
background(255);

  draw_book(mouseX,mouseY);
}

void draw_book(int posX,int posY){
  int n=1;
  int sx=0;
  int sy=0;

  while(n<4){
fill(0);                                          //hair
quad((posX+30)+sx,(posY-180)+sy,(posX+50)+sx,(posY-170)+sy,(posX+30)+sx,(posY-150)+sy,(posX+30)+sx,(posY-160)+sy);

fill(0);
ellipse((posX+30)+sx,(posY-150)+sy,25,25);

fill(0);
ellipse((posX+20)+sx,(posY-125)+sy,35,35);

fill(0);
ellipse((posX+10)+sx,(posY-100)+sy,40,40);

fill(0);
ellipse(posX+sx,(posY-70)+sy,50,50);

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

noFill();                                            //mouth
stroke(0);
curve((posX+70)+sx,posY+sy,(posX-30)+sx,(posY+100)+sy,(posX+30)+sx,(posY+100)+sy,(posX-70)+sx,posY+sy);

noFill();                                            //eye l
stroke(0);
curve((posX-150)+sx,(posY+20)+sy,(posX-60)+sx,(posY+25)+sy,(posX-20)+sx,(posY+40)+sy,(posX-50)+sx,(posY+70)+sy);

noFill();                                            //eye r
stroke(0);
curve((posX+50)+sx,(posY+70)+sy,(posX+20)+sx,(posY+40)+sy,(posX+60)+sx,(posY+25)+sy,(posX+150)+sx,(posY+20)+sy);

stroke(0);                                           //nose
fill(0);
ellipse(posX+sx,(posY+70)+sy,3,3);

stroke(#FCA88A);                                     //cheek l
fill(#FCA88A);
ellipse((posX-65)+sx,(posY+85)+sy,30,30);

stroke(#FCA88A);                                     //cheek r
fill(#FCA88A);
ellipse((posX+65)+sx,(posY+85)+sy,30,30);

stroke(0);                                          //hand l
fill(#FFEDB9);
ellipse((posX-70)+sx,(posY+160)+sy,60,60);

stroke(0);                                          //hand r
fill(#FFEDB9);
ellipse((posX+70)+sx,(posY+160)+sy,60,60);

textSize(60);                                       //name book
fill(c);
text("REBORN!",(posX-120)+sx,(posY-190)+sy);

  n++;
  sx = sx+250;
  sy = sy+20;
  }
}

void mousePressed(){
  c=#FF0004;
}

Lab 4 : Song

int x=50;

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

void draw(){
  background(#FCECB5);
  draw_song(x,10);
}

void draw_song(int x,int y){
  int n=1;
  int sx=0;

  while(n<=3){

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  n++;
  sx = sx+400;
  }
}

void keyPressed(){
  x=x+100;
}

void mousePressed(){
  x=x-100;
}

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

Lab 3 : Delivery Charge

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

  cal_charge(2,2,4,22);

  fill(#DE1FFC);
  textSize(80);
    text("Delivery Charge", 40, 200);
}

/////pack1=letter , pack2=box , service1=next day priority , service2=next day standard
/////service3=2-day price=num of packservice

void cal_charge(int pack,int service,int weight,int price) {

  int x=100;
  int y=300;
  float boxprio=15.75+((weight-1)*1.25);
  float boxstard=13.75+((weight-1)*1.00);
  float boxday=7.00+((weight-1)*0.50);

  textSize(35);
  fill(#5A94F0);
  if (pack==1 && service==1 && weight<=8 && price==11){
    text("Package Type : Letter", x, y);
    text("Service type : Next Day Priority", x, y+80);
    text("Weight : "+weight+" oz",x,y+160);
    text("Price : $12.00",x,y+240);
  }
   if (pack==1 && service==2 && weight<=8 && price==12){
    text("Package Type : Letter", x, y);
    text("Service type : Next Day Standard", x, y+80);
    text("Weight : "+weight+" oz",x,y+160);
    text("Price : $10.50",x,y+240);
  }
   if (pack==1 && service==3 && price==13){
    text("Package Type : Letter", x, y);
    text("Service type : 2-Day", x, y+80);
    text("Weight : "+weight+" oz",x,y+160);
    text("Price : Not available",x,y+240);
  }
   if (pack==2 && service==1 && price==21){
    text("Package Type : Box", x, y);
    text("Service type : Next Day Priority", x, y+80);
    text("Weight : "+weight+" pound",x,y+160);
    text("Price : $"+boxprio,x,y+240);
  }
   if (pack==2 && service==2 && price==22){
    text("Package Type : Box", x, y);
    text("Service type : Next Day Standard", x, y+80);
    text("Weight : "+weight+" pound",x,y+160);
    text("Price : $"+boxstard,x,y+240);
  }
   if (pack==2 && service==3 && price==23){
    text("Package Type : Box", x, y);
    text("Service type : 2-Day", x, y+80);
    text("Weight : "+weight+" pound",x,y+160);
    text("Price : $"+boxday,x,y+240);
  }
  if(pack!=1 && pack!=2 || service!=1 && service!=2 && service!=3 || price!=11 && price!=12 && price!=13 && price!=21 && price!=22 && price!=23){
    text("Package Type : Not available", x, y);
    text("Service type : Not available", x, y+80);
    text("Weight : Not available",x,y+160);
    text("Price : Not available",x,y+240);
  }
}


Lab 3 : Leap Year

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

  int year=2013;
  cal_year(year);

  fill(#1FFC6A);
  textSize(80);
    text("Leap Year", 60, 150);
  textSize(50);
    text("Year : "+year, 110, 250);
}

void cal_year(int year) {

  int x=100;
  int y=350;

  textSize(40);
  fill(#FF0000);
  if (year%4==0 || year%4==0 && year%100!=0 || year%4==0 && year%100==0 && year%400==0){
    text("Year's Leap Year", x-10, y);
  }
  if(year%4!=0 || year%4==0 && year%100==0 || year%4==0 && year%100==0 && year%400!=0){
    text("Year isn't Leap Year",x-30,y);
  }
}

Lab 3 : Power of 10

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

  int power=21;
  cal_power(power);

  textSize(70);
    text("Power Of 10", 50, 150);
  textSize(50);
    text("Power = "+power, 120, 250);
}

void cal_power(int power) {

  int x=180;
  int y=350;


  textSize(40);
  fill(#FF0000);
  if (power==6){
    text("Million", x, y);
  }else if(power==9){
    text("Billion", x, y);
  }else if(power==12){
    text("Trillion", x, y);
  }else if(power==15){
    text("Quadrillion", x-30, y);
  }else if(power==18){
    text("Quintillion", x-20, y);
  }else if(power==21){
    text("Sextillion", x-10, y);
  }else if(power==30){
    text("Nonillion", x-10, y);
  }else if(power==100){
    text("Googol", x+20, y);
  }else{
    text("No number",x-20,y);
  }
}


Lab 3 : Battery

int posX=100;
int posY=100;
int y=25;
int h=100;
int paint;
int mouse;
int per=100;

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


void draw(){
  background(#9B8B8B);
  draw_battery(posX,posY,60,h);
    if(h>0){
    h=h-1;
    paint=#FF0000;
    per=per-1;
   }
   if(h>40){
     paint=#FFF812;
   }
   if(h>80){
     paint=#24BF02;
   }
    if(h<10){
     draw_charge(190,150);
   }
   if(h==0){
     h=100;
     h=h+1;
     per=101;
     per=per-1;
   }

}

void draw_battery(int posX,int posY,int w,int h){

//strokeWeight();
fill(255);
rect(posX+10,posY+125,40,20);             //head battery
rect(posX-5,posY-5,70,130);           //battery
rect(posX-20,posY+150,20,5);           //positive and negative
rect(posX+60,posY+150,20,5);
rect(posX+68,posY+143,5,20);

textSize(20);
text(per+" %",posX,posY-25);

fill(paint);
rect(posX,posY,60,h);
}

void draw_charge(int x,int y){
  textSize(25);
  fill(#FF0000);
  text("Charge!",x,y);
}

Lab 3 : Game (follow mouse and keyPressed)


int c=#6A3205;

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

void draw(){
  draw_brown(mouseX,mouseY);
}

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

fill(c);                              //ear l
stroke(c);
ellipse(x-50,y+30,120,120);

fill(c);                              //ear r
stroke(c);
ellipse(x+150,y+30,120,120);

fill(#4C2404);                              //in ear l
stroke(#4C2404);
ellipse(x-50,y+30,75,75);

fill(#4C2404);                              //in ear r
stroke(#4C2404);
ellipse(x+150,y+30,75,75);

fill(c);                              //head
stroke(c);
ellipse(x+50,y+170,340,320);

fill(#EFF804);                              //petal1
stroke(#EFF804);
ellipse(x-25,y+35,50,50);

fill(#EFF804);                              //petal2
stroke(#EFF804);
ellipse(x-55,y+60,50,50);

fill(#EFF804);                              //petal3
stroke(#EFF804);
ellipse(x+5,y+60,50,50);

fill(#EFF804);                              //petal4
stroke(#EFF804);
ellipse(x-5,y+95,50,50);

fill(#EFF804);                              //petal5
stroke(#EFF804);
ellipse(x-45,y+95,50,50);

fill(#522F03);                              //pollen
stroke(#522F03);
ellipse(x-25,y+70,30,30);


fill(0);                                        //eye l
stroke(0);
ellipse(x+30,y+140,25,25);

fill(0);                                        //eye r
stroke(0);
ellipse(x+80,y+140,25,25);

fill(#FDCF86);                            //mouth
stroke(#FDCF86);
ellipse(x+55,y+200,80,95);

fill(0);                                        //nose
stroke(0);
ellipse(x+55,y+185,15,15);

noFill();                                     //continue nose
stroke(0);
strokeWeight(2);
line(x+55,y+185,x+55,y+220);

curve(x+130,y+110,x+30,y+210,x+80,y+210,x-20,y+110);

fill(#FEAF04);                            //sun
stroke(#FEAF04);
ellipse(x+260,y-270,250,250);

}

void keyPressed(){
  c=#7808BF;
}

Lab 3 : Song (mousePressed and keyPressed)


int x=50;

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

void draw(){
  draw_song(x,10);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

void keyPressed(){
  x=x+100;
}

void mousePressed(){
  x=x-100;
}

Lab 3 : Book (follow mouse and mousePressed)

int c;

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

void draw(){
background(255);

  draw_book(mouseX,mouseY);
}

void draw_book(int posX,int posY){
fill(0);                                          //hair
quad(posX+30, posY-180, posX+50, posY-170,posX+30, posY-150, posX+30, posY-160);

fill(0);
ellipse(posX+30, posY-150, 25, 25);

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

fill(0);
ellipse(posX+10, posY-100, 40, 40);

fill(0);
ellipse(posX, posY-70, 50, 50);

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

noFill();                                            //mouth
stroke(0);
curve(posX+70,posY,posX-30,posY+100,posX+30,posY+100,posX-70,posY);

noFill();                                            //eye l
stroke(0);
curve(posX-150,posY+20,posX-60,posY+25,posX-20,posY+40,posX-50,posY+70);

noFill();                                            //eye r
stroke(0);
curve(posX+50,posY+70,posX+20,posY+40,posX+60,posY+25,posX+150,posY+20);

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

stroke(#FCA88A);                                     //cheek l
fill(#FCA88A);
ellipse(posX-65, posY+85, 30, 30);

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

stroke(0);                                          //hand l
fill(#FFEDB9);
ellipse(posX-70, posY+160, 60, 60);

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

textSize(60);                                       //name book
fill(c);
text("REBORN!",posX-120,posY-190);

}

void mousePressed(){
  c=#FF0004;
}

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

Lab 3 : Flying Bird

int w=150;
int c;

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

void draw(){
  background(#69C2F7);
  w=mouseY;
  if(frameCount%40>20){
    w+=40;
  }else{
    w-=50;
  }
  if(mouseY<200){
    c=#FF0000;
  }else if(mouseY<350){
    c=255;
  }else{
    c=#10BF08;
  }

  draw_bird(mouseX,mouseY);
}

void draw_bird(int x,int y){
    strokeWeight(5);
    fill(c);
  ellipse(x,y,150,150);             //head

    fill(255);
  ellipse(x-25,y-10,30,30);               //eye l
  ellipse(x+25,y-10,30,30);               //eye r

    fill(#FAC208);
  triangle(x-20,y+30,x,y+15,x+20,y+30);     //mouse on
  triangle(x-15,y+30,x,y+40,x+15,y+30);     //mouse under

    fill(0);
  ellipse(x-25,y-10,10,10);                 //in eye l
  ellipse(x+25,y-10,10,10);                //in eye r

  rect(x-45,y-30,40,10);                    //eyebrow l
  rect(x+5,y-30,40,10);                    //eyebrow r

  line(x-75,y,x-150,w);                  //wing l
  line(x+75,y,x+150,w);               //wing r
}