2025年5月15日 星期四

12750653-week13

 import processing.video.*;

//week13-1
//java使用外掛的匯入
//Capture video;//有視訊鏡頭的用這格版本
Movie movie;//沒有鏡頭用這個版本
void setup(){
  size(640,480);
  //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-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
//再把貼圖加進去
PImage img;
void setup(){
  size(400,400,P3D);
  img=loadImage("chessboard.png");
  textureMode(NORMAL);
}
void draw(){
  background(128);//灰背景
  beginShape();//開始畫
  texture(img);//把圖片當貼圖
  vertex(40,80,0,0);//4個頂點vertex的四邊形 會裁出2個三絞刑
  vertex(320,20,1,0);
  vertex(380,360,1,1);
  vertex(160,380,0,1);
  endShape();
}

//week13-4
//把貼圖、跟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);
  
  //正前方Z座標對放0
  beginShape();
  texture(img);
  vertex(0,0,0,0);
  vertex(400,0,0,1,0);
  vertex(400,400,0,1,1);
  vertex(0,400,0,0,1);
  endShape();
  
  //左方,X座標對放0
  beginShape();
  texture(img);
  vertex(0,0,0,0);
  vertex(0,400,0,0,1);
  vertex(0,400,400,1,1);
  vertex(0,0,400,1,0);
  endShape();
}
//week13-5
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(x,y,z,x+cos(radians(angle)),y,z+sin(radians(angle)),0,1,0);
  //camera(mouseX,200,mouseY,mouseX,200,mouseY-10,0,1,0);
  background(128);
  
  beginShape(); //正前方Z座標對放0
  texture(img);
  vertex(0,0,0,0);
  vertex(400,0,0,1,0);
  vertex(400,400,0,1,1);
  vertex(0,400,0,0,1);
  endShape();
  beginShape(); //左方,X座標對放0
  texture(img);
  vertex(0,0,0,0);
  vertex(0,400,0,0,1);
  vertex(0,400,400,1,1);
  vertex(0,0,400,1,0);
  endShape();
}

//week13-6
import processing.video.*; // 要使用 Movie 需要匯入 video 函式庫
Movie movie;
PImage img;
void setup(){
  size(400, 400, P3D);
  movie = new Movie(this, "street.mov");// 影片檔案,解析度為 720x480
  movie.loop();//循環播放
  img = loadImage("chessboard.png");
  textureMode(NORMAL);
}
void draw(){
  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();
  image(movie, 0, 0, 360, 240);
}

import processing.video.*; PImage img; Movie movie; void setup(){ size(400, 400, P3D); movie = new Movie(this, "street.mov"); // 720x480 movie.loop(); // 記得要把視訊「循環播放」 img = loadImage("chessboard.png"); textureMode(NORMAL); video = new Capture(this, 640, 480); // 建立攝影機物件 video.start(); // 要記得「開始播放」 } 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); vertex(400, 0, 0, 1, 0); vertex(400, 400, 0, 1, 1); vertex(0, 400, 0, 0, 1); endShape(); image(movie, 0, 0, 360, 240); if (video.available()) { video.read(); } beginShape(); texture(video); // 使用攝影機畫面作為貼圖 vertex(0, 0, 0, 0, 0); vertex(0, 400, 0, 0, 1); vertex(0, 400, 400, 1, 1); vertex(0, 0, 400, 1, 0); endShape(); }









沒有留言:

張貼留言