2025年5月15日 星期四

12750192_WKY

 week13-1_video

import processing.video.*;

//Capture video;

Movie movie;

void setup(){

 size(640,960);

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

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

 movie.loop();

 //video.start();

}

void draw(){

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

 image(movie,0,0);

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

 //image(video,0,0);

} 


//week13_2_camera_movie_eye_center_up

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

import processing.video.*;//要使用影片的外掛喔

Movie movie;//要放影片的變數

void setup(){

  size(720,480,P3D);

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

  movie.loop();//迴圈係數

}

void draw(){

  background(128);

  //https://processing.org/reference/camera_.html

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

  //很多參數 eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ

  

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

  image(movie,0,0);

}

//week13_3_texture_textureMode_beginShape_vertex_endShape

//先交貼圖之後再加進去

//https://processing.org/reference/texture_.html

PImage img;

void setup(){

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

  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_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();//正前方,z座標都放0

     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();

   beginShape();//左方,x座標都放0

     texture(img);

     vertex(0,0,0,0,0);//x,y,z,u,v

     vertex(0,400,0,1,0);

     vertex(0,400,400,1,1);

     vertex(0,0,400,0,1);

   endShape();

}


//week13-5

//把貼圖和camrea整合在一起


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);

  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

//集大成

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);

    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();

  //image(video,0,0);

  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();

}







沒有留言:

張貼留言