วันอังคารที่ 14 ตุลาคม พ.ศ. 2557

count words 01-10[2]


void setup(){


  String s = "Welcome to Thailand";

  int count = count_words(s);

  println(count);
}

int count_words(String s){
  int count = 1;


    for(int i=0;i<s.length();i++){

      if(s.charAt(i) ==' '){
        count=count+1;

     }
  }
  return count;
}

lab3 con[1]



void setup () {
  int []K = {
    4, 8, 5
  }; //your array
  int []R = {
    0, 1, 2
  }; //array of index
  int n = 4;//number you want to know
  int a = 0;
  for (int i = 0; i<K.length; i++) {
    if (n==K[i]) {
      println(K[i]+" has index = " +R[i]+" in K") ;
      a=a+K.length;//N
    } else if (n!=K[i])
      a=a-1;
  }
  if (a<=-1) {
    println(n+" is not in K");
  }
}

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

bug report

BUG REPORT

what?
1.ใช้ switch ในการเปลี่ยนเฟรม
โดย กำหนด if(mousePressed){num=1;}
เมื่อ frame แรกมีค่า num = 0;
แล้ว เมื่อรันโปรมแกรมแล้วคลิ๊ก
frame ต่อไปที่แสดงไม่เป็นไปตามเงื่อนไขที่กำหนด

2.เมื่อนำ frame ทุก frame มารวมกันโดยใช้คำสั่ง switch
ภาพบางจุดของ frame 2 และ 3 ไม่ขยับตามคำสั่ง

why?
เนื่องจาก ฟังก์ชัน mousePressed เป็นฟังก์ชัน
ที่จะต้องมีการกด mouse ก่อน(กำหนดให้ mousePressed = true)
แต่เมื่อเรากดความเร็วในการรับค่าจากการออกแรงกดเพียง1ที
อาจมากกว่าที่เรากด mouse ทำให้ลำดับขั้นตอนของแต่ละเฟรมที่แสดงนั้น
เปลี่ยนไปอย่างรวดเร็ว จนบางครั้งดูไม่ทันว่าเฟรมนั้นๆถูกแสดงไม่หรือยัง

hot to fix?
เปลี่ยนจากการใช้เงื่อนไข
if(mousePressed){num=1;}
if(mousePressed){num=2;}
if(mousePressed){num=3;}
if(mousePressed){num=4;}
if(mousePressed){num=5;}

เป็น

void mousePressed() {
  switch(num) {
  case 0:
    num = 1;
    break;
  case 1:
    num = 2;
    break;
  case 2:
    num = 3;
    break;
  case 3:
    num = 4;
    break;
  case 4:
    num = 5;
    break;
  case 5:
    num = 0;
    break;
  }
}

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

Lab2 : income tax [return]

int income;
void setup(){
  size(200,100);
  background(255);
  fill(0);
  text("tax = "+function(500000),50,50);
  println(function(500000));
}
int function (int x){
  int income = 0;
 if (x >= 800000){ //income is greater than or equal to 800000
  income = x*25/100;
 }else if((x < 800000)&&( x >= 500000)){ //income is less than 800000 and greater than or equal to 500000
 income = x*20/100;
 }else if((x  < 500000)&&(x  >= 300000)){ //income is less than 500000 and greater than or equal to 300000
 income = x*15/100;
 }else if((x < 300000)&&(x  >= 150000)){ //income is less than 300000 and greater than or equal to 150000
income = x*10/100;
 }else{ //income is less than 150000
income =  0;
 }
  return income;
}

Lab3 : balloon


int X[] = {75,150,225};
int Y[] = {300,250,200};


void setup(){
  size(400,300);
  background(255);
  frameRate(100);
}

int i = 0;
int a = 70;
int s = 90;
void draw(){
  background(255);

  for(int i=0;i<Y.length;i++){
  balloon(X[i],Y[i],a,s);

  Y[i]=Y[i]-1;
  if  (mousePressed){Y[i] = height -(50*i) ;
 }
  }

}
void balloon(int x,int y,int a,int s){
  line(x,y+20,x,y+120);
  fill(255,0,0);
  ellipse(x,y,a,s);
  triangle(x,y+45,x+5,y+50,x-5,y+50);

}

Lab3 : turtle

 
 void setup() {

  size(400, 400);
  background(255);
  int X[] = {160,300,100};
  int Y[] = {280,100,120};
  
  for(int i=0;i<Y.length;i++){
  drawTurtle(X[i], Y[i], 40, 20, 3);
  }

}
void drawTurtle(int X, int Y, int Width, int Height,int Radius) {
  fill(255, 255, 153);
  ellipse(X, Y, Width, Height); //leg

  fill(255, 255, 153);
  rect(X+90, Y-30, Width-20, Height-10, Radius); //tail

  fill(0, 153, 0);
  ellipse(X+30, Y-30, Width+100, Height+60); //body

  fill(153, 153, 0);
  rect(X+5, Y-60, Width-20, Height, Radius+7); //shell
  rect(X+30,Y-60,Width-20,Height,Radius+7); //shell
  rect(X+55,Y-60,Width-20,Height,Radius+7); //shell

  fill(255, 255, 153);
  noStroke();
  ellipse(X-40, Y-50, Width+30, Height+60); //face
  ellipse(X-50,Y-30,Width+20,Height+20); //face

  stroke(2);
  line(X-70, Y-30, X-60, Y-30); //mouse

  fill(0);
  ellipse(X-60, Y-60, Width-25, Height-5); //eye
  fill(255);
  ellipse(X-65, Y-63, Width-35, Height-15); //eye

  fill(255, 255, 153);
  ellipse(X+20, Y, Width, Height); //leg
  ellipse(X+70,Y,Width,Height); //leg
}

