วันจันทร์ที่ 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);
}