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

Lab2-Gintama(Color Change)



int eyeSize = 100;
int R = 255;
int G = 255;
int B = 255;

void setup(){
    int space = 200;
    size(500,600);
    background(100);
    strokeWeight(5);
}

void draw(){
    fill(R,G,B);
    rect(50,50,400,500);
    eye(150,200,eyeSize);
    eye(350,200,eyeSize);
    mouth(250,320);
    elizabeth_text(250,80);
    gintama_text(250,500);
}

void mouseMoved() {
    R = R - 5;
    G = G - 15;
    B = B - 51;
    if (R == 0) {
        R = 255;
    }
    if (G == 0) {
        G = 255;
    }
    if (B == 0) {
        B = 255;
    }
}

void eye(int eyeposX,int eyeposY,int eyeSize){
    fill(255);
    ellipse(eyeposX,eyeposY,eyeSize,eyeSize);
    fill(0);
    ellipse(eyeposX,eyeposY,eyeSize/2,eyeSize/2);
    /////Eyelashes/////
    line(eyeposX-40,eyeposY-60,eyeposX-30,eyeposY-40);
    line(eyeposX,eyeposY-70,eyeposX,eyeposY-50);
    line(eyeposX+40,eyeposY-60,eyeposX+30,eyeposY-40);
}