Lab3 : pencil


int XR[] = {100};

int YR[] = {125};

int XT[] = {100,122,145};

int YT[] = {210,250,210};

void setup(){

  size(400,300);

  background(255);

int i = 0;

int w = 15;

int h = 90;

  drawRectPencil(XR[i],YR[i],w,h);

  drawTrianglePencil(XT[0],YT[0],XT[1],YT[1],XT[2],YT[2]); //wood

}

void drawRectPencil(int x,int y,int w,int h){

  int r = 5;

fill(255,255,0); //yellow

rect(x,y,w,h,r); //left

fill(0,255,0); //green

rect(x+15,y,w,h,r); //middle

fill(255,255,0); //yellow1

rect(x+30,y,w,h,r); //right

fill(204,204,0);//yellow2

rect(x,y-20,w+30,h-65,r-5);//eraser

fill(255,255,255);//white

rect(x,y-20,w+30,h-80,r-2);//eraser

fill(0,0,0);

rect(x+20,y+121,w-10,h-85,r-5);//lead

}

void drawTrianglePencil(int x1,int y1,int x2,int y2,int x3,int y3){

fill(255,255,255);

triangle(x1,y1,x2,y2,x3,y3);

}

Lab3 : histogram


int[] x = {0, 50, 100, 150, 200};
int[] y = {175, 100, 200, 200, 150};
void setup() {
  size(400, 300);
}
void draw() {
  background(0);
  stroke(0);
  histogram();
  fill(100, 74, 250);
  textSize(20);
  text("MAX = "+ max(y), 290, 20);
  fill(20, 255, 92);
  textSize(20);
  text("MIN = "+ min(y), 290, 40);
  fill(255);
  textSize(20);
  text("AVG = "+ avg(), 290, 60);
  move();
  stroke(255,0,0);
  line(0,height-avg(),300,height-avg());
}
void histogram() {
  for (int i = 0; i<y.length; i++) {
  
    if (y[i] == max(y)) {
      fill(100, 74, 250);
    } else if (y[i] == min(y)) {
      fill(20, 255, 92);
    } else {
      fill(255);
    }
rect(x[i], 300, 50, -y[i]);}
  
}
void move() {
  for (int i = 0; i<y.length; i++) {
    if (mousePressed&&mouseX>i*50&&mouseX<(i+1)*50) {
      y[i]=height-mouseY;
    }
  }
}

int avg(){
  int x = 0;
  for(int i = 0;i<y.length;i++) {
  x = x+(y[i]/5);
  }
return x;
}

วันจันทร์ที่ 8 กันยายน พ.ศ. 2557

Quadrant


 void setup(){
   size(300, 300);
  background(255);
  frameRate(30);
 }
  void draw(){
  strokeWeight(6);
  line(0,150,300,150);
  line(150,0,150,300);
  Quadrant();
}
void Quadrant(){
 if((mouseX>150)&&(mouseY<150)){
    println("Quadrant1");
}else if((mouseX<150)&&(mouseY<150)){
    println("Quadrant2");
}else if((mouseX<150)&&(mouseY>150)){
    println("Quadrant3");
}else {
    println("Quadrant4");
}
}

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

income tax


void setup(){
 size(200,100);
 background(255);

 float income = 500000 ;
 if (income >= 800000){ //income is greater than or equal to 800000
 println("pay for tax "+income*25/100);
 }else if((income < 800000)&&(income >= 500000)){ //income is less than 800000 and greater than or equal to 500000
 println("pay for tax "+income*20/100);
 }else if((income < 500000)&&(income >= 300000)){ //income is less than 500000 and greater than or equal to 300000
 println("pay for tax "+income*15/100);
 }else if((income < 300000)&&(income >= 150000)){ //income is less than 300000 and greater than or equal to 150000
 println("pay for tax "+income*10/100);
 }else if (income < 150000){ //income is less than 150000
 println("pay for tax "+"0");
 }
 }

calculate grade


void setup(){
 size(200,100);
 background(0);

int score = 79 ;
 char grade ;
 if (score >= 80){ //score is greater than or equal to 80
 grade = 'A' ; //show "GRADE A"
 }else if((score < 80)&&(score >= 70)){ //score is less than 80 and greater than or equal to 70
 grade = 'B' ; //show "GRADE B"
 }else if((score < 70)&&(score >= 60)){ //score is less than 70 and greater than or equal to 60
 grade = 'C' ; //show "GRADE C"
 }else if((score < 60)&&(score >= 50)){ //score is less than 60 and greater than or equal to 50
 grade = 'D' ; //show "GRADE D"
 }else{ //score is less than 50
 grade = 'F' ; //show "GRADE F"
 }
 println("GRADE "+grade); fill(255,0,10); text("GRADE "+grade,70,50);
}

