Processing
09 Movie Maker 作影片
For making movies, It’s different in Processing 2.0 Processing 2.0之後 作影片方不太一樣
Let’s just make a really quick tryout. 很快地來試一下
import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*;
pushMatrix(); fill(255,0,0); translate(0,-70,80); noStroke(); sphere(20); popMatrix();
PeasyCam cam; void setup(){ size(1000,500,P3D); cam = new PeasyCam(this,0,0,0, 600); }
void draw(){ background(255,0,50); ////SnowMan////////////////////////////////////////////////////// stroke(255); strokeWeight(1); pushMatrix(); noFill(); translate(0,100,0); sphere(140); popMatrix(); pushMatrix(); noFill(); translate(0,-70,0); sphere(80); popMatrix(); pushMatrix(); noFill(); stroke(0,255,180); translate(0,-20,0); scale(1,0.3,1); sphere(100); popMatrix();
pushMatrix(); fill(0); translate(-30,-100,65); noStroke(); sphere(10); popMatrix(); pushMatrix(); fill(0); translate(30,-100,65); noStroke(); sphere(10); popMatrix(); pushMatrix(); fill(0); translate(0,-140,0); rotateX(PI/2); stroke(255); strokeWeight(1); ellipse(0,0,160,160); popMatrix(); pushMatrix(); fill(0); translate(0,-170,0); stroke(255); strokeWeight(1); box(80,60,80); popMatrix();
自己轉
cam.rotateY(radians(0.5));
Auto-rotation
}
Test_Code
Although the Christmas is over, I just draw a snow man. 雖然聖誕已過 還是畫個雪人
Now we need something to record the video. 我們現在需要一些東 西來製作影片
import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*;
pushMatrix(); fill(255,0,0); translate(0,-70,80); noStroke(); sphere(20); popMatrix();
PeasyCam cam; void setup(){ size(1000,500,P3D); cam = new PeasyCam(this,0,0,0, 600); }
void draw(){ background(255,0,50); ////SnowMan////////////////////////////////////////////////////// stroke(255); strokeWeight(1); pushMatrix(); noFill(); translate(0,100,0); sphere(140); popMatrix(); pushMatrix(); noFill(); translate(0,-70,0); sphere(80); popMatrix(); pushMatrix(); noFill(); stroke(0,255,180); translate(0,-20,0); scale(1,0.3,1); sphere(100); popMatrix();
pushMatrix(); fill(0); translate(-30,-100,65); noStroke(); sphere(10); popMatrix(); pushMatrix(); fill(0); translate(30,-100,65); noStroke(); sphere(10); popMatrix(); pushMatrix(); fill(0); translate(0,-140,0); rotateX(PI/2); stroke(255); strokeWeight(1); ellipse(0,0,160,160); popMatrix(); pushMatrix(); fill(0); translate(0,-170,0); stroke(255); strokeWeight(1); box(80,60,80); popMatrix();
cam.rotateY(radians(0.5));
saveFrame("output/frames####.png");
}
Add this line for converting images 加這一行以轉換影像
If you want, You can also add a Keypressed function to record it specifically. 如果你需要 也可以加 按鍵功能
import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; PeasyCam cam;
boolean recording; void setup(){ size(1000,500,P3D); cam = new PeasyCam(this,0,0,0, 600); }
Don’t forget this. 別忘了這個
void draw(){ background(255,0,50); ////SnowMan////////////////////////////////////////////////////// stroke(255); strokeWeight(1); pushMatrix(); noFill(); translate(0,100,0); sphere(140); popMatrix(); pushMatrix(); noFill(); translate(0,-70,0); sphere(80); popMatrix(); pushMatrix(); noFill(); stroke(0,255,180); translate(0,-20,0); scale(1,0.3,1); sphere(100); popMatrix(); pushMatrix(); fill(255,0,0); translate(0,-70,80); noStroke(); sphere(20); popMatrix(); pushMatrix(); fill(0); translate(-30,-100,65); noStroke(); sphere(10); popMatrix();
pushMatrix(); fill(0); translate(30,-100,65); noStroke(); sphere(10); popMatrix(); pushMatrix(); fill(0); translate(0,-140,0); rotateX(PI/2); stroke(255); strokeWeight(1); ellipse(0,0,160,160); popMatrix();
pushMatrix(); fill(0); translate(0,-170,0); stroke(255); strokeWeight(1); box(80,60,80); popMatrix(); cam.rotateY(radians(0.5));
if (recording) { saveFrame("output/frames####.png"); }
} void keyPressed() { // If we press r, start or stop recording! if (key == 'r' || key == 'R') { recording = !recording; }
} keyPressed function. 按鍵功能
Before you start recording, Please save your file 在你紀錄影片之前 請先存檔
When you start recording, it will automatically have this “output” folder
當你開始錄影時 你會發現存檔的資料 夾中多了“output”
It converts each of your frame into an Images 他將你影格都轉換成影像
But then, we got Frames. How to make it as a movie. 但我們有了影格 怎麼製作影片?
先選PNG八
Just choose PNG for now
Choose the output folder with your images inside 選擇錄製時輸出影像的output資料夾
You can also choose a sound file for background music 你還可以加聲音
create a file name and save. 取個名字
After all, just
CREATE MOVIE 最後 創建影片
Now, just wait for this. 再來就等待吧
DONE!
If you have problems of playing movies, choose “JPEG” instead of “PNG” while converting the movie. 如果你播放有問題的話 在輸出的時候選擇 “JPEG” 而不要選擇 “PNG”