void mouth(int mouthposX,int mouthposY){
    fill(#FFFF00);
    ellipse(mouthposX,mouthposY,250,80);
    line(mouthposX-110,mouthposY,mouthposX+110,mouthposY);
}

void elizabeth_text(int x,int y){
    fill(0);
    textAlign(CENTER);
    textSize(20);
    text("ELIZABETH",x,y);
}

void gintama_text(int x,int y){
    fill(50);
    textAlign(CENTER);
    textSize(70);
    text("GINTAMA",x,y);
}

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

Lab2-Jurassic Brown(Moved & Random Color)

int posX = -300 ,posY = 200;
int color_bgCir,colorText,colorOutline;
int right_moved;
int left_moved;

void setup(){
    size(600,400);
    smooth(4);
    frameRate(50);
}

Lab2-BMI(Function)



int posX = 25, posY = 50;
int space = 50;
float high = 173;
float weight = 60;

void setup(){
    size(450,200);
    background(#99FFFF);

    float BMI = cal_BMI(high,weight);

    textSize(30);
    fill(#008B00);
    text("Weight = "+weight+" kg",posX,posY);
    text("Height = "+high+" cm",posX,posY+space);
    fill(#FF0000);
    text("BMI = "+BMI,posX,posY+space*2);
}

float cal_BMI(float high,float weight){
    float BMI;
    float highM = high/100;
    BMI = weight/(highM*highM);
    return BMI;
}

Lab2-Circle(Function)



int posX = 25, posY = 50;
int space = 50;
float rad = 15;

void setup(){
    size(600,250);
    background(#FFCCCC);

    float dia = cal_dia(rad);
    float cir = cal_cir(rad);
    float area = cal_area(rad);

    fill(#FF0000);
    textSize(30);
    text("Radius = "+rad,posX, posY);
    text("Diameter = "+dia,posX, posY+space);
    text("Area = "+area,posX, posY+space*2);
    text("Circumference = " +cir,posX, posY+space*3);
}

float cal_cir(float rad){
    float cir;
    cir = 2*PI*rad;
    return cir;
}

float cal_area(float rad){
    float area;
    area = PI*rad*rad;
    return area;
}

flaot cal_dia(float rad){
    float dia;
    dia = rad*2;
    return dia;
}

Lab2-BATTERY

int volumeposX = 110 ,volumeposY = 110;
int volumeWidth = 180 ,volumeHeight = 380;
int batteryposX = 100 ,batteryposY = 100;
int batt_usage;
int batt_charge;
int posY_change;
int volumeColor = #008B00;
int update = 0;

void setup(){
  size(400,600);
}

void draw(){
  frameRate(50); 
  background(0);
 
  battery(batteryposX,batteryposY,200,400,60,20);
  positive(batteryposX/2,batteryposY-20);
  negative(batteryposX/2,batteryposY+420);
 
  volumeHeight = volumeHeight - batt_usage + batt_charge;
  volumeposY = volumeposY + posY_change;
 
  if((volumeHeight == 0 && volumeposY == 490) || (volumeHeight == 380 && volumeposY == 110)){
    batt_usage = 0;
    batt_charge = 0;
    posY_change = 0;
  }
 
  int percentage = battPercent(volumeHeight);
  if(percentage <= 40){
    volumeColor = #FFCC00;
  }
  if(percentage <= 20){
    volumeColor = #FF0000;
  }
  if(percentage >= 40){
    volumeColor = #008B00;
  }
}

void mouseClicked() {
  if(volumeHeight <= 380 && volumeposY >= 110 && update == 0) {
    batt_usage = 2;
    batt_charge = 0;
    posY_change = 2;
    update = 1;
  }
  else if(volumeHeight >= 0 && volumeposY <= 490 && update == 1) {
    batt_usage = 0;
    batt_charge = 2;
    posY_change = -2;
    update = 0;
  }
}

void battery(int batteryposX,int batteryposY,int batteryWidth,int batteryHeight,int poleWidth,int poleHeight){
  /////BATTERY BODY/////
  noFill();
  stroke(#FFFFFF);
  strokeWeight(5);
  rect(batteryposX,batteryposY,batteryWidth,batteryHeight);
  fill(255);
  rect((batteryposX+(batteryWidth/2))-(poleWidth/2),batteryposY-poleHeight,poleWidth,poleHeight);
  /////VOLUME/////
  strokeWeight(2);
  fill(volumeColor);
  rect(volumeposX,volumeposY,volumeWidth,volumeHeight);
}

void positive(int positiveposX,int positiveposY){
 fill(#FF0000);
 textAlign(CENTER);
 text("+",positiveposX,positiveposY);
}

void negative(int negativeposX,int negativeposY){
 fill(#FF0000);
 textAlign(CENTER);
 text("-",negativeposX,negativeposY);
}

int battPercent(int volumeHeight){
  int batt_percent = 100;
  batt_percent = (volumeHeight*100)/380;
  textAlign(CENTER);
  textSize(40);
  fill(#FFFFFF);
  text((int)(batt_percent)+"%",batteryposX+100,batteryposY+200);
  return batt_percent;
}





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

Lab1-Spyair(Move Up and Down)

void setup(){
  int up = 250;
  int down = 120;
  size(400,400);
  background(0);
  strokeWeight(12);
  stroke(#FFFFFF);
  noFill();

  /////Logo/////
  ellipse(200,130+down,220,220);
  line(95,100+down,260,40+down);
  line(205,65+down,280,200+down);
  line(205,65+down,180,235+down);
  line(95,100+down,260,165+down);
  line(130,210+down,260,165+down);

  ///// "SPYAIR" /////
  textAlign(CENTER);
  textSize(100);
  text("SPYAIR",200,350-up);
}


Lab1-Gintama(Resize)

void setup(){
  int resize = 40;
  int space = 200;
  size(500,600);
  background(100);
  strokeWeight(5);

  /////Book/////
  rect(50,50,400,500);

  /////Eye/////
  ellipse(150,200,100-resize,100-resize); //Left
  ellipse(150+space,200,100-resize,100-resize); //Right

  /////In Eye/////
  fill(0);
  ellipse(150,200,50-resize,50-resize); //Left
  ellipse(150+space,200,50-resize,50-resize); //Right

  /////Eyelashes/////
  line(110,140,120,160); //Left1
  line(150,130,150,150); //Left2
  line(190,140,180,160); //left3
  line(110+space,140,120+space,160); //Right1
  line(150+space,130,150+space,150); //Right2
  line(190+space,140,180+space,160); //Right3

  /////Mouth/////
  fill(#FFFF00);
  ellipse(250,320,250-resize,80-resize);
  line(140+resize,320,160-resize+space,320);

  ///// "ELIZABETH" /////
  fill(0);
  textAlign(CENTER);
  textSize(20);
  text("ELIZABETH",250,80);

  ///// "GINTAMA" /////
  fill(50);
  textAlign(CENTER);
  textSize(70-resize);
  text("GINTAMA",250,500);
}


Lab1-Jurassic Brown(Move Down)

void setup(){
  int down = 60;
  size(600,400);
  background(0);

  /////Background Logo/////
  noStroke();
  fill(#FFFF00);
  ellipse(300,200,350,350);
  rect(50,200+down,500,120);

  /////Red Circle/////
  stroke(0);
  strokeWeight(5);
  fill(#FF0000);
  ellipse(300,200,320,320);

  /////Ear/////
  strokeWeight(3);
  fill(#4E3028);
  arc(250,130+down,50,60,HALF_PI+QUARTER_PI,PI+PI,OPEN); //Left
  arc(350,130+down,50,60,-PI,QUARTER_PI,OPEN); //Right

  /////InEar/////
  noStroke();
  fill(#281914);
  arc(250,130+down,30,45,HALF_PI+QUARTER_PI,PI+PI,OPEN); //Left
  arc(350,130+down,30,45,-PI,QUARTER_PI,OPEN); //Right

  /////Head/////
  stroke(0);
  strokeWeight(3);
  fill(#4E3028);
  arc(300,210+down,200,200,PI,PI+PI);

  /////Face/////
  noStroke();
  fill(#FFFFCC);
  ellipse(300,200+down,50,70); //Nose Background
  fill(0);
  ellipse(290,160+down,10,10); //Left Eye
  ellipse(310,160+down,10,10); //Right Eye
  stroke(0);
  strokeWeight(3);
  triangle(300,185+down,295,175+down,305,175+down); //Nose

  ///Mouth///
  line(300,180+down,300,200+down);
  line(300,200+down,280,220+down);
  line(300,200+down,320,220+down);

  /////Black label/////
  fill(0);
  rect(60,210+down,480,100);

  ///// "JURASSIC BROWN" /////
  fill(#FFFF00);
  textSize(50);
  text("JURASSIC BROWN",75,280+down);
}


Lab1-Circle

void setup(){
 float dia = 100; //Diameter
 float rad = dia/2; //Radius
 float cir; //Circumference
 float area; //Area

 /////Calculate/////
 cir = 2*PI*rad;
 area = PI*rad*rad;

 /////Show Value/////
 size(600,250);
 background(#FFCCCC);
 fill(#FF0000);
 textSize(30);
 text("Diameter = "+dia,25,50);
 text("Radius = "+rad,25,100);
 text("Circumference = " +cir,25,150);
 text("Area = "+area,25,200);
}


Lab1-BMI

void setup(){
 float high = 173; //Height in centimeters
 float weight = 60; //Weight in kilograms
 float highM = high/100; //Height in meters
 float BMI; //Body Mass Index

 /////Calculate/////
 BMI = weight/(highM*highM);

 /////Show Value/////
 size(450,200);
 background(#99FFFF);
 textSize(30);
 fill(#008B00);
 text("Weight = "+weight+" kg",25,50);
 text("Height = "+high+" cm",25,100);
 fill(#FF0000);
 text("BMI = "+BMI,25,150);
}


วันศุกร์ที่ 21 สิงหาคม พ.ศ. 2558

Lab1-Positive

void setup(){
 int highX = 100; //ความสูงของสี่เหลี่ยมในแนวแกน X
 int widthX = 300; //ความยาวของสี่เหลี่ยมในแนวแกน X
 int highY = 300; //ความสูงของสี่เหลี่ยมในแนวแกน Y
 int widthY = 100; //ความยาวของสี่เหลี่ยมในแนวแกน Y
 int posX = 200; //ตำแหน่งแกน X
 int posY = 50; //ตำแหน่งแกน Y

 size(500,500);
 background(#FFFFFF);

/////POSITIVE/////
noStroke();
 fill(#FF0000);
 rect(posX,posY,highX,widthX);
 rect(posX-100,posY+100,highY,widthY);

///// "POSITIVE" /////
 textAlign(CENTER);
 textSize(60);
 fill(#008B00);
 text("POSITIVE",posX+50,posY+400);
}


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

Lab1-BATTERY

void setup(){
    int space = 65;
    size(400,600);
    background(0);

    /////ตัวแบตเตอรี่/////
    noFill();
    stroke(#FFFFFF)
    strokeWeight(5);
    rect(100,100,200,400);
    fill(#FFFFFF)
    rect(170,80,60,20);
   
    /////ปริมาณแบตเตอรี่ที่คงอยู่/////
    strokeWeight(2);
    //โซนสีเขียว//
    fill(#008B00);
    rect(110,110,180,60);
    rect(110,110+space,180,60);
    rect(110,110+space*2,180,60);
     //โซนสีเหลือง//
    fill(#FFCC33);
    rect(110,110+space*3,180,60);
    rect(110,110+space*4,180,60);
    //โซนสีแดง//
    fill(#FF0000);
    rect(110,110+space*5,180,60);
   
    /////เปอร์เซ็นต์แสดงปริมาณแบตเตอรี่/////
    textAlign(CENTER);
    textSize(40);
    fill(#FFFFFF);
    text("100%",200,155);
    text("80%",200,155+space);
    text("60%",200,155+space*2);
    text("40%",200,155+space*3);
    text("20%",200,155+space*4);
    text("0%",200,155+space*5);
 
    ///// "BATTERY" /////
    textSize(60);
    fill(100);
    text("BATTERY",200,580);
}

 

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

Lab0-SPYAIR

void setup(){
  size(400,400);
  background(0);
  strokeWeight(12);
  stroke(#FFFFFF);
  noFill();

  /////Logo/////
  ellipse(200,130,220,220);
  line(95,100,260,40);
  line(205,65,280,200);
  line(205,65,180,235);
  line(95,100,260,165);
  line(130,210,260,165);

  ///// "SPYAIR" /////
  textAlign(CENTER);
  textSize(100);
  text("SPYAIR",200,350);
}

Lab0-Gintama

void setup(){
  int space = 200;
  size(500,600);
  background(100);
  strokeWeight(5);

  /////Book/////
  rect(50,50,400,500);

  /////Eye/////
  ellipse(150,200,100,100); //Left
  ellipse(150+space,200,100,100); //Right

  /////In Eye/////
  fill(0);
  ellipse(150,200,50,50); //Left
  ellipse(150+space,200,50,50); //Right

  /////Eyelashes/////
  line(110,140,120,160); //Left1
  line(150,130,150,150); //Left2
  line(190,140,180,160); //left3
  line(110+space,140,120+space,160); //Right1
  line(150+space,130,150+space,150); //Right2
  line(190+space,140,180+space,160); //Right3

  /////Mouth/////
  fill(#FFFF00);
  ellipse(250,320,250,80);
  line(140,320,160+space,320);

  ///// "ELIZABETH" /////
  fill(0);
  textAlign(CENTER);
  textSize(20);
  text("ELIZABETH",250,80);

  ///// "GINTAMA" /////
  fill(50);
  textAlign(CENTER);
  textSize(70);
  text("GINTAMA",250,500);
}

 

Lab0-Jurassic Brown

void setup(){
  size(600,400);
  background(0);

  /////Background Logo/////
  noStroke();
  fill(#FFFF00);
  ellipse(300,200,350,350);
  rect(50,200,500,120);

  /////Red Circle/////
  stroke(0);
  strokeWeight(5);
  fill(#FF0000);
  ellipse(300,200,320,320);

  /////Ear/////
  strokeWeight(3);
  fill(#4E3028);
  arc(250,130,50,60,HALF_PI+QUARTER_PI,PI+PI,OPEN); //Left
  arc(350,130,50,60,-PI,QUARTER_PI,OPEN); //Right

  /////InEar/////
  noStroke();
  fill(#281914);
  arc(250,130,30,45,HALF_PI+QUARTER_PI,PI+PI,OPEN); //Left
  arc(350,130,30,45,-PI,QUARTER_PI,OPEN); //Right

  /////Head/////
  stroke(0);
  strokeWeight(3);
  fill(#4E3028);
  arc(300,210,200,200,PI,PI+PI);

  /////Face/////
  noStroke();
  fill(#FFFFCC);
  ellipse(300,200,50,70); //Nose Background
  fill(0);
  ellipse(290,160,10,10); //Left Eye
  ellipse(310,160,10,10); //Right Eye
  stroke(0);
  strokeWeight(3);
  triangle(300,185,295,175,305,175); //Nose
  ///Mouth///
  line(300,180,300,200);
  line(300,200,280,220);
  line(300,200,320,220);

  /////Black label/////
  fill(0);
  rect(60,210,480,100);

  ///// "JURASSIC BROWN" /////
  fill(#FFFF00);
  textSize(50);
  text("JURASSIC BROWN",75,280);
}