2012-12-01 1 views
1

내가처리 중 Android 모드에서 프레임 속도를 늘리는 방법은 무엇입니까?

내가 프레임 속도를 변경할 때, 그것은 자바 & 자바 스크립트 모드를 모양 이동에 있지만 안드로이드 모드의 변화를 보여주고, 프레임 속도() 메소드가 processing.js.com 사이트에서 오픈 소스 코드를 사용하고 , 왜 이런 일이 발생합니까? 시각화를 위해 프레임 속도를 어떻게 높여야합니까?

 // Set number of circles 
    int count = 25; 
    // Set maximum and minimum circle size 
    int maxSize = 100; 
    int minSize = 20; 
    // Build float array to store circle properties 
    float[][] e = new float[count][5]; 
    // Set size of dot in circle center 
    float ds=2; 
    // Selected mode switch 
    int sel = 0; 
    // Set drag switch to false 
    boolean dragging=false; 
    // If use drags mouse... 
    void mouseDragged(){ 
    // Set drag switch to true 
    dragging=true; 
    } 
    // If user releases mouse... 
    void mouseReleased(){ 
    // ..user is no-longer dragging 
    dragging=false; 
    } 

    // Set up canvas 
    void setup(){ 
    // Frame rate 
    frameRate(130); 
    // Size of canvas (width,height) 
    size(600,475); 
    // Stroke/line/border thickness 
    strokeWeight(1); 
    // Initiate array with random values for circles 
    for(int j=0;j< count;j++){ 
     e[j][0]=random(width); // X 
     e[j][1]=random(height); // Y 
     e[j][2]=random(minSize,maxSize); // Radius   
     e[j][3]=random(-.5,.5); // X Speed 
     e[j][4]=random(-.5,.5); // Y Speed  
    } 
    } 

    // Begin main draw loop (called 25 times per second) 
    void draw(){ 
    // Fill background black 
    background(0); 
    // Begin looping through circle array 
    for (int j=0;j< count;j++){ 
    // Disable shape stroke/border 
    noStroke(); 
    // Cache diameter and radius of current circle 
    float radi=e[j][2]; 
    float diam=radi/2; 
    // If the cursor is within 2x the radius of current circle... 
    if(dist(e[j][0],e[j][1],mouseX,mouseY) < radi){ 
    // Change fill color to green. 
    fill(64,187,128,100); 
    // Remember user has circle "selected" 
    sel=1; 
    // If user has mouse down and is moving... 
    if (dragging){ 
     // Move circle to circle position 
     e[j][0]=mouseX; 
     e[j][1]=mouseY; 
     } 
    } else { 
     // Keep fill color blue 
     fill(64,128,187,100); 
     // User has nothing "selected" 
     sel=0; 
    } 
    // Draw circle 
    ellipse(e[j][0],e[j][1],radi,radi); 
    // Move circle 
    e[j][0]+=e[j][3]; 
    e[j][1]+=e[j][4]; 


    /* Wrap edges of canvas so circles leave the top 
    and re-enter the bottom, etc... */ 
    if(e[j][0] < -diam  ){ e[j][0] = width+diam; } 
    if(e[j][0] > width+diam){ e[j][0] = -diam;  } 
    if(e[j][1] < 0-diam ){ e[j][1] = height+diam; } 
    if(e[j][1] > height+diam){ e[j][1] = -diam;  } 

    // If current circle is selected... 
    if (sel==1) { 
     // Set fill color of center dot to white.. 
     fill(255,255,255,255); 
     // ..and set stroke color of line to green. 
     stroke(128,255,0,100);  
    } else {    
     // otherwise set center dot color to black.. 
     fill(0,0,0,255); 
     // and set line color to turquoise. 
     stroke(64,128,128,255);  
    } 

    // Loop through all circles 
    for(int k=0;k< count;k++){ 
     // If the circles are close... 
     if(dist(e[j][0],e[j][1],e[k][0],e[k][1]) < radi){ 
     // Stroke a line from current circle to adjacent circle 
     line(e[j][0],e[j][1],e[k][0],e[k][1]); 
     } 
    } 
    // Turn off stroke/border 
    noStroke();  
    // Draw dot in center of circle 
    rect(e[j][0]-ds,e[j][1]-ds,ds*2,ds*2); 
    } 
    } 
+0

여기에 붙여 넣으시겠습니까? –

+0

@BhavikAmbani 소스 코드를 추가합니다. –

+0

프레임 속도를 변경하고 싶습니까, 아니면 애니메이션 속도를 높이고 싶습니까? 프레임 속도 문제로 어떤 일이 일어나는지 잘 모르겠지만 애니메이션 속도를 높이는 더 좋은 방법을 알려줄 수 있습니다. – spex

답변

