Week 17
本週進度是讓 畫面看起來立體 並對物體進行打光 加上 音訊插入,進行測試
很遺憾我的電腦目前無法使用,不過這個程式應該沒問題(
import ddf.minim.*;
Minim minim;
AudioPlayer player, layer;
void setup(){
size(600,500,P3D);
minim = new Minim(this);
player = minim.loadFile("ost.mp3");
//註: 音樂名稱.副檔名,要把檔案放進資料夾才行
//註: 音樂名稱.副檔名,要把檔案放進資料夾才行
layer = minim.loadFile("K.mp3"); //註: 同上
}
int y = 100;
void draw(){
if(mousePressed){
lights();
}
//lights();
background(0);
translate(width / 2, height / 2);
// Orange point light on the right
pointLight(100, 100, 255, // Color
20, 150, 100); // Position
// Blue directional light from the left
directionalLight(0, 102, 255, // Color
1, 0, 1); // The x-, y-, z-axis direction
// Yellow spotlight from the front
spotLight(255, 150, 109, // Color
mouseX, 40, 20, // Position
0, 0.5, -0.5, // Direction
PI / 2, 2); // Angle, concentration
// Change height of the camera with mouseY
camera(mouseX, mouseY, 220.0, // eyeX, eyeY, eyeZ
-0.0, -5.0, 0.0, // centerX, centerY, centerZ
-10.0, 0.0, 1.0); // upX, upY, upZ
fill(100);
noStroke();
triangle(100,0,-30,20.5,0,120.5);
//sphere(50);
box(90);
stroke(255);
line(-100, 0, 0, 100, 0, 0);
line(0, -100, 0, 0, 100, 0);
line(0, 0, -100, 0, 0, 100);
y = y-1;
if(y < 0 ){
y = height;
}
//建立map函式
//建立map函式
float posx = map(player.position(), 0, player.length(), 0, width);
stroke(0,200,0);
float posy = map(layer.position(), 0, player.length(), 0, width);
line(posx, posy, posx, height);
// note that if the file is MONO, left.get() and right.get() will return the same value
//以下就是用音訊輸入當作控制的神奇畫圖機制
for(int i = 0; i < player.bufferSize() - 1; i++)
{
float x1 = map( i, y, player.bufferSize(), 0, width );
float x2 = map( i+1, y, player.bufferSize(), 0, width );
line( x1, 50 + player.left.get(i), x2, 50 + player.left.get(i+1)*50 );
line( x1, 150 + player.right.get(i)*50, x2, 150 + player.right.get(i+1)*50 );
}
for(int i = 0; i < layer.bufferSize() - 1; i++)
{
float x1 = map( i, y, layer.bufferSize(), 0, height );
float x2 = map( i+1, y, layer.bufferSize(), 0, height );
line( x1, 50 + layer.left.get(i), x2, 50 + layer.left.get(i+1)*50 );
line( x1, 150 + layer.right.get(i)*50, x2, 150 + layer.right.get(i+1)*50 );
}
}
void sound(){
}
void keyPressed(){ //鍵盤按鍵控制音訊播放
if( player.isPlaying() )
{
player.pause();
layer.play();
}
else if ( player.position() == player.length() )
{
player.rewind();
player.play();
layer.pause();
}
else
{
player.play();
layer.pause();
}
}
以上,如有bug,煩請自行改善。
為何要修改別人的程式? 因為他就在那裏。
程式的進步需要大家的幫助!
感謝!
沒有留言:
張貼留言