2017-01-27 2 views
0

iPad 용 코드 내에서로드 한 노래의 진폭에 원을 그리는 배열이있는 스케치를 만들었습니다. 나는 그 서클을 수정하려고하고있다. (즉, 색상을 변경하거나 진폭의 특정 값에서 획을 추가한다. 그러나 문장이 있다면 그 부분을 정확히 어디에 놓을 지 확신 할 수 없다.) 내가 시도한 모든 것은 영향을받지 않는다. 그려진 비주얼p5.js 음악 VIsualization

키는 원/비주얼을 "그리기"위한 것이거나 손가락이 화면에 있지 않더라도 마지막으로 "터치 한"장소에서 작업하는 것입니다.이 스케치는 다음과 같이 상호 작용할 수 있습니다. mmengle.com startover_music 링크로

var circles = []; 


function preload() { 
    sound = loadSound('assets/findingnemoegg.mp3'); 
} 

function setup() { 
    createCanvas(windowWidth, windowHeight); 

    amplitude = new p5.Amplitude(); 
    sound.play(); 

for (var i = 0; i < 1; i++) { 
    circles[i] = { 
    display: function() { 
     var level = amplitude.getLevel(); 
     var size = map(level, 0, 1, 10, 900); 
     noStroke(); 
     fill(128,166,206,40); 
     ellipse(touchX + level, touchY + level, size, size); 

    } 
    } 
    } 

    } 

function draw() { 

    fill(255,8); 
    rect(0,0,windowWidth, windowHeight); 



    for (var i = 0; i < circles.length; i++) { 
    circles[i].display(); 
    } 

} 
+0

그래서 사용자가 마지막으로 터치 한 곳에서 원을 그려야하며 특정 색상으로 표시해야합니까? – Pepe

답변

0

임이 당신이 원하는 것을 가정 할 것 :.

var circles = []; 
var lastTouchX; 
var lastTouchY; 

function preload() { 
    sound = loadSound('assests/findingnemoegg.mp3'); 
} 

function setup() { 
    createCanvas(windowWidth, windowHeight); 

    amplitude = new p5.Amplitude(); 
    sound.play(); 

    lastTouchX = width/2; 
    lastTouchY = height/2; 
} 

function draw() { 

    fill(255, 8); 
    rect(0, 0, windowWidth, windowHeight); 

    for (var i = 0; i < circles.length; i++) { 
    circles[i].display(); 
    } 

} 

//change to touchEnded() 
function mousePressed() { 
    lastTouchX = mouseX; 
    lastTouchY = mouseY; 
    circles.push(new Circle()); 
} 

function Circle() { 
    this.x = lastTouchX; 
    this.y = lastTouchY; 

    this.display = function() { 
    var level = amplitude.getLevel(); 
    var size = map(level, 0, 1, 10, 200); 
    noStroke(); 
    //if statement to change fill 
    fill(128, 166, 206, 40); 
    //if statement to change fill 
    ellipse(this.x, this.y, size, size); 

    } 
} 
+0

내가받는 유일한 오류는 너비와 높이가 정의되어 있지 않다는 것입니다! 그렇지 않으면 작동해야하는 것처럼 보입니다. –

+0

죄송합니다. var lastTouchX; var lastTouchY;'설정에서'lastTouchX = width/2; lastTouchY = 높이/2; ' – Pepe

+0

원은 중심에만 머물러있는 것처럼 보입니다! 그리고 마우스 또는 터치 상호 작용을 기반으로 이동하지 않습니다. 음. –

관련 문제