Lab2 : an example showing that draw()


 void setup() {
 size(300, 250);
 background(255);
 strokeWeight(8);
 draw(155,110);
 draw(120,90);
 draw(100,70);
 draw(50,50);
 draw(155,15);
 draw(10,90);
 draw(10,10);
}
void draw(int width,int height) {
 rect(50,50,width,height);
}

Lab2 : forest


 void setup(){
 size(400, 200);
 background(64,64,64);

 //friend's tree
draw_rect(130,100,50,150) ;
draw_circle(150,90,30); // circle
draw_circle(125,110,30); // circle
draw_circle(100,100,30); // circle
draw_circle(75,90,30); // circle
draw_circle(100,80,30); // circle
draw_circle(125,70,30); // circle
draw_circle(150,60,30); // circle
draw_circle(175,70,30); // circle
draw_circle(200,80,30); // circle
draw_circle(225,90,30); // circle
draw_circle(200,100,30); // circle
draw_circle(175,110,30); // circle
}
 void draw_rect (int x, int y , int small , int longg) {
 fill(#8B4513);
 noStroke();
 rect(x+80,y,small,longg);
}
void draw_circle (int x,int y , int radius){
fill(#00FF00);
noStroke();
ellipse(x+80,y,2*radius,2*radius);

 //my tree =="
fill(#8A5C00);
draw_tree(105, 80, 165, 80, 165, 163, 105, 163); //brown tree
fill(#19A319);
noStroke();
draw_leaves(100, 90, 40, 40); //green leaves1
draw_leaves(85, 65, 40, 40); //green leaves2
draw_leaves(105, 50, 40, 40); //green leaves3
draw_leaves(153, 45, 30, 40); //green leaves4
draw_leaves(185, 75, 40, 40); //green leaves5
draw_leaves(175, 60, 40, 40); //green leaves6
draw_leaves(175, 90, 30, 40); //green leaves7
draw_leaves(140, 63, 90, 65); //green leaves8
}
void draw_tree(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
quad(x1,y1+50, x2, y2+50, x3, y3+50, x4, y4+50);
}
void draw_leaves(int x,int y,int width,int height){
ellipse(x, y+50, width, height); }

วันพุธที่ 3 กันยายน พ.ศ. 2557

Lab2 : convert celsius to fahrenheit


void setup() {
size(300,100);
background(0);
float Celsius, Fahrenheit ;
Celsius = 100;
Fahrenheit = Value(Celsius);
println(Celsius+"Celsius = "+Fahrenheit+"Fahrenheit");
fill(255,0,10);
text(Celsius+"Celsius = "+Fahrenheit+"Fahrenheit",70,50);
}
float Value(float Celsius) {
float Fahrenheit;
Fahrenheit = (Celsius*9)/5 + 32;
return Fahrenheit;
}

Lab2 : bicycle


void setup(){
  size(400,400);
  background(133,210,255);

draw_tire(100,300,100,100);
draw_spoke(55,300,145,300);
draw_lockring(95, 305);
draw_quadCLC(105,300,190,310,190,290,105,295);
draw_lineCLC(105,295,160,300);
draw_chainRings(180,300,20,20);
draw_seatTube(180, 290);
draw_CLS(100, 295);
draw_hub(270,300,10,10);
draw_frontFock(270, 300);
draw_mainFrame(253, 240);
draw_topTube(253, 230);
draw_seat(200, 245);
draw_hand(255,200,15,5,3);
}


void draw_tire(int x,int y,int width,int height){
  fill(0);
  ellipse(x,y,width,height);  // tire

  fill(133,210,255);
  ellipse(x,y,width-10,height-10);  //tire

  fill(0);
  ellipse(x+170,y,width,height);  //tire

  fill(133,210,255);
  ellipse(x+170,y,width-10,height-10);  //tire
}

void draw_spoke(int x1,int y1,int x2,int y2){

  line(x1,y1,x2,y2);  //spoke
  line(x1+45,y1-45,x2-45,y2+45);  //spoke
  line(x1+215,y1-45,x2+125,y2+45);  //spoke
  line(x1+170,y1,x2+175,y2);  //spoke
}

void draw_lockring(int x,int y){
  fill(192,192,192);
  beginShape();
  vertex(x,y);
  vertex(x+10,y);
  vertex(x+10,y-10);
  vertex(x+5,y-10);
  vertex(x,y-5);
  endShape(CLOSE);  //lockring
}

void draw_quadCLC(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){

  fill(255,255,204);
  quad(x1,y1,x2,y2,x3,y3,x4,y4);  // connecting lockring and chain rings(CLC)
}

void draw_lineCLC(int x1,int y1,int x2,int y2){

  line(x1,y1,x2,y2);  // connecting lockring and chain rings(CLC)
  line(x1+55,y1+5,x2+10,y2+5);  // connecting lockring and chain rings(CLC)
}

void draw_chainRings(int x,int y,int width,int height){
 
  fill(192,192,192);
  ellipse(x,y,width,height);  // chain rings
  fill(133,210,255);
  ellipse(x,y,width-15,height-15);  // chain rings

 
}

void draw_seatTube(int x,int y){

  fill(255,255,204);
  beginShape();
  vertex(x,y);
  vertex(x-5,y);
  vertex(x-10,y-50);
  vertex(x-5,y-50);
  endShape(CLOSE);  //seat tube
}

void draw_CLS(int x,int y){

  fill(255,255,204);
  beginShape();
  vertex(x,y);
  vertex(x+5,y);
  vertex(x+75,y-45);
  vertex(x+70,y-45);
  endShape(CLOSE);  // connecting lockring and seat post(CLS)
}

void draw_hub(int x,int y,int width,int height){

  fill(192,192,192);
  ellipse(x,y,width,height);  // hub
}

void draw_frontFock(int x,int y){

  fill(255,255,204);
  beginShape();
  vertex(x,y);
  vertex(x-15,y-30);
  vertex(x-20,y-100);
  vertex(x-15,y-100);
  vertex(x-10,y-30);
  vertex(x+5,y-5);
  endShape(CLOSE);  //front fock
}

void draw_mainFrame(int x,int y){

  fill(255,255,204);
  beginShape();
  vertex(x,y);
  vertex(x,y-5);
  vertex(x-66,y+50);
  vertex(x-63,y+55);
  endShape(CLOSE);  //main frame
}

void draw_topTube(int x,int y){

  beginShape();
  vertex(x,y);
  vertex(x,y-5);
  vertex(178, 265);
  vertex(178, 270);
  endShape(CLOSE);  //top tube
  }
 
void draw_seat(int x,int y){

  fill(153,76,0);
  beginShape();
  vertex(x,y);
  vertex(x, y-5);
  vertex(x-35,y-20);
  vertex(x-50,y-10);
  vertex(x-35,y+5);
  endShape(CLOSE);  //seat
}

void draw_hand(int x,int y,int width,int height,int radius){

  fill(102,71,0);
  rect(x,y,width,height,radius);  //hand



}

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

Lab2 : turtle


void setup(){
size(400,400);
background(255,0,0);
draw_legRight(160,280,40,20);
draw_tail(250,250,20,10,3);
draw_body(190,250,140,80);
draw_shell(155,220,20,20,10);
draw_face(120,230,70,80);
draw_eye(100,220,15,15);
draw_mouse(90,250,100,250);
draw_legLeft(180,280,40,20);
}
void draw_legRight(int OriginalX,int OriginalY,int OriginalWidth,int OriginalHeight){ fill(255,255,153);
ellipse(OriginalX,OriginalY,OriginalWidth,OriginalHeight); //leg
}
void draw_tail(int OriginalX,int OriginalY,int OriginalWidth,int OriginalHeight,int OriginalRadius){
fill(255,255,153);
rect(OriginalX,OriginalY,OriginalWidth,OriginalHeight,OriginalRadius); //tail
}
void draw_body(int OriginalX,int OriginalY,int OriginalWidth,int OriginalHeight){ fill(0,153,0);
ellipse(OriginalX,OriginalY,OriginalWidth,OriginalHeight); //body
}
void draw_shell(int OriginalX,int OriginalY,int OriginalWidth,int OriginalHeight,int OriginalRadius){
fill(153,153,0);
rect(OriginalX,OriginalY,OriginalWidth,OriginalHeight,OriginalRadius); //shell rect(OriginalX+30,OriginalY,OriginalWidth,OriginalHeight,OriginalRadius); //shell rect(OriginalX+60,OriginalY,OriginalWidth,OriginalHeight,OriginalRadius); //shell
}
void draw_face(int OriginalX,int OriginalY,int OriginalWidth,int OriginalHeight){ fill(255,255,153);
noStroke(); ellipse(OriginalX,OriginalY,OriginalWidth,OriginalHeight); //face ellipse(OriginalX-10,OriginalY+20,OriginalWidth-10,OriginalHeight-40); //face
}
void draw_mouse(int OriginalX,int OriginalY,int OriginalWidth,int OriginalHeight){ stroke(2);
line(OriginalX,OriginalY,OriginalWidth,OriginalHeight); //mouse
}
void draw_eye(int OriginalX,int OriginalY,int OriginalWidth,int OriginalHeight){
fill(0);
ellipse(OriginalX,OriginalY,OriginalWidth,OriginalHeight); //eye
fill(255);
ellipse(OriginalX-5,OriginalY-3,OriginalWidth-10,OriginalHeight-10); //eye
}
void draw_legLeft(int OriginalX,int OriginalY,int OriginalWidth,int OriginalHeight){ fill(255,255,153);
ellipse(OriginalX,OriginalY,OriginalWidth,OriginalHeight); //leg ellipse(OriginalX+50,OriginalY,OriginalWidth,OriginalHeight); //leg
}

Lab2 : pencil


void setup() {
size(300, 300);
background(#2EB82E);
draw_rectPencil(100,125,15,90,5);

draw_pencilTriangle(100,210,122,250,145,210); //wood

}
void draw_rectPencil(int x,int y,int w,int h,int r){
fill(255,255,0); //yellow
rect(x,y,w,h,r); //left
fill(0,255,0); //green
rect(x+15,y,w,h,r); //middle
fill(255,255,0); //yellow1
rect(x+30,y,w,h,r); //right
fill(204,204,0);//yellow2
rect(x,y-20,w+30,h-65,r-5);//eraser
fill(255,255,255);//white
rect(x,y-20,w+30,h-80,r-2);//eraser
fill(0,0,0);
rect(x+20,y+121,w-10,h-85,r-5);//graphite

}
void draw_pencilTriangle(int x1,int y1,int x2,int y2,int x3,int y3){
fill(255,255,255);
triangle(x1,y1,x2,y2,x3,y3);
}

Lab2 : soccer (football) field

void setup() { size(323, 200); background(#2EB82E); fill(#2EB82E); strokeWeight(3); draw_quadInField(25,20,25,180,300,180,300,20); draw_ellipseInField(162.5,100,40,40); draw_lineInField(162.5,20,162.5,180); draw_cornerField(25,180,15); } void draw_quadInField(float originalX1,float originalY1,float originalX2,float originalY2,float originalX3,float originalY3,float originalX4,float originalY4){ quad(originalX1,originalY1,originalX2,originalY2,originalX3,originalY3,originalX4,originalY4); //field quad(originalX1,originalY1+30,originalX2,originalY2-30,originalX3-230,originalY3-30,originalX4-230,originalY4+30); //penalty area (left court) quad(originalX1,originalY1+50,originalX2,originalY2-50,originalX3-250,originalY3-50,originalX4-250,originalY4+50); //penalty area (left court) quad(originalX1,originalY1+65,originalX2,originalY2-65,originalX3-285,originalY3-65,originalX4-285,originalY4+65); //goal (left court) quad(originalX1+275,originalY1+130,originalX2+275,originalY2-130,originalX3-45,originalY3-130,originalX4-45,originalY4+130); //penalty area (right court) quad(originalX1+275,originalY1+50,originalX2+275,originalY2-50,originalX3-25,originalY3-50,originalX4-25,originalY4+50); //penalty area(right court) quad(originalX1+275,originalY1+65,originalX2+275,originalY2-65,originalX3+10,originalY3-65,originalX4+10,originalY4+65); //goal (right court) } void draw_ellipseInField(float originalX1,float originalY1,float originalWidth,float originalHeight){ ellipse(originalX1,originalY1,originalWidth,originalHeight) ; //center circle } void draw_lineInField(float originalX1,float originalY1,float originalX2,float originalY2){ line(originalX1,originalY1,originalX2,originalY2); //half way line } void draw_cornerField(float originalX1,float originalY1,float originalRadius){ arc(originalX1,originalY1-160,originalRadius,originalRadius,0,PI/2); //top corner (left court) arc(originalX1,originalY1,originalRadius,originalRadius,TWO_PI-PI/2,TWO_PI); //buttom corner (left court) arc(originalX1+275,originalY1-160,originalRadius,originalRadius, PI/2,PI); //top corner (right court) arc(originalX1+275,originalY1,originalRadius,originalRadius, PI, TWO_PI-PI/2); //buttom corner (right court) }

Lab2 : spoon & fork


void setup() {
size(400, 400);
background(255,229,204);

fill(160, 160, 160);
noStroke();
draw_fork(120,155,15,80,5);
draw_spoon(220,155,40,60);
}
void draw_fork(int originalFork_x,int originalFork_y,int originalFork_width,int originalFork_height,int originalFork_radius){
rect( originalFork_x, originalFork_y, originalFork_width-5, originalFork_height+5, originalFork_radius) ; //part of fork1
rect( originalFork_x-20, originalFork_y-55, originalFork_width-5, originalFork_height-30,originalFork_radius) ; //part of fork2
rect( originalFork_x-5, originalFork_y-55, originalFork_width-5, originalFork_height-30,originalFork_radius) ; //part of fork3
rect( originalFork_x+10, originalFork_y-55, originalFork_width-5, originalFork_height-30,originalFork_radius) ; //part of fork4
rect( originalFork_x+25, originalFork_y-55, originalFork_width-5, originalFork_height-30,originalFork_radius) ; //part of fork5
rect( originalFork_x-20, originalFork_y-10, originalFork_width+40, originalFork_height-55,originalFork_radius) ; //part of fork6
}
 void draw_spoon(int originalSpoon_x,int originalSpoon_y,int originalSpoon_width,int originalSpoon_height){
 rect( originalSpoon_x, originalSpoon_y, originalSpoon_width-30, originalSpoon_height+25,5) ; //part of spoon1
ellipse( originalSpoon_x+5, originalSpoon_y-20, originalSpoon_width+10, originalSpoon_height+15) ; //part of spoon2
fill( 126, 126, 126);
ellipse( originalSpoon_x+5, originalSpoon_y-20, originalSpoon_width,originalSpoon_height) ; //part of spoon3
}

Lab2 : star


void setup() {
size(323, 200);
background(#000000);
draw_star(166);
}
void draw_star(int center_star){
noStroke ();
fill (#FFCC00);
triangle(center_star, 50, center_star, center_star-61, center_star-36, center_star-41); //triangle1
triangle(center_star, center_star-116, center_star, 105, center_star+36, center_star-41); //triangle2
triangle(center_star-46, center_star-91, center_star, center_star-61, center_star+44, center_star-91); //triangle3
}

Lab2 : hope & dream


void setup() {
size(323, 200);
background(#FFFFFF);

fill(#333333);
draw_bodyCamera(78, 108, 98, 60); //gray body
fill(#6699FF);
draw_bodyCamera(78, 108, 98,20); //blue body
fill(#000000);
draw_bodyCamera(109, 128, 35, 40); // black body
fill(#6699FF);
draw_flashCameraRect(112.5, 104.5, 28, 28); //blue flash
fill(#000000);
draw_flashCameraRect(116.5, 107.5, 20, 20); //black flash
fill(#FFFFFF);
draw_flashCameraCircle(127.5, 118, 13, 13); //flash fill(#999999);
draw_camera(127.5, 150, 25, 25); //gray camera2
fill(#999999);
draw_camera(127.5, 150, 15, 15); //gray camera1
fill(#000000);
draw_cameraButton(77, 104.5, 15, 10); //button
fill(#000000);
draw_cameraCoverCircle(55, 165, 25, 5); //camera cover
fill(#333333);
draw_cameraCoverRect(42, 165, 25, 5); //camera cover
fill(#CC33FF);
rect(185, 65, 35, 40); //photo purple
fill(#FF99FF); rect(233, 75, 35, 40); //photo pink
fill(#FFCC99); rect(203, 105, 35, 40); //photo cream
}
void draw_bodyCamera(int x,int y,int width,int height){
rect(x,y,width,height);
}
void draw_flashCameraRect(float x,float y,int width,int height){
rect(x,y,width,height);
}
void draw_flashCameraCircle(float x,int y,int width,int height){
ellipse(x,y,width,height);
}
void draw_camera(float x,int y,int width,int height){
ellipse(x,y,width,height);
}
void draw_cameraButton(int x,float y,int width,int height){
rect(x,y,width,height);
}
void draw_cameraCoverCircle(int x,int y,int width,int height){
ellipse(x,y,width,height);
}
void draw_cameraCoverRect(int x,int y,int width,int height){
rect(x,y,width,height);
}

Lab2 : favorite a subject/topic


void setup() {
size(323, 200);
background(#E2FFAA);

strokeWeight(2);
stroke(#E69C53);
fill(#FFAD5C);
draw_cone(110, 115, 138, 180, 166, 115);

fill(#24248F); 
draw_brand(153, 145, 122, 145, 130, 163, 146, 163);

strokeWeight(2);
stroke(#E69C53);
fill(#FFAD5C);
draw_circle(138, 115, 55, 25);

strokeWeight(2);
stroke(#FFBFBF);
 fill(#FFB8B8);
draw_circle(138, 105, 50, 50); //ice-cream

strokeWeight(2);
stroke(#FFBFBF);
 fill(#FF0000);
draw_circle(138, 80, 20, 20); //cherry
}
void draw_cone(int x1,int y1,int x2,int y2,int x3,int y3){
 triangle(x1, y1, x2, y2, x3, y3);
}
void draw_brand(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
quad(x1, y1, x2, y2, x3, y3, x4, y4);
}
void draw_circle(int x,int y,int width,int height){
ellipse(x, y, width, height);
}

Lab2 : tree


void setup() {
size (323,200);
background(255);
fill(#000000);
draw_tree(188, 131, 78, 131, 102, 125, 164, 125); //black soil
fill(#8A5C00);
draw_tree(105, 80, 165, 80, 165, 163, 105, 163); //brown tree
fill(#A3C2C2);
draw_tree(188, 131, 78, 131, 102, 173, 164, 173); //blue pots
fill(#19A319);
noStroke();
draw_leaves(100, 90, 40, 40); //green leaves1
draw_leaves(85, 65, 40, 40); //green leaves2
draw_leaves(105, 50, 40, 40); //green leaves3
draw_leaves(153, 45, 30, 40); //green leaves4
draw_leaves(185, 75, 40, 40); //green leaves5
draw_leaves(175, 60, 40, 40); //green leaves6
draw_leaves(175, 90, 30, 40); //green leaves7
draw_leaves(140, 63, 90, 65); //green leaves8
}
void draw_tree(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
quad(x1,y1, x2, y2, x3, y3, x4, y4);
}
void draw_leaves(int x,int y,int width,int height){ ellipse(x, y, width, height);
}

วันพุธที่ 27 สิงหาคม พ.ศ. 2557

star anime


void setup() {
size(323, 200);
background(200,0,0);

frameRate(200);

}

float y = 100;

void draw()

{

background(0);   // Set the background to black

  y = y - 1;

  if (y < -166) { y = width; }


    int center_star = 166 ;

    noStroke ();
    fill  (#FFCC00);

    triangle(center_star+y, 50, center_star+y, center_star-61, center_star-36+y, center_star-41); //triangle1
    triangle(center_star+y, center_star-116, center_star+y, 105, center_star+36+y, center_star-41); //triangle2
    triangle(center_star-46+y, center_star-91, center_star+y, center_star-61, center_star+44+y, center_star-91);  //triangle3


}

วันอังคารที่ 26 สิงหาคม พ.ศ. 2557

Lab1 : Convert pounds into kilograms


{ void setup() {
float pounds = 100;
 float kilograms = 0;
 kilograms = (pounds/2.2046);
 println(kilograms);
 }

Lab1 : Convert Celsius to Fahrenheit



void setup() {
 float Celsius = 100;
 float Fahrenheit = 0;
 Fahrenheit = (Celsius*9)/5 + 32;
 println(Fahrenheit);
 }

Lab1 : Compute the volume of a cylinder


 void setup() {
 float height = 100;
 float radius = 20 ;
 float volume = 0;
 float Pi = 3.1415 ;
 volume = (Pi*radius*radius*height);
 println(volume);
 }

Lab1 : Convert feet into meters


void setup() {
 float feet = 10;
 float meters = 0;
 meters = feet*0.3048;
 println(meters); }

วันเสาร์ที่ 23 สิงหาคม พ.ศ. 2557

Lab1 : draw a football (soccer) field


    void setup() {
    size(323, 200);
    background(#2EB82E);
  
    fill(#2EB82E);
  strokeWeight(3);
    int center_filedX = 162.5 ;
    int center_filedY = 100 ;
    int radius_center_circle = 40
  
    quad(center_filedX-137.5,center_filedY-80,center_filedX-137.5,center_filedY+80,center_filedX+137.5,center_filedY+80,
center_filedX+137.5,center_filedY-80) ; //field
    ellipse(center_filedX,center_filedY,radius_center_circle,
radius_center_circle) ; //center circle
    line(center_filedX,center_filedY-80,center_filedX,center_filedY+80) ;  //half way line
 
    //left court
    int corner_filedX = 25 ;
    int corner_filedY = 50 ;
  
    quad(corner_filedX,corner_filedY,corner_filedX,
corner_filedY+100,corner_filedX+45,corner_filedY+100,
corner_filedX+45,corner_filedY) ;  //penalty area
    quad(corner_filedX,corner_filedY+20,corner_filedX,
corner_filedY+80,corner_filedX+25,corner_filedY+80,
corner_filedX+25,corner_filedY+20) ;  //penalty area
    quad(corner_filedX,corner_filedY+35,corner_filedX,
corner_filedY+65,corner_filedX-10,corner_filedY+65,corner_filedX-10,corner_filedY+35) ;  //goal
    arc(corner_filedX, corner_filedY-30, corner_filedX-10,
corner_filedY-35, 0, PI/2) ; //top corner
    arc(corner_filedX, corner_filedY+130, corner_filedX-10, corner_filedY-35, TWO_PI-PI/2, TWO_PI
) ; //buttom corner
    arc(corner_filedX+48,corner_filedY+50,corner_filedX-5,corner_filedY, -PI/2,PI/2);
  
    //right court
    int corner_filedX = 300 ;
    int corner_filedY = 50 ;
  
    quad(corner_filedX,corner_filedY+100,corner_filedX,corner_filedY,
corner_filedX-45,corner_filedY,corner_filedX-45,corner_filedY+100) ; //penalty area
    quad(corner_filedX,corner_filedY+20,corner_filedX,
corner_filedY+80,corner_filedX-25,corner_filedY+80,corner_filedX-25,corner_filedY+20) ;  //penalty area
    quad(corner_filedX,corner_filedY+35,corner_filedX,corner_filedY+65,
corner_filedX+10,corner_filedY+65,corner_filedX+10,corner_filedY+35) ;  //goal
    arc(corner_filedX, corner_filedY-30, corner_filedX-285,corner_filedY-35, PI/2,PI) ; //top corner
    arc(corner_filedX, corner_filedY+130, corner_filedX-285, corner_filedY-35, PI, TWO_PI-PI/2) ; //buttom corner
    arc(corner_filedX-47,corner_filedY+50,corner_filedX-280,corner_filedY
, PI/2,TWO_PI-PI/2);
  
  
  
   }

Lab1 : draw spoon and fork


 void setup() {
size(400, 400);
background(255,229,204);

int fork1_X = 120 ;
int fork1_Y = 155 ;
int fork_width = 10 ;
int fork_height = 50 ;
int fork_radius = 5 ;

fill(160, 160, 160);
noStroke();
rect( fork1_X, fork1_Y, fork_width+5, fork_height+30, fork_radius) ; //part of fork1
rect( fork1_X-20, fork1_Y-55, fork_width, fork_height) ; //part of fork2
rect( fork1_X-5, fork1_Y-55, fork_width, fork_height) ; //part of fork3
rect( fork1_X+10, fork1_Y-55, fork_width, fork_height) ; //part of fork4
rect( fork1_X+25, fork1_Y-55, fork_width, fork_height) ; //part of fork5
rect( fork1_X-20, fork1_Y-10, fork_width+45, fork_height-25, fork_radius) ; //part of fork6

int spoon1_X = 220 ;
 int spoon1_Y = 155 ;
int width_spoon = 40 ;
int height_spoon = 60 ;

rect( spoon1_X, spoon1_Y, spoon1_Y-140, 2*width_spoon, height_spoon-55) ; //part of spoon1
ellipse( spoon1_X+5, spoon1_Y-20, width_spoon+10, height_spoon+15) ; //part of spoon2
fill( 126, 126, 126);
ellipse( spoon1_X+5, spoon1_Y-20, width_spoon, height_spoon) ; //part of spoon3
}

Lab1 : star


void setup() {
size(400, 400);
background(#000000);

int top_point_starX = 166 ;
int top_point_starY = 50 ;
int circle_smallX = 300 ;
int circle_smallY = 450 ;
int circle_radius = 250 ;

noStroke() ;
fill(206,206,206);
triangle( top_point_starX, top_point_starY-20, top_point_starX, top_point_starY+75, top_point_starX-56, top_point_starY+95) ; //part1 of star1
triangle( top_point_starX, top_point_starY-20, top_point_starX, top_point_starY+75, top_point_starX+56, top_point_starY+95) ; //part2 of star1
triangle( top_point_starX-66, top_point_starY+18, top_point_starX, top_point_starY+75, top_point_starX+64, top_point_starY+18) ; //part3 of star1

fill(206,116,229);
triangle( top_point_starX, top_point_starY-10, top_point_starX, top_point_starY+65, top_point_starX-46, top_point_starY+85) ; //part1 of star2
triangle( top_point_starX, top_point_starY-10, top_point_starX, top_point_starY+65, top_point_starX+46, top_point_starY+85) ; //part2 of star2
triangle( top_point_starX-56, top_point_starY+21, top_point_starX, top_point_starY+65, top_point_starX+54, top_point_starY+21) ; //part3 of star2

fill(255); triangle( top_point_starX, top_point_starY, top_point_starX, top_point_starY+55, top_point_starX-36, top_point_starY+75) ; //part1 of star3
triangle( top_point_starX, top_point_starY, top_point_starX, top_point_starY+55, top_point_starX+36, top_point_starY+75) ; //part2 of star3
triangle( top_point_starX-46, top_point_starY+25, top_point_starX, top_point_starY+55, top_point_starX+44, top_point_starY+25) ; //part3 of star3

fill(255,0,0);
ellipse(circle_smallX,circle_smallY,circle_radius+150,circle_radius+150) ; //circle red

fill(255,255,0);
ellipse(circle_smallX,circle_smallY,circle_radius+100,circle_radius+100) ; //circle yellow

fill(0,153,76);
ellipse(circle_smallX,circle_smallY,circle_radius+50,circle_radius+50) ; // circle green

fill(0,0,102);
ellipse(circle_smallX,circle_smallY,circle_radius,circle_radius) ; //circle blue

fill(51,0,102); ellipse(circle_smallX,circle_smallY,circle_radius-50,circle_radius-50) ; //circle dark blue

fill(102,0,102);
ellipse(circle_smallX,circle_smallY,circle_radius-100,circle_radius-100) ; //circle purple
}

Lab1 : my hope and dream


void setup() {
size(323, 200);
background(#FFFFFF);

int pointRightX_body = 176 ;
int pointTopY_body = 127 ;
float centerX_flash = 127.5 ;
int centerY_flash = 118 ;
int size_partCamera = 20 ;

fill(#333333);
quad(pointRightX_body, pointTopY_body, pointRightX_body-98, pointTopY_body, pointRightX_body-98, pointTopY_body+42, pointRightX_body, pointTopY_body+42); //gray body

fill(#6699FF);
quad(pointRightX_body, pointTopY_body, pointRightX_body-98, pointTopY_body, pointRightX_body-98, pointTopY_body-19, pointRightX_body, pointTopY_body-19); //blue body

fill(#000000);
rect(pointRightX_body-67, pointTopY_body+1, pointRightX_body-141, pointTopY_body-87); // black body

fill(#6699FF);
rect(pointRightX_body-63.5, pointTopY_body-22.5, size_partCamera+8, size_partCamera+8); //blue flash

fill(#000000);
rect(pointRightX_body-59.5, pointTopY_body-18.5, size_partCamera, size_partCamera); //black flash

fill(#FFFFFF);
ellipse(centerX_flash, centerY_flash, size_partCamera-7, size_partCamera-7); //flash

fill(#999999);
ellipse(centerX_flash, centerY_flash+32, size_partCamera+5, size_partCamera+5); //gray camera2

fill(#999999);
ellipse(centerX_flash, centerY_flash+32, size_partCamera-5, size_partCamera-5); //gray camera1

fill(#000000);
rect(pointRightX_body-99, pointTopY_body-22.5, size_partCamera-5, size_partCamera-10); //button

fill(#000000);
ellipse(centerX_flash-72.5, centerY_flash+47, size_partCamera+5, size_partCamera-15); //camera cover

fill(#333333);
rect(pointRightX_body-134, pointTopY_body+38, size_partCamera+5, size_partCamera-15); //camera cover

int photo_purpleX = 185 ;
int photo_purpleY = 65 ;
int photo_width = 35 ;
int photo_height = 40 ;

fill(#CC33FF);
rect(photo_purpleX, photo_purpleY, photo_width, photo_height); //photo purple

fill(#FF99FF);
rect(photo_purpleX+48, photo_purpleY+10, photo_width, photo_height); //photo pink

fill(#FFCC99);
rect(photo_purpleX+18, photo_purpleY+40, photo_width, photo_height); //photo cream
}