วันอังคารที่ 22 กันยายน พ.ศ. 2558

Lab5-- Find average of values in array

def findAverage():
   ListNum=[1,2,3,4,5,6,7,8]
   i=0
   sum=0
   while(i<len(ListNum)):
      sum=sum+ListNum[i]
      i=i+1
   average=sum/len(ListNum)  
   print("Average of Array =",average)
 
findAverage()

Result
Average of Array = 4.5

Lab5-Find Sum of value in array

def findSum():
   ListNum=[1,2,3,4,5,6,7,8]
   i=0
   sum=0
   #lengthListNum=len(ListNum)-1
   while(i<len(ListNum)):
      sum=sum+ListNum[i]    
      print("+",ListNum[i])  
      i=i+1
   print("Sum=",sum)
findSum()


Result
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
Sum= 36

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

Lab5-Element of Array

def eleArray():
   n=[1,2,3,4,5,6,7,8]
   i=0
   while(i<len(n)):
      print("n","[",i,"]","=",n[i])
      i=i+1
     
eleArray()  

ผลลัพธ์
n [ 0 ] = 1
n [ 1 ] = 2
n [ 2 ] = 3
n [ 3 ] = 4
n [ 4 ] = 5
n [ 5 ] = 6
n [ 6 ] = 7
n [ 7 ] = 8

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

Lab4x-Circle

import math
def calCircle(radius):
  circumferance=2*math.pi*radius
  area=math.pi*radius**2
  print("Radius=",radius)
  print("Circumferance=",circumferance)
  print("Area=",area)

calCircle(10)

Lab4x-Sum of Prime Number

def setup():
   print(sumOfPrimeNum(10))
def sumOfPrimeNum(lastNum):
   x=2
   sum=0
   while(x<=lastNum):
      if(primeNum(x)):
        sum=sum+x
      x=x+1
   return sum
 
def primeNum(p):
   x = 2
   while(x<p):
      if(p%x == 0 or p==1 ):
         return False
   
      x=x+1
   return True
setup()

Lab4x-Grade

def BMI(weight,heightM):
  heightCm=heightM/100
  BMI = weight/(heightCm**2);
  print("height=",heightM,"m")
  print("weight=",weight,"kg")
  print("BMI=",BMI)

BMI(71,167)   

#grade
def grade(score):
     text="\"your grade is"
     if(score<50):
        print(text,'F')
        print("You should have more practice")
     elif(score>=50 | score<=59):
        print(text,'D')
     elif(score>=60 | score<=69):
        print(text,'C')
     elif(score>=70 | score<=79):
        print(text,'B')
     elif(score>=80 | score<=100):
        print(text,'A')

grade(70)

Lab4x-BMI

def BMI(weight,heightM):
  heightCm=heightM/100
  BMI = weight/(heightCm**2);
  print("height=",heightM,"m")
  print("weight=",weight,"kg")
  print("BMI=",BMI)

BMI(71,167)  

Lab4x-Multiple Table

def setup(table):
  firstNum=1
  x=12
  while(firstNum<=x):
     result=table*firstNum
     print(table,"X",firstNum,"=",result)
     firstNum=firstNum+1
setup(25)

Lab4x-Sum of Integer

def setup(firstNum,lastNum):
  sum=0
  while(firstNum<=lastNum):
     sum=sum+firstNum
     firstNum=firstNum+1
  print("sum =",sum)
setup(1,10)

Lab4x-Service Charge

def serviceCharge(typeOfPackage, typeOfService, weightOfPackage):
   cost=0
   textTypePac="type of package is"
   textTypeSer="type of service is"
   textWeight="Weight of package is"
   if(typeOfPackage==1):
      print(textTypePac,"Letter")
      print(textWeight,weightOfPackage,"oz")
   elif(typeOfPackage==2):
      print(textTypePac,"Box")
      print(textWeight,weightOfPackage,"pound")
   else:
      print("Not Found")
   
   if(typeOfService==1):
      print(textTypeSer,"Next Day Priority")
   elif(typeOfService==2):
      print(textTypeSer,"Next Day Standard")
   elif(typeOfService==3):
      print(textTypeSer,"Two-Day")
   else:
      print(textTypeSer,"Not Found")
   
   if(typeOfPackage==1):
      if(typeOfService==1 and weightOfPackage<=8):
         cost=12
      elif(typeOfService==2 and weightOfPackage<=8):
         cost=10
      else:
         print("No Service")
       
   if(typeOfPackage==2):
      if(typeOfService==1):
         if(weightOfPackage<=1):
             cost=15.75
         elif(weightOfPackage>1):
             cost=15.75+((weightOfPackage-1)*1.25)
      elif(typeOfService==2):
         if(weightOsPackage<=1):
             cost=13.75
         elif(weightOfPackage>1):
             cost=13.75+((weightOfPackage-1)*1.00)
      elif(typeOfService==3):
         if(weightOfPackage<=1):
             cost=7
         elif(weightOfPacksge>1):
             cost=7+ ((weightOfPackage-1)*0.50)
      print("Charge: $",cost)
   