1

스케치에서 원의 속도를 변경하려면 속도 값을 간단히 변경하는 것이 더 쉽습니다.

e[j][3] = random(-.5, .5); // X Speed 
e[j][4] = random(-.5, .5); // Y Speed 

이 값은() 무승부에 동그라미를 이동하기 위해 나중에 사용되는 기능 :

// Move circle 
e[j][0] += e[j][3]; 
e[j][1] += e[j][4]; 

당신이 할 수 단순히 변화 셋업() 함수에서

, 다음과 같은 설정 e[j][3]e[j][4] 값이 setup() 함수에 설정되어 있거나 코드 시작 부분에 전역 범위에 할당 된 변수로 바꿀 수 있습니다. 다음은 내가 할 수있는 빠른 수정입니다. 코드 시작 부분에 변수 float speed = 0.5;을 설정합니다. 이 값을 크게하면 서클의 움직임이 빨라집니다.

// Set number of circles 
int count = 25; 
// Set maximum and minimum circle size 
int maxSize = 100; 
int minSize = 20; 
// Set speed 
float speed = 0.5; 
// Build float array to store circle properties 
float[][] e = new float[count][5]; 
// Set size of dot in circle center 
float ds = 2; 
// Selected mode switch 
int sel = 0; 
// Set drag switch to false 
boolean dragging = false; 

// If use drags mouse... 
void mouseDragged() { 
    // Set drag switch to true 
    dragging = true; 
} 

// If user releases mouse... 
void mouseReleased() { 
    // ..user is no-longer dragging 
    dragging = false; 
} 

// Set up canvas 
void setup() { 
    // Size of canvas (width,height) 
    size(600, 475); 
    // Stroke/line/border thickness 
    strokeWeight(1); 
    // Initiate array with random values for circles 
    for (int j = 0; j < count; j++) { 
    e[j][0] = random(width); // X 
    e[j][1] = random(height); // Y 
    e[j][2] = random(minSize, maxSize); // Radius 
    e[j][3] = random(-speed, speed); // X Speed 
    e[j][4] = random(-speed, speed); // Y Speed 
    } 
} 

// Begin main draw loop (called 25 times per second) 
void draw() { 
    // Fill background black 
    background(0); 
    // Begin looping through circle array 
    for (int j = 0; j < count; j++) { 
    // Disable shape stroke/border 
    noStroke(); 
    // Cache diameter and radius of current circle 
    float radi = e[j][2]; 
    float diam = radi/2; 
    // If the cursor is within 2x the radius of current circle... 
    if (dist(e[j][0], e[j][1], mouseX, mouseY) < radi) { 
     // Change fill color to green. 
     fill(64, 187, 128, 100); 
     // Remember user has circle "selected" 
     sel = 1; 
     // If user has mouse down and is moving... 
     if (dragging) { 
     // Move circle to circle position 
     e[j][0] = mouseX; 
     e[j][1] = mouseY; 
     } 
    } else { 
     // Keep fill color blue 
     fill(64, 128, 187, 100); 
     // User has nothing "selected" 
     sel = 0; 
    } 
    // Draw circle 
    ellipse(e[j][0], e[j][1], radi, radi); 
    // Move circle 
    e[j][0] += e[j][3]; 
    e[j][1] += e[j][4]; 


    /* Wrap edges of canvas so circles leave the top 
    and re-enter the bottom, etc... */ 
    if (e[j][0] < -diam) { 
     e[j][0] = width + diam; 
    } 
    if (e[j][0] > width + diam) { 
     e[j][0] = -diam; 
    } 
    if (e[j][1] < 0 - diam) { 
     e[j][1] = height + diam; 
    } 
    if (e[j][1] > height + diam) { 
     e[j][1] = -diam; 
    } 

    // If current circle is selected... 
    if (sel == 1) { 
     // Set fill color of center dot to white.. 
     fill(255, 255, 255, 255); 
     // ..and set stroke color of line to green. 
     stroke(128, 255, 0, 100); 
    } else { 
     // otherwise set center dot color to black.. 
     fill(0, 0, 0, 255); 
     // and set line color to turquoise. 
     stroke(64, 128, 128, 255); 
    } 

    // Loop through all circles 
    for (int k = 0; k < count; k++) { 
     // If the circles are close... 
     if (dist(e[j][0], e[j][1], e[k][0], e[k][1]) < radi) { 
     // Stroke a line from current circle to adjacent circle 
     line(e[j][0], e[j][1], e[k][0], e[k][1]); 
     } 
    } 
    // Turn off stroke/border 
    noStroke(); 
    // Draw dot in center of circle 
    rect(e[j][0] - ds, e[j][1] - ds, ds * 2, ds * 2); 
    } 
} 
관련 문제