2025年5月15日 星期四

12751036-徐詩淳_week13



 









// week13_1_processing__video

// Sketch - Library - Manage Libraries... 安裝video

// 教學

import processing.video.*; // Java 使用外掛的匯入

Capture video; // 有視訊鏡頭 用這個

Movie movie; // 沒有鏡頭 改用這個

void setup(){

  size(640, 960); // 常見的視訊

  // video = new Capture(this, 640, 480);

  // video.start(); // 打開視訊

  movie = new Movie(this, "street.mov"); // 讀檔案

  movie.loop();

}

void draw(){

  // if(video.available()) video.read();

  // image(video, 0, 0);

  if(movie.available()) movie.read();

  image(movie, 0, 0);

}











// week13_2_camera_movie_eye_center_up

// 電腦圖學繪圖時 會設定 camera 的相關係數

import processing.video.*;

Movie movie;

void setup(){

  size(720, 480, P3D); // 要加 P3D 才有OpenGL 3D 功能

  movie = new Movie(this, "street.mov");

  movie.loop(); // 迴圈播放

}

void draw(){

  background(128);

  camera(mouseX, mouseY, 500, 360, 240, 0, 0, 1, 0);


  if(movie.available()) movie.read(); //有新畫面就讀入

  image(movie, 0, 0);

}








// week13_3_texture_textureMode_beginShape_vertex_endShape

// 先教貼圖 再加進去

PImage img;

void setup(){

  size(400, 400, P3D); // 要加 P3D 才有OpenGL 3D 功能

  img = loadImage("chessboard.png");

  textureMode(NORMAL);

} // 先用最簡單的 NORMAL 來畫 2個三角形 不像3D透視的效果

void draw(){

  background(128); // 灰色背景

  beginShape(); // 開始畫

    texture(img); // 把圖片 當貼圖

    vertex(40, 80, 0, 0); // 4個頂點 vertex 

    vertex(320, 20, 1, 0);

    vertex(380, 360, 1, 1);

    vertex(160, 380, 0, 1);

  endShape();

}














// week13_4_camera_chessboard_texture_front_left
// 把貼圖 跟 camera 整合在一起
PImage img;
void setup(){
  size(400, 400, P3D);
  img = loadImage("chessboard.png");
  textureMode(NORMAL);
}
void draw(){
  camera(mouseX, 200, mouseY, mouseX, 200, mouseY-10, 0, 1, 0);
  background(128); // 灰色背景
  beginShape(); // 
    texture(img); 
    vertex(0, 0, 0, 0, 0); 
    vertex(400, 0, 0, 1, 0);
    vertex(400, 400, 0, 1, 1); 
    vertex(0, 400, 0, 0, 1); 
  endShape();
  beginShape(); // 
    texture(img); 
    vertex(0, 0, 0, 0, 0); 
    vertex(0, 400, 0, 1, 0);
    vertex(0, 400, 400, 1, 1); 
    vertex(0, 0, 400, 0, 1); 
  endShape();
}

















// week13_5_camera_keyPressed_keyCode_x_y_z_angle_cos_sin
// 修改自 week13_4_camera_chessboard_texture_front_left
// 利用 方向鍵(上下左右) 來移動
PImage img;
void setup(){
  size(400, 400, P3D);
  img = loadImage("chessboard.png");
  textureMode(NORMAL);
}
float x = 200, y = 200, z = 200, angle = 180; 
void keyPressed(){  // 按方向鍵
   if(keyCode==LEFT) angle--;
  if(keyCode==RIGHT) angle++;
  if(keyCode==UP){
    x += cos(radians(angle));
    z += sin(radians(angle));
  }
  if(keyCode==DOWN){
    x -= cos(radians(angle));
    z -= sin(radians(angle));
  }
}
void draw(){ // 攝影機[往前看] 左右前後移動
  if(keyPressed) keyPressed();
  // camera(mouseX, 200, mouseY, mouseX, 200, mouseY-10, 0, 1, 0);
  camera(x, y, z, x+ cos(radians(angle)), y, z+sin(radians(angle)), 0, 1, 0);
  background(128); // 灰色背景
  beginShape(); 
    texture(img); 
    vertex(0, 0, 0, 0, 0); 
    vertex(400, 0, 0, 1, 0);
    vertex(400, 400, 0, 1, 1); 
    vertex(0, 400, 0, 0, 1); 
  endShape();
  beginShape(); // 
    texture(img); 
    vertex(0, 0, 0, 0, 0); 
    vertex(0, 400, 0, 1, 0);
    vertex(0, 400, 400, 1, 1); 
    vertex(0, 0, 400, 0, 1); 
  endShape();
}





















// week13_6_combine_all_Movie_Capture_PIamge_camera_sin_cos_P3D
import processing.video.*;
Movie movie;
PImage img;
void setup(){
  size(400, 400, P3D);
  movie = new Movie(this, "street.mov");
  movie.loop(); // 循環播放
  img = loadImage("chessboard.png");
  textureMode(NORMAL);
  video = new Capture(this, 640, 480);
  video.start();
}
Capture video;
void draw(){ // 攝影機[往前看] 左右前後移動
  camera(200, 200, 200, 200+cos(radians(frameCount)), 200, 200+sin(radians(frameCount)), 0, 1, 0);
  background(128);
  if(movie.available()) movie.read();
  beginShape();  // 正前方的牆
    texture(img); 
    vertex(  0,   0, 0, 0, 0);  // x,y,z,u,v
    vertex(400,   0, 0, 1, 0);
    vertex(400, 400, 0, 1, 1); 
    vertex(  0, 400, 0, 0, 1); 
  endShape();
  translate(0, 0, 1);
  image(movie, 0, 0, 360, 240);
  if(video.available()) video.read();
  beginShape(); // 左邊的牆
    texture(video); 
    vertex(0,   0,   0, 0, 0); 
    vertex(0, 400,   0, 1, 0);
    vertex(0, 400, 400, 1, 1); 
    vertex(0,   0, 400, 0, 1); 
  endShape();
  translate(0, 0, 1);
  image(movie, 0, 0, 360, 240);
}






沒有留言:

張貼留言