2025年5月15日 星期四

week13

 

//week13-1

//sketch-library-Manage Libaries...安裝video

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

//有視訊鏡頭的

Capture video;

Movie movie;//沒鏡頭

void setup(){

  size(640,480);

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

  video.start();//開視訊

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

  //movie.loop();

}

void draw(){

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

   image(video,0,0);

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

   //image(movie,0,0);

}  

//week13-1
//sketch-library-Manage Libaries...安裝video
import processing.video.*;//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的相關係數
import processing.video.*;
Movie movie;
void setup(){
   size(600,400,P3D);
   movie=new Movie(this,"street.mov");
   movie.loop();//迴圈播放
}
void draw(){
  background(128);
  camera(mouseX,mouseY,120,300,200,0,0,1,0);
  if(movie.available())movie.read();
  image(movie,0,0);
}

//week13-2
//電腦圖學會圖時,會設定camera的相關係數
import processing.video.*;
Movie movie;
void setup(){
   size(720,480,P3D);
   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);
  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);
  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,1,0);
    vertex(0,400,400,1,1);
    vertex(0,0,400,0,1);
  endShape();
}

//week13-5
//利用方向鍵來移動我們的主角
//修改自week13-4
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(){
  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,1,0);
    vertex(0,400,400,1,1);
    vertex(0,0,400,0,1);
  endShape();
}

//week13-5
//利用方向鍵來移動我們的主角
//修改自week13-4
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(){
  camera(x,y,z,x+cos(radians(angle)),y,z+sin(radians(angle)),0,1,0);
  if(keyPressed)keyPressed();
  //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,1,0);
    vertex(0,400,400,1,1);
    vertex(0,0,400,0,1);
  endShape();
}

//week13-6
//把今天教的全部加進來
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(){
  background(128);
  camera(200,200,200,200+cos(radians(frameCount)),200,200+sin(radians(frameCount)),0,1,0);
  if(movie.available())movie.read();
  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();
  translate(0,0,1);
  image(movie,0,0,360,240);
  //if(video.available() video.read();
  beginShape();//左方的牆放視訊
    //texture(video);
    /*vertex(0,0,0,0);
    vertex(0,400,0,1,0);
    vertex(0,400,400,1,1);
    vertex(0,0,400,0,1);
  endShape();*/
}

沒有留言:

張貼留言