serviceCharge(2,1,20)

วันอังคารที่ 15 กันยายน พ.ศ. 2558

Lab4-plant as zombie

int shoot;
int colour;
void setup(){
  size(500,500);
  }
void draw(){
  int n = 0;
  int count = 3;
  int another = 0;
  int x = 100;
  int y = 100;
  size(500,500);
  background(#FFFFFF);
  while(n<=count){
  zombie(x+another,y);
  another+=100;
  n+=1;
  }
  plant(mouseX,mouseY);
  pea(shoot,colour);
  advice(10,400);
  if( mousePressed == true){
    colour=#99ff00;
    shoot+=10;
  }
  while(shoot>350){
    shoot=0;
  }

}
void plant(int x, int y){
  stroke(#339900);
  strokeWeight(5);
  fill(#99FF00);
  arc(x-100,y,100,150,PI,TWO_PI);
  arc(x-100,y,100,100,PI,TWO_PI);
  fill(#FFFFFF);
  arc(x-100,y,100,70,PI,TWO_PI);
  fill(#99FF00);
  arc(x+20,y+100,100,200,HALF_PI,PI+HALF_PI);
  fill(#FFFFFF);
  arc(x+20,y+100,70,200,HALF_PI,PI+HALF_PI);
  //head
  stroke(#339900);
  strokeWeight(5);
  fill(#99FF00);
  ellipse(x-20,y+100,50,25);
  ellipse(x,y,200,200);//face
  ellipse(x+120,y+20,100,140);//mouth

  fill(#000000);
  ellipse(x+130,y+20,50,100);//hole

  //eye
  stroke(#000000);
  strokeWeight(1);
  ellipse(x+10,y-30,40,70);//Reye
  ellipse(x+50,y-40,30,60);//Leye
  fill(#FFFFFF);
  ellipse(x+5,y-40,15,30);
  ellipse(x+45,y-50,10,20);

  stroke(#339900);
  strokeWeight(5);
  fill(#00CC00);
  ellipse(x+70,y+200,100,50);
  ellipse(x-30,y+200,100,50);
  }
void pea(int shoot, int Gcolor){
  int r = 50;
  fill(colour);
  noStroke();
  ellipse(mouseX+130+shoot,mouseY+20,r,r);
}
void advice(int x, int y){
  textSize(30);
  fill(0);
  text("Press left mouse to shoot",x,y);
}
void zombie(int x, int y){
  fill(#999999);
  rect(x-30,y+30,60,30,20);
  ellipse(x,y,100,100);
  fill(#FFFFFF);
  ellipse(x-20,y-10,30,30);
  ellipse(x+20,y-10,30,30);
  rect(x-20,y+30,40,20,20);
  fill(0);
  ellipse(x-25,y-15,5,5);
  ellipse(x+20,y-5,5,5);

}

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

Lab4-Lone

void setup() {
  size(850, 600);
  background(0);
  int year = 1;
  calLone(5000,0.12,year);
  draw_text(year);
}
void calLone(float beginBalance, float interestRate, int year) {
  int x = 430;
  int y = 400;

  int month = year*12;
  float IRPM = interestRate/month;//interest rate per month
  float paypermonth = beginBalance*(IRPM/(1-pow(1+IRPM, -month)));
  float interest = 0;
  float principal = 0;
  float endingBalance = 0;
  int n = 1;

  while (n<=month) {
    interest = IRPM*beginBalance;
    principal = paypermonth - interest;
    endingBalance = beginBalance - principal;
 
    textSize(30);
    text(nf(+beginBalance,3,1),x-300,y-300);
    text(nf(+interest,2,1),x-100,y-300);
    text(nf(+principal,3,1),x+50,y-300);
    text(nf(+endingBalance,3,1),x+220,y-300);
    beginBalance = endingBalance;
    y+=40;
    n+=1;
  }
}

void draw_text(int year){
  int x = 430;
  int y = 400;
  int n = 1;
  int month = year*12;

  text("Begin Balance",x-350,y-350);
  text("interest",x-130,y-350);
  text("principal",x+20,y-350);
  text("Ending balance",x+160,y-350);

  while(n<=month){
    text(+n,x-370,y-300);
    y+=40;
    n++;
  }

}

Lab4-Sum of integers

void setup(){
  size(300,300);
  background(#CCCC00);
  int x = 100;
  int y = 100;
  int firstNum = 0;
  int lastNum = 10;
  int sum = 0 ;
  textSize(30);
  text("Sum of "+firstNum,x-50,y);
  text("to "+lastNum,x+90,y);
  text("is",x+50,y+40);
  while(firstNum<=lastNum){
    sum+=firstNum;
    firstNum++;
  }
 text(+sum,x+35,y+80);
}

Lab4-Sum of prime number

void setup(){
  size(500,400);
  background(#FFCC33);
  int x = 250;
  int y = 250;
  int firstNum = 0;
  int lastNum = 10;
  textSize(30);
  text("Sum of Prime Number from "+firstNum,x-200,y-100);
  text("to  "+lastNum,x-25,y-60);
  text("is",x,y-20);
  text(+sumOfPrime(firstNum,lastNum),x-10,y+20);
}

int sumOfPrime(int firstNum, int lastNum){
  int x = 2;
  int sum = 0;
  while(x<=lastNum){
    if(primeNum(x)){
      sum+=x;
    }
    x++;  
  }
  return sum;
}

boolean primeNum(int p){
  boolean result = true;
  int x = 2;
  while(x<p){
    if(p%x == 0 || p==1 ){
      result = false;  
    }
    x++;
  }
  return result;
}

Lab4-flock of bird

int x=250;
int y=250;
int fly=0;
int Rtree1mov;
int Rtree2mov;
int Ltree1mov;
int Ltree2mov;
void setup(){
  size(700,700);
  }
void draw(){
  size(700,700);
  background(#33FFFF);
  int posX = mouseX;
  int posY = mouseY;
  int n =0;
  int count = 3;
  int another = 0;
  frameRate(50);
    view_background(Rtree1mov,Rtree2mov,Ltree1mov,Ltree2mov);
  Rtree1mov+=1;
  Rtree2mov+=1;
  Ltree1mov+=1;
  Ltree2mov+=1;
  if(Rtree1mov>180){
    Rtree1mov=0;
  }
  if(Rtree2mov>80){
    Rtree2mov=-100;
  }
  if(Ltree1mov>180){
    Ltree1mov=0;
  }
  if(Ltree2mov>80){
    Ltree2mov=-100;
  }
  while(n<=count){
      bird(posX+another,posY+another,80,fly);
      bird(posX-another,posY+another,80,fly);
      if(frameCount%20>15){
      fly=-120;
      } else {
      fly=60;
      }
      n+=1;
      another+=100;
  }
}
void bird(int x, int y, int r, int fly){
  strokeWeight(5);
  line(x+r/2,y,x+80+fly/5,y+40+fly);
  line(x-r/2,y,x-80-fly/5,y+40+fly);
  fill(#666666);
  arc(x,y,100,150,PI+QUARTER_PI,TWO_PI-QUARTER_PI);
  ellipse(x,y,r,r);//body
  ellipse(x-15,y-10,r-60,r-60);//Leye
  ellipse(x+15,y-10,r-60,r-60);//Reye
  fill(#FFFF00);
  triangle(x-15,y+10,x,y+50,x+15,y+10);
}
void view_background(int Rtree1mov, int Rtree2mov, int Ltree1mov, int Ltree2move){
  int x = 350;
  int y = 350;
  int sizeX = 50;
  int sizeY = 90;
  strokeWeight(0);
  fill(#999999);
  quad(x+50,y,x-50,y,0,y+350,x+350,y+350);//fill colour lane
  fill(#99FF00);
  triangle(0,y,x-50,y,0,y+350);//fill colour left lane
  triangle(x+350,y,x+50,y,x+350,y+350);//fill colour right lane
  fill(#336600);
  rect(x+130+Rtree1mov,y-20+Rtree1mov,sizeX,sizeY);//trunk Rtree1
  rect(x-180-Ltree1mov,y-20+Ltree1mov,sizeX,sizeY);//trunk Ltree1
  rect(x+230+Rtree2mov,y+100+Rtree2mov,sizeX,sizeY);//trunk Rtree2
  rect(x-280-Ltree2mov,y+100+Ltree2mov,sizeX,sizeY);//trunk Ltree2
  fill(#669900);
  triangle(x+110+Rtree1mov,y-20+Rtree1mov,x+155+Rtree1mov,y-160+Rtree1mov,x+200+Rtree1mov,y-20+Rtree1mov);//leave Rtree1
  triangle(x-110-Ltree1mov,y-20+Ltree1mov,x-155-Ltree1mov,y-160+Ltree1mov,x-200-Ltree1mov,y-20+Ltree1mov);//leave Ltree1
  triangle(x+210+Rtree2mov,y+100+Rtree2mov,x+255+Rtree2mov,y-60+Rtree2mov,x+300+Rtree2mov,y+100+Rtree2mov);//leave  Rtree2
  triangle(x-210-Ltree2mov,y+100+Ltree2mov,x-255-Ltree2mov,y-60+Ltree2mov,x-300-Ltree2mov,y+100+Ltree2mov);//leave Ltree2
}

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

Lab4-Many balloon

void setup() {
  size(500, 500);
}
void draw() {
  size(500,500);
  background(#FFFFFF);
  int x=mouseX;
  int y=mouseY;
  balloon(x, y);
}
void balloon(int x, int y) {
  int count = 4;
  int n = 0;
  int another = 0;
  if (x <250 && y < 250) {
      background(#CCFF00);
    fill(#FF6600);
  }else if(x > 250 && y < 250){
  background(#FF0000);
    fill(#990066);
  }else if(x < 250 && y > 250){
    background(#990066);
    fill(#CCFF00);
  }else if(x > 250 && y > 250 ){
  background(#FF6600);
    fill(#FF0000);
  }
  while(n<=count){
  line(x+another, y+another, x+another, y+200+another);
  ellipse(x+another, y+another, 100, 100);
  another+=50;
  n+=1;
  }
}

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

Lab3-Power of ten

void setup(){
    size(500,500);
    background(#DD0000);
    int power = 6;
    textSize(30);
    text("Power of ten ="+power,width/2-200,height/2);
    text("Word number is",width/2-200,height/2+50);
    powerOfTen(power);
}

void powerOfTen(int Power_Ten){
    if(Power_Ten==6) {      
        text("Million",width/2+30,height/2+50);
    }else if(Power_Ten==9){ 
        text("Billion",width/2+30,height/2+50);
    }else if(Power_Ten==12){
        text("trillion",width/2+30,height/2+50);
    }else if(Power_Ten==15){
        text("Quadrillion",width/2+30,height/2+50);
    }else if(Power_Ten==18){
        text("Quintillion",width/2+30,height/2+50);
    }else if(Power_Ten==21){
        text("Sextillion",width/2+30,height/2+50);
    }else if(Power_Ten==30){
        text("Nonillion",width/2+30,height/2+50);
    }else if(Power_Ten==100){
        text("Googol",width/2+30,height/2+50);
    }

}

Lab3-Leap year

int whenYear = 1997;
void setup(){
    size(500,500);
    background(#FFFFCC);

    }
void draw(){
    textSize(50);
    fill(0);
    word();

     }
void word(){
    text("Leap Year",width/5,height/5);
    text(+whenYear,width/2-230,height/2);
    showLeap(leapYear(whenYear));  
}
void showLeap(boolean booLean){
  if (booLean == true){
    fill(255,0,0);
    text("is Leap Year ",width/2-110,height/2);
    fill(#666666);
  }else{
    text("isn't Leap Year ",width/2-110,height/2);
  }
}

boolean leapYear(int whenYear){
  boolean value=false;
  if(whenYear%4 == 0){
    if(whenYear%100 ==0){
      if(whenYear%400 ==0){
        value = true;}
      }else{
        value = true;}
    }else{
      value = false;
    }
    return value;
}

Lab3-service charge

void setup() {
  size(600, 400);
  background(#cc3333);
  textSize(30);
  text("Expressimo Delivery Service", width/10, height/10);
  text("type of package is", width/50+10, height/2-90);
  text("type of service is", width/50+10, height/2-50);
  serviceCharge(2,1,20);
}
//Choose Type of package 1=Letter,2=Box
//Choose Type os service 1=Next Day Priority,2=Next Day Standard,3=Two-Day
void serviceCharge(int typeOfPackage, int typeOfService, float weightOfPackage ) {
  float cost = 0;
  if (typeOfPackage==1) {
    text("Letter", width/50+280, height/2-90);
  } else if (typeOfPackage==2) {
    text("Box", width/50+280, height/2-90);
  } else {
    text("Not found", width/50+280, height/2-90);
  }
  if (typeOfService==1) {
    text("Next Day Priority", width/50+270, height/2-50);
  } else if (typeOfService ==2) {
    text("Next Day Standard", width/50+270, height/2-50);
  } else if (typeOfService ==3) {
    text("Two-Day", width/50+270, height/2-50);
  } else {
    text("Not found", width/50+270, height/2-50);
  }
  if (typeOfPackage == 1) {
    text("oz.", width/2+340, height/2-10);
    if (typeOfService == 1 && weightOfPackage <= 8)
      cost = 12;
    if (typeOfService == 2 && weightOfPackage <= 8)
      cost = 10;
    if (typeOfService >= 3 || weightOfPackage > 8)
    text("'No Services'", 230, height/2+110);
  }

  if (typeOfPackage  == 2) {
    text("pound.", width/2+130, height/2-10);
    if (typeOfService == 1) {
      if (weightOfPackage <= 1)
        cost = 15.75;
      else if (weightOfPackage > 1) {
        cost = calServicePriority(weightOfPackage);
      }
    } else if (typeOfService == 2) {
      if (weightOfPackage <= 1)
      cost = 13.75;
      else if (weightOfPackage > 1) {
        cost = calServiceStandard(weightOfPackage);
      }
    } else if (typeOfService == 3) {
      if (weightOfPackage <= 1)
      cost = 7.00;
      else if (weightOfPackage > 1) {
        cost = calServiceTwodays(weightOfPackage);
      }
    }
  }
  text("Weight of Package :  "+weightOfPackage, width/50+10, height/2-10);
  text("Charge : "+"$ "+cost, width/50+10, height/2+30);
}

float calServicePriority(float weightOfPackage) {
  float priorityCharge;
  float firstCharge = 15.75;
  priorityCharge = firstCharge + ((weightOfPackage-1)*1.25);
  return priorityCharge;
}

float calServiceStandard(float weightOfPackage) {
  float standardCharge;
  float firstCharge = 13.75;
  standardCharge = firstCharge + ((weightOfPackage-1)*1.00);
  return standardCharge;
}

float calServiceTwodays(float weightOfPackage) {
  float twodaysCharge;
  float firstCharge = 7.00;
  twodaysCharge = firstCharge + ((weightOfPackage-1)*0.50);
  return twodaysCharge;
}

Lab3-Battery react

int x=10;
int y=100;
int sizeX=110;
int sizeY=100;
int time=0;
void setup(){
    size(500,500);
    noStroke();
    fill(#FFFFFF);
    rect(x+50,y,sizeX+50,sizeY+160,20);//Body battery
    rect(x+115,y-20,sizeX-80,sizeY-60,20);//positive termoinal
    bodyBat(sizeX,sizeX,sizeX,sizeX,sizeX);
    energy(0,0,0,0,0);
    hor(x,y-70);
    hor(x,y+290);
    ver(x+100,y-75);
    textSize(30);
    text("Use battery",x+230,y);
    text("press mouseright",x+230,y+30);
    text("Charge battery",x+230,y+70);
    text("press mouseleft",x+230,y+100);
    }
 
void draw(){
    if ( mousePressed && mouseButton == RIGHT){
      time+=1;
      energyDrop();
    }
    if( mousePressed && mouseButton == LEFT){
      time-=1;
      energyCharge();
    }
}
void energyDrop(){
    if(time>50){
      bodyBat(0,sizeX,sizeX,sizeX,sizeX);
      energy(1000,0,0,0,0);  
    }
    if(time>100){
      bodyBat(0,0,sizeX,sizeX,sizeX);
      energy(1000,1000,0,0,0);
    }
    if(time>150){
      bodyBat(0,0,0,sizeX,sizeX);
      energy(1000,1000,1000,0,0);
    }
    if(time>200){
      bodyBat(0,0,0,0,sizeX);
      energy(1000,1000,1000,1000,0);
    }
    if(time>250){
      bodyBat(0,0,0,0,0);
      energy(1000,1000,1000,1000,1000);
    }
}
void energyCharge(){
    if(time<250){
      bodyBat(0,0,0,0,sizeX);
      energy(1000,1000,1000,1000,0);  
    }
    if(time<200){
      bodyBat(0,0,0,sizeX,sizeX);
      energy(1000,1000,1000,0,0);
    }
    if(time<150){
      bodyBat(0,0,sizeX,sizeX,sizeX);
      energy(1000,1000,0,0,0);
    }
    if(time<100){
      bodyBat(0,sizeX,sizeX,sizeX,sizeX);
      energy(1000,0,0,0,0);
    }
    if(time<50){
      bodyBat(sizeX,sizeX,sizeX,sizeX,sizeX);
      energy(0,0,0,0,0);
    }
}
//body battery function//
void bodyBat(int sizeX1,int sizeX2,int sizeX3,int sizeX4,int sizeX5){
    fill(#FFFFFF);
    rect(x+50,y,sizeX+50,sizeY+160,20);//Body battery
    rect(x+115,y-20,sizeX-80,sizeY-60,20);//positive termoinal
    fill(#33CC00);
    rect(x+70,y+10,sizeX1,sizeY-60,20);//100%-81%
    fill(#33FF00);
    rect(x+70,y+60,sizeX2,sizeY-60,20);//80%-61%
    fill(#66FF00);
    rect(x+70,y+110,sizeX3,sizeY-60,20);//60%-41%
    fill(#FF6600);
    rect(x+70,y+160,sizeX4,sizeY-60,20);//40%-21%
    fill(#FF3300);
    rect(x+70,y+210,sizeX5,sizeY-60,20);//20%-0%
}
//Number of battery function//
void energy(int C1,int C2,int C3,int C4,int C5){
    textSize(30);
    fill(C1);
    text("100%",x+90,y+40);
    fill(C2);
    text("80%",x+100,y+90);
    fill(C3);
    text("60%",x+100,y+140);
    fill(C4);
    text("40%",x+100,y+190);
    fill(C5);
    text("20%",x+100,y+240);
}
//horizontal function//
void hor(int axisHorX,int axisHorY){
    rect(axisHorX+100,axisHorY,sizeX-60,sizeY-80);
    }
//vertical function//
void ver(int x,int y){
    rect(x+15,y-10,sizeX-90,sizeY-50);
    }

Lab3-Bird

int x=250;
int y=250;
int fly=0;
int Rtree1mov;
int Rtree2mov;
int Ltree1mov;
int Ltree2mov;
void setup(){
  size(700,700);
  frameRate(10);
  }
void draw(){
  size(700,700);
  background(#33FFFF);
  frameRate(50);
  view_background(Rtree1mov,Rtree2mov,Ltree1mov,Ltree2mov);
  Rtree1mov+=1;
  Rtree2mov+=1;
  Ltree1mov+=1;
  Ltree2mov+=1;
  if(Rtree1mov>180){
    Rtree1mov=0;
  }
  if(Rtree2mov>80){
    Rtree2mov=-100;
  }
  if(Ltree1mov>180){
    Ltree1mov=0;
  }
  if(Ltree2mov>80){
    Ltree2mov=-100;
  }
 
  bird(mouseX,mouseY,80,fly);
  if(frameCount%20>15){
  fly=-120;
  } else {
  fly=60;
  }

}
void bird(int x, int y, int r, int fly){
  strokeWeight(5);
  line(x+r/2,y,x+80+fly/5,y+40+fly);
  line(x-r/2,y,x-80-fly/5,y+40+fly);
  fill(#666666);
  arc(x,y,100,150,PI+QUARTER_PI,TWO_PI-QUARTER_PI);
  ellipse(x,y,r,r);
  ellipse(x-15,y-10,r-60,r-60);
  ellipse(x+15,y-10,r-60,r-60);
  fill(#FFFF00);
  triangle(x-15,y+10,x,y+50,x+15,y+10);
  }
void view_background(int Rtree1mov, int Rtree2mov, int Ltree1mov, int Ltree2move){
  int x = 350;
  int y = 350;
  int sizeX = 50;
  int sizeY = 90;
  strokeWeight(0);
  fill(#999999);
  quad(x+50,y,x-50,y,0,y+350,x+350,y+350);//fill colour lane
  fill(#99FF00);
  triangle(0,y,x-50,y,0,y+350);//fill colour left lane
  triangle(x+350,y,x+50,y,x+350,y+350);//fill colour right lane
  fill(#336600);
  rect(x+130+Rtree1mov,y-20+Rtree1mov,sizeX,sizeY);//trunk Rtree1
  rect(x-180-Ltree1mov,y-20+Ltree1mov,sizeX,sizeY);//trunk Ltree1
  rect(x+230+Rtree2mov,y+100+Rtree2mov,sizeX,sizeY);//trunk Rtree2
  rect(x-280-Ltree2mov,y+100+Ltree2mov,sizeX,sizeY);//trunk Ltree2
  fill(#669900);
  triangle(x+110+Rtree1mov,y-20+Rtree1mov,x+155+Rtree1mov,y-160+Rtree1mov,x+200+Rtree1mov,y-20+Rtree1mov);//leave Rtree1
  triangle(x-110-Ltree1mov,y-20+Ltree1mov,x-155-Ltree1mov,y-160+Ltree1mov,x-200-Ltree1mov,y-20+Ltree1mov);//leave Ltree1
  triangle(x+210+Rtree2mov,y+100+Rtree2mov,x+255+Rtree2mov,y-60+Rtree2mov,x+300+Rtree2mov,y+100+Rtree2mov);//leave  Rtree2
  triangle(x-210-Ltree2mov,y+100+Ltree2mov,x-255-Ltree2mov,y-60+Ltree2mov,x-300-Ltree2mov,y+100+Ltree2mov);//leave Ltree2
}

Lab3-plant react

int shoot;
int colour;
void setup(){
  size(500,500);
  }
void draw(){
  size(500,500);
  background(#FFFFFF);
  plant(mouseX,mouseY);
  pea(shoot,colour);
  advice(10,400);
  if( mousePressed == true){
    colour=#99ff00;
    shoot+=5;
  }else if(mouseButton == RIGHT){
    colour=0;
    shoot=0;
  }
}
void plant(int x, int y){
  stroke(#339900);
  strokeWeight(5);
  fill(#99FF00);
  arc(x-100,y,100,150,PI,TWO_PI);
  arc(x-100,y,100,100,PI,TWO_PI);
  fill(#FFFFFF);
  arc(x-100,y,100,70,PI,TWO_PI);
  fill(#99FF00);
  arc(x+20,y+100,100,200,HALF_PI,PI+HALF_PI);
  fill(#FFFFFF);
  arc(x+20,y+100,70,200,HALF_PI,PI+HALF_PI);
  //head
  stroke(#339900);
  strokeWeight(5);
  fill(#99FF00);
  ellipse(x-20,y+100,50,25);
  ellipse(x,y,200,200);//face
  ellipse(x+120,y+20,100,140);//mouth

  fill(#000000);
  ellipse(x+130,y+20,50,100);//hole

  //eye
  stroke(#000000);
  strokeWeight(1);
  ellipse(x+10,y-30,40,70);//Reye
  ellipse(x+50,y-40,30,60);//Leye
  fill(#FFFFFF);
  ellipse(x+5,y-40,15,30);
  ellipse(x+45,y-50,10,20);

  stroke(#339900);
  strokeWeight(5);
  fill(#00CC00);
  ellipse(x+70,y+200,100,50);
  ellipse(x-30,y+200,100,50);
  }
void pea(int shoot, int Gcolor){
  int r = 50;
  fill(colour);
  noStroke();
  ellipse(mouseX+130+shoot,mouseY+20,r,r);
}
void advice(int x, int y){
  textSize(30);
  fill(0);
  text("Press left mouse to shoot",x,y);
  text("Press right mouse to reset pea",x,y+50);
}

Lab3-Grade

void setup(){
  size(500,300);
  background(#00FFDD);
  }
void draw(){
  int score = 80;
  textSize(50);
  fill(#DD0000);
  cal_grade(score);
  text("My score ="+score,50,100);
  text("My grade =",50,200);
  }
void cal_grade(int score){
  if(score<50){
  text("F",50,100);
  }else if(score>=50 && score<=59){
  text("D",50,100);
  }else if(score>=60 && score<=69){
  text("C",50,100);  
  }else if(score>=70 && score<=79){
  text("B",100,100);  
  }else if(score>=80 && score<=100){
  text("A",350,200);
  }else if(score<=0 && score>=100){
  text("error",50,200);
  }
}