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

วันอาทิตย์ที่ 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);
}