แสดงบทความที่มีป้ายกำกับ Lab 3 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ Lab 3 แสดงบทความทั้งหมด

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

Lab 3 - Service Charge

int space = 50;
void setup() {
  size(650, 300);
  background(#000000);
  int x =50, y =50;

  int packageType = 2;
  int serviceType = 2; 
  float weight = 7.99;

  fill(#00FFFF);
  textSize(40);
  text("Expressimo Delivery Service", x, y);
  charge(x+space, y+space, packageType, serviceType, weight);
}

void charge(int x, int y, int package_t, int service_t, float weight) {
  float cost = 0;
  fill(#00FF00);
  textSize(25);
  if (package_t == 1) {
    text("Package Type : LETTER", x, y);
  } else if (package_t == 2) {
    text("Package Type  : BOX", x, y);
  } else {
    text("Package Type  : ERROR", x, y);
  }

  if (service_t == 1) {
    text("Service Type  : Next day Priority", x, y+space);
  } else if (service_t == 2) {
    text("Service Type  : Next day Standard", x, y+space);
  } else if (service_t == 3) {
    text("Service Type  : Two-days", x, y+space);
  } else {
    text("Service : ERROR", x, y+space);
  }

  if (package_t == 1) {
    text("Weight : "+weight+" Oz", x, y+space*2);
    if (service_t == 1 && weight <= 8) {
      cost = 12;
    }
    if (service_t == 2 && weight <= 8) {
      cost = 10.5;
    }
    if (service_t >= 3 || weight > 8) {
      cost = 0;
      text("Charge : $"+cost+" (No Services)", x, y+space*3);
    }
  }
  if (package_t == 2) {
    text("Weight : "+weight+" Pound", x, y+space*2);
    if (service_t == 1) {
      if (weight <= 1) cost = 15.75;
      else if (weight > 1) {
        cost = cal_service1(weight);
      }
    } else if (service_t == 2) {
      if (weight <= 1) cost = 13.75;
      else if (weight > 1) {
        cost = cal_service2(weight);
      }
    } else if (service_t == 3) {
      if (weight <= 1) cost = 7.00;
      else if (weight > 1) {
        cost = cal_service3(weight);
      }
    }
  }
  text("Charge : $"+cost, x, y+space*3);
}

float cal_service1(float weight) {
  float priority_charge;
  float firstCharge = 15.75;
  priority_charge = firstCharge + ((weight-1)*1.25);
  return priority_charge;
}

float cal_service2(float weight) {
  float standard_charge;
  float firstCharge = 13.75;
  standard_charge = firstCharge + ((weight-1)*1);
  return standard_charge;
}

float cal_service3(float weight) {
  float twodays_charge;
  float firstCharge = 7.00;
  twodays_charge = firstCharge + ((weight-1)*0.5);
  return twodays_charge;
}

Lab 3 - Syntax Error

Syntax Error
    ปีกนกยืดตามเมาส์เนื่องจากไม่ได้กำหนดค่าตัวแปรให้


Lab 3 - Book

int value = 0;

void setup(){
size (800,600);
background(value);

}
void draw() {
  //Center Alphabet
  fill(value,value,0);
  stroke(value,value,0);
  rect(360,200,80,160);
  rect(310,240,180,80);
  quad(280,440,310,360,360,360,360,440);
  arc(360,360,160,160,0,HALF_PI);

  // Left Alphabet

  fill(value,0,value);
  stroke(value,0,value);
  ellipse(580,280,160,160);
  rect(660,240,80,120);
  quad(500,440,530,360,660,360,660,440);
  arc(660,360,160,160,0,HALF_PI);

  // Right Alphabet
  fill(0,value,value);
  stroke(0,value,value);
  arc(220,320,160,160, PI+PI/2, TWO_PI);
  arc(220,360,160,160,0,HALF_PI);
  rect(220,320,80,40);
  rect(110,240,110,80);
  quad(80,440,110,360,220,360,220,440);

  // Text
   textSize(40);
  text("Detective Conan",30,220);
}
void mousePressed() {
  if (value == 0) {
    value = 255;
  } else {
    value = 0;
  }
}

Lab 3 - Power of Ten


void setup() {
  size (400, 400);
  background (255);
  fill(255,0,0);
  textSize(30);
  textAlign(CENTER);
  text("Power of Ten",width/2,50);
  
}

void draw() {
  power_ten(6);
  power_ten(5);
  power_ten(12);
  power_ten(15);
  power_ten(18);
  power_ten(21);
  power_ten(30);
  power_ten(100);
  
  
}

void power_ten(int x){
  
  fill(0);
  textSize(15);
  if(x==6||x==9||x==12||x==15||x==18||x==21||x==30||x==100){
    if(x==6){
    text("10^"+x+"= Million",width/2,height/2-70);
    }
    if(x==9){
    text("10^"+x+"= Billion",width/2,height/2-50);
    }
    if(x==12){
    text("10^"+x+"= Trillion",width/2,height/2-30);
    } 
    if(x==15){
    text("10^"+x+"= Quadrillion",width/2,height/2-10);
    }
    if(x==18){
    text("10^"+x+"= Quintillion",width/2,height/2+10);
    }
    if(x==21){
    text("10^"+x+"= Sextillion",width/2,height/2+30);
    }
    if(x==30){
    text("10^"+x+"= Nonillion",width/2,height/2+50);
    }
    if(x==100){
    text("10^"+x+"= Googol",width/2,height/2+70);
    }
  } else {
    
    textAlign(CENTER);
    textSize(50);
    
    text("ERROR!!!",width/2,height/2);
  }
  
}

Lab 3 - Leap Year


void setup(){
  size(400,400);
  background(255);
  textAlign(CENTER);
  textSize(30);
  fill(0,0,255);
  text("LEAP YEAR",width/2,50);
}

void draw(){
  leap_year(2016);
}

void leap_year(int x){

  if(x%4==0&&x!=0||x%400==0){
    fill(0,255,0);
    text(x+" is Leap Year",width/2,height/2);
  } else{
    fill(255,0,0);
    text(x+" isn't Leap Year",width/2,height/2+30);
  }
  }

Lab 3 - Grade Calculator

void setup() {
  cal_grade(50);
  cal_grade(60);
  cal_grade(75);
  cal_grade(89);
}

void cal_grade(int x) {
  if (x>=50) {
    if (x>=60) {
      if (x>=70) {
        if (x>=80) {
          println("grade A");
        } else println("grade B");
      } else println("grade C");
    } else println("grade D");
  } else println("grade F");
}

Lab 3 - Flying Bird

int fly;
int cloudx=600;

void setup() {
  size(600, 400);
  strokeWeight(5);
}
void draw() {
  background(#1ACFFF);
  fly=mouseY;
  if (frameCount%40>30) {
    fly=fly+20;
  } else {
    fly=fly-50;
  }
 
  fly_bird(mouseX, mouseY);
 
  cloud(25,20);
  cloud(10,350);
  cloud(100,100);
  cloud(50,250);
  cloudx=(cloudx+2)%width;
}




void fly_bird(int x, int y) {
  stroke(0);
  ellipse(x, y, 100, 40);
  ellipse(x-20, y, 1, 1);
  line(x, y, x+100, fly);
}

void cloud(int a,int b){
  noStroke();
  fill(255);
    ellipse(a+cloudx,b,50,50);
    ellipse(a+30+cloudx,b,50,50);
    ellipse(a+60+cloudx,b,50,50);
   
}

Lab 3 - Battery Status

int battx=10;
int speed=1;
int axis_X= 200;
int axis_Y= 200;
int sizex = 50;
int sizey = 200;
int angle = 5;
 
void setup() {
  size (800, 600);
  background(0);
  stroke(255);
  strokeWeight(3);
  noFill();
  rect(axis_X+10, axis_Y, 440, sizey, angle );
  rect(650, 280, 20, 40, angle );
}
void draw() {
  battx=battx+speed;
  frameRate(60);
 
  //body
  noStroke();
  rect(axis_X+battx, axis_Y, sizex, sizey, angle );
  if (battx<14) {
    fill(#32CD32);
    speed=1;
  }
  if (battx==400) {
    textSize(40);
    text("Full", width/2, 60);
    speed=0;
  }
 
}

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

Lab 3 - Balloon Drag Mouse

void setup() {
  size (400, 600);
}
void draw() {
  background(255);
  int x = 200;
  int y = mouseY;

  if (y < 100) {
      y = 100;
      fill(#00AA00);
  } else {
      fill(255);
    if (y>500) {
      y=500;
      fill(#0000AA);
    }
  }
  draw_balloon(x, y);
}

void draw_balloon(int x, int y) {
  int sized = 100;
  int string_length = 150;

  line(x, y, x, y + string_length);
  ellipse(x, y, sized, sized);
}