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

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

Lab 2 - Digital Clock


void draw() {
  int s1 = second();  // Values from 0 - 59
  int m1 = minute();  // Values from 0 - 59
  int h1 = hour();    // Values from 0 - 23
  int d2 = day();    // Values from 1 - 31
  int m2 = month();  // Values from 1 - 12
  int y2 = year();   // 2003, 2004, 2005, etc.

  size(500, 200);
  background(0);
// Background Clock
  fill(#083100);
  stroke(#27AA03);
  rect(65, 55, 360, 70);


  PFont font;
  font = loadFont("DS-Digital-Bold-80.vlw");
  // Time
  fill(#27AA03);
  textFont(font, 90);
  text(h1, 70, 120); // Hour
  text(":", 170, 115);
  text(m1, 200, 120); // Minute
  text(":", 300, 115);
  text(s1, 330, 120); // Second

  // Date
  fill(#FCE000);
  textFont(font, 40);
  text(d2, 160, 40); // Day
  text("/", 200, 40);
  text(m2, 220, 40); // Month
  text("/", 260, 40);
  text(y2, 280, 40); // Year}

Syntax Error



** เมื่อนำการกำหนดค้าตัวแปรไปเป็น Global จะไม่สามารถทำให้นาฬิกาขยับได้
จึงต้องนำมาไว้ที่ void draw()


Lab 2 - Battery Duplicate (Function)


void setup() {
  size(700, 600);
  background (0);
  draw_battery(100, 100, #25D100);
  draw_battery(400, 100, #FF0000);
}

void draw_battery(int AxisX, int AxisY, color colour) {
  int sizeX = 200;
  int sizeY = 410;
  int angle = 15;

  //Outside 1st battery
  fill(100);
  stroke(100);
  strokeWeight(5);
  rect(AxisX+60, AxisY-20, sizeX-120, 40, angle-5);

  //inside 1st battery
  fill(colour);
  rect(AxisX, AxisY, sizeX, sizeY, angle);
}

Lab 2 - Battery Move

int AxisX=0;

void setup() {
  size(700, 600);
  frameRate(10);
}

void draw() {
  background (0);
  draw_battery(AxisX, 100);
  AxisX=(AxisX+10)%width;
}

void draw_battery(int AxisX, int AxisY) {
  // int value of battery
  int sizeXin = 180;
  int sizeYin = 70;
  int angle = 10;

  // Symbols
  fill(255);
  noStroke();
  rect(AxisX+70, AxisY-70, 60, 20, angle-5);
  rect(AxisX+90, AxisY-90, 20, 60, angle-5);

  rect(AxisX+70, AxisY+450, 60, 20, angle-5);

  // Outside 1st battery
  fill(100);
  stroke(100);
  strokeWeight(5);
  rect(AxisX+60, AxisY-20, 80, 40, angle-5);

  // inside 1st battery
  fill(0);
  rect(AxisX, AxisY, 200, 410, angle);

  fill(#4BFF00);
  strokeWeight(0);
  rect(AxisX+10, AxisY+10, sizeXin, sizeYin, angle);
  fill(#B6FF00);
  rect(AxisX+10, AxisY+90, sizeXin, sizeYin, angle);
  fill(#FAFF00);
  rect(AxisX+10, AxisY+170, sizeXin, sizeYin, angle);
  fill(#FFC400);
  rect(AxisX+10, AxisY+250, sizeXin, sizeYin, angle);
  fill(#FF3300);
  rect(AxisX+10, AxisY+330, sizeXin, sizeYin, angle);
}

Lab 2 - BMI Calculator (Function)

void setup() {
  println(cal_BMI(62, 176));
  println(cal_BMI(44, 152));
  println(cal_BMI(50, 165));
}

// Function
double cal_BMI(int kilo, int cen) {
  double cal_BMI;
  cal_BMI=kilo/((cen*cen)*1e-4);
  return cal_BMI;
}

Lab 2 - Circle Calculator (Function)


void setup() {
  println(area_cir(20));
  println(area_cir(200));
  println(area_cir(2000));
}

// Function
  float area_cir(int diameter){
    float area_cir;
    area_cir = PI*(diameter/2)*(diameter/2);
    return area_cir;
}

Lab 2 - Positive Move and Resize (Function)

int AxisX=0;
int AxisY=0;
int resize=10;
void setup() {
  size(400, 400);
  frameRate(30);
}

void draw() {
  background(255);
  draw_plus(AxisX, AxisY,resize, #007DFF);
  AxisX=(AxisX+1)%width;
  AxisY=(AxisY+1)%height;
  resize=(resize+1)%width;
}

void draw_plus(int AxisX, int AxisY,int resize , color colour) {


  // Rectangular Vertical+Herizontal
  noStroke();
  fill(colour);
  rect(AxisX, AxisY+50, resize, resize/2);
  rect(AxisX+50, AxisY, resize/2, resize);
}

Lab 2 - Book MousePress

int value = 0;

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

}
void draw() {
  //Center Alphabet
  fill(0,value,0);
  stroke(0,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,0);
  stroke(value,0,0);
  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,0,value);
  stroke(0,0,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 2 - Movie MouseMove

int colour = 0;

void setup(){
size(1000,700);
}

void draw() {
// BMW
background(colour);
fill(0);
stroke(100);
strokeWeight(10);
ellipse(250,250,400,400);

fill(255);
stroke(100);
strokeWeight(5);
ellipse(250,250,250,250);

fill(#2E9AFE);
stroke(100);
arc(250,250,250,250,0,PI/2);
arc(250,250,250,250,PI,TWO_PI-PI/2);

line(125,250,375,250);
line(250,125,250,375);


// Benz
fill(0);
stroke(255);
strokeWeight(15);
ellipse(700,250,400,400);

fill(255);
stroke(255);
strokeWeight(15);
triangle(700,50,690,250,710,250);
triangle(540,370,690,250,700,270);
triangle(860,370,690,260,710,250);

//text
fill(#FFC903);
textSize(50);
text("THE TRANSPORTER",250,650);

//Console
println("This Project is German Car Brands");
println("Left is Bavarian Motor Works");
println("Right is Mercedes Benz");
}
void mouseMoved() {
  colour = colour + 5;
  if (colour > 255) {
    colour = 0;
  }
}

Lab 2 - Music

int axisX = 0;

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

void draw() {
  background(255);
  draw_music(axisX, 0);
  axisX = (axisX+10)%width;
}
void draw_music(int axisX, int axisY ) {
  fill(#FA3030);
  stroke(#FA3030);
  ellipse(axisX+150, axisY+300, 400, 400);
  quad(axisX+150, axisY+250, axisX+150, axisY+100, axisX+550, axisY+100, axisX+470, axisY+250);

  fill(#FA309F);
  stroke(#FA309F);
  ellipse(axisX+180, axisY+290, 600, 300);

  fill(#FFFFFF);
  PFont font;
  font = loadFont("SegoeUI-BoldItalic-200.vlw");
  textFont(font, 150);
  text("vevo", axisX+120, axisY+210);

  fill(#000000);
  PFont font2;
  font2 = loadFont("dY-Jidrid-48.vlw");
  textFont(font2, 60);
  text("Savage Garden", axisX+120, axisY+75);
}

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

Lab 1 - BMI Calculate

void setup() {

  float tallcm = 176;
  double tallm = tallcm*1e-2;
  float mass = 62;
  double bmi = mass/(tallm*tallm);
 
 
  //Centimeters
  print("Your Height is "+ tallcm);
  println(" Centimeters");
 
  //Kilograms
  print("Your Weight is "+ mass);
  println(" Kilograms");
 
  //BMI
  print("Your BMI is "+ bmi);
 
}

Lab 1 - Circle Calculate

void setup() {
  size (500, 500);
  background(0);

  // Value of radius
  float radius=15;

  // Area of Circle
  float area=PI*radius*radius;

  // Circumference
  float circ=2*PI*radius;

  // Console Viewer
  println("Radius is "+ radius);
  println("Area of circle is "+ area);
  println("Circumference of circle is "+ circ);

  //  Image
  fill(0);
  stroke(255);
  ellipse(250, 250, radius*20, radius*20);

  // Text Image Area
  fill(255, 0, 0);
  textAlign(CENTER);
  textSize(5+radius);
  text("Area of circle is "+ area, 250, 250);

  // Text Image Circumference
  fill(0, 0, 255);
  textAlign(CENTER);
  textSize(5+radius);
  text("Circumference of circle is "+ area, 250, 20);

  // Text Image Radius
  fill(0, 255, 0);
  textAlign(CENTER);
  textSize(5+radius);
  text("Radius of circle is "+ radius, 250, 480);
}

Lab 1 - Cross Sign (Faroe Islands)

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

  int sized=40;
  int position=20;


  //Rectangular Vertical+Herizontal
  noStroke();
  fill(0, 0, 100);
  rect(160, 0, 100, 400);
  rect(0, 150, 600, 100);


  noStroke();
  fill(255, 0, 0);
  rect(160+position, 0, 100-sized, 400);
  rect(0, 150+position, 600, 100-sized);

  println("Faroe Islands's Flag; part of Denmark");
}

Lab 1 - Battery

void setup() {
  size(700, 600);
  background (0);
  // int value of battery
  int AxisX = 300;
  int AxisXin = 10;
  int sizeX = 20;

  //Outside 1st battery
  fill(100);
  stroke(100);
  strokeWeight(5);
  rect(160, 80, 80, 40, 5);

  //inside 1st battery
  fill(0);
  rect(100, 100, 200, 410, 15);

  fill(#4BFF00);
  strokeWeight(0);
  rect(100+ AxisXin, 110, 200-sizeX, 70, 10);
  fill(#B6FF00);
  rect(100+ AxisXin, 190, 200-sizeX, 70, 10);
  fill(#FAFF00);
  rect(100+ AxisXin, 270, 200-sizeX, 70, 10);
  fill(#FFC400);
  rect(100+ AxisXin, 350, 200-sizeX, 70, 10);
  fill(#FF3300);
  rect(100+ AxisXin, 430, 200-sizeX, 70, 10);

  //Outside 2nd battery
  fill(100);
  stroke(100);
  strokeWeight(5);
  rect(160+AxisX, 80, 80, 40, 5);

  //inside 2nd battery
  fill(0);
  rect(100+AxisX, 100, 200, 410, 15);

  fill(#00D7FF);
  strokeWeight(0);
  rect(100+ AxisXin+ AxisX, 110, 200-sizeX, 70, 10);
  fill(#009BFF);
  rect(100+ AxisXin+ AxisX, 190, 200-sizeX, 70, 10);
  fill(#9C00FF);
  rect(100+ AxisXin+ AxisX, 270, 200-sizeX, 70, 10);
  fill(#FF00C8);
  rect(100+ AxisXin+ AxisX, 350, 200-sizeX, 70, 10);
  fill(#FF0015);
  rect(100+ AxisXin+ AxisX, 430, 200-sizeX, 70, 10);
}

Lab 1 - Movie Resize and Rearrange

void setup(){
  size(1000, 700);
  background(0);

  int AxisX = 20;
  int AxisY = 30;
  int sized = 20;

  // BMW
  fill(0);
  stroke(100);
  strokeWeight(10);
  ellipse(250, 250+ AxisY, 400, 400);

  fill(255);
  stroke(100);
  strokeWeight(5);
  ellipse(250, 250+ AxisY, 250, 250);

  fill(#2E9AFE);
  stroke(100);
  arc(250, 250+ AxisY, 250, 250, 0, PI/2);
  arc(250, 250+ AxisY, 250, 250, PI, TWO_PI-PI/2);

  line(125, 250+ AxisY, 375, 250+ AxisY);
  line(250, 125+ AxisY, 250, 375+ AxisY);


  // Benz
  fill(0);
  stroke(255);
  strokeWeight(15);
  ellipse(700, 250+ AxisY, 400, 400);

  fill(255);
  stroke(255);
  strokeWeight(15);
  triangle(700, 50+ AxisY, 690, 250+ AxisY, 710, 250+ AxisY);
  triangle(540, 370+ AxisY, 690, 250+ AxisY, 700, 270+ AxisY);
  triangle(860, 370+ AxisY, 690, 260+ AxisY, 710, 250+ AxisY);

  //text
  fill(#FFC903);
  textSize(50-sized);
  text("THE TRANSPORTER", 250+AxisX+AxisX, 650-AxisY-AxisY);

  //Console
  println("This Project is German Car Brands");
  println("Left is Bavarian Motor Works");
  println("Right is Mercedes Benz");
}

Lab 1 - Book Rearrange

void setup() {
  size (800, 600);
  background(#FFEA00);

  int AxisX=20;
  int AxisY=40;

  //Center Alphabet

  fill(#E50000);
  stroke(#E50000);
  rect(360+ AxisX, 200+ AxisY, 80, 160);
  rect(310+ AxisX, 240+ AxisY, 180, 80);
  quad(280+ AxisX, 440+ AxisY, 310+ AxisX, 360+ AxisY, 360+ AxisX, 360+ AxisY, 360+ AxisX, 440+ AxisY);
  arc (360+ AxisX, 360+ AxisY, 160, 160, 0, HALF_PI);

  //Left Alphabet

  fill(#E50000);
  stroke(#E50000);
  ellipse(580+ AxisX, 280+AxisY, 160, 160);
  rect(660+ AxisX, 240+ AxisY, 80, 120);
  quad(500+ AxisX, 440+ AxisY, 530+ AxisX, 360+ AxisY, 660+ AxisX, 360+ AxisY, 660+ AxisX, 440+ AxisY);
  arc (660+ AxisX, 360+ AxisY, 160, 160, 0, HALF_PI);

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

  // Text
  textSize(40);
  text("Detective Conan", 30+ AxisX, 220+ AxisY);
}

Lab 1 - Music Resize

void setup(){
size(600,250);
background(255);

  int AxisX = 20;
  int AxisY = 20;
  int sizeC = 10;

// Background Red Circle
  fill(#FA3030);
  stroke(#FA3030);
  ellipse(150+AxisX,300+AxisY,400+sizeC,400+sizeC);

// Background Red Quad
quad(150+AxisX,250+AxisY,150+AxisX,100+AxisY,550+AxisX,100+AxisY,470+AxisX,250+AxisY);

// Background Pink Circle
  fill(#FA309F);
  stroke(#FA309F);
  ellipse(180+AxisX,290+AxisY,600+sizeC,300+sizeC);


// Text  VEVO
   fill(#FFFFFF);
  PFont font;
  font = loadFont("SegoeUI-BoldItalic-200.vlw");
  textFont(font,150);
  text("vevo",120+AxisX,210+AxisY);


// Text Savage Garden
   fill(#000000);
  PFont font2;
  font2 = loadFont("dY-Jidrid-48.vlw");
  textFont(font2,60);
  text("Savage Garden",120+AxisX,75+AxisY);
}


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

Lab 0 - Movie

void setup(){
size(1000,700);
background(0);

// BMW
fill(0);
stroke(100);
strokeWeight(10);
ellipse(250,250,400,400);

fill(255);
stroke(100);
strokeWeight(5);
ellipse(250,250,250,250);

fill(#2E9AFE);
stroke(100);
arc(250,250,250,250,0,PI/2);
arc(250,250,250,250,PI,TWO_PI-PI/2);

line(125,250,375,250);
line(250,125,250,375);


// Benz
fill(0);
stroke(255);
strokeWeight(15);
ellipse(700,250,400,400);

fill(255);
stroke(255);
strokeWeight(15);
triangle(700,50,690,250,710,250);
triangle(540,370,690,250,700,270);
triangle(860,370,690,260,710,250);

//text
fill(#FFC903);
textSize(50);
text("THE TRANSPORTER",250,650);

//Console
println("This Project is German Car Brands");
println("Left is Bavarian Motor Works");
println("Right is Mercedes Benz");


}

Lab 0 - Music


void setup(){
size(600,250);
background(255);
  
  fill(#FA3030);
  stroke(#FA3030);
  ellipse(150,300,400,400);
  quad(150,250,150,100,550,100,470,250);
  
  fill(#FA309F);
  stroke(#FA309F);
  ellipse(180,290,600,300);
  
   fill(#FFFFFF);
  PFont font;
  font = loadFont("SegoeUI-BoldItalic-200.vlw");
  textFont(font,150);
  text("vevo",120,210);
  
   fill(#000000);
  PFont font2;
  font2 = loadFont("dY-Jidrid-48.vlw");
  textFont(font2,60);
  text("Savage Garden",120,75);
  


  
}

Lab 0 - Book

void setup(){
size (800,600);
background(#FFEA00);

//Center Alphabet

fill(#E50000);
stroke(#E50000);
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(#E50000);
stroke(#E50000);
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(#E50000);
stroke(#E50000);
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);


}