2014-03-25 36 views
2

我正在使用處理2.1。 任何想法爲什麼我的簡單素描在我的(強大)機器上運行緩慢?任何想法爲什麼這個處理草圖運行如此緩慢?

我只是在網格中繪製一些四邊形,當按下鼠標時,我試圖通過動畫(通過Ani庫)動畫,但動畫是sl and,超級低....任何提示?

import de.looksgood.ani.*; 
import de.looksgood.ani.easing.*; 

int quadSize = 30; 
int spacing = 10; 
int numRows = 11; 
int numColumns = 22; 

float angleRotationIncrease = 3; 

void setup() { 
size (900, 600, P3D); 
background (0); 
fill (255); 
stroke (255); 
Ani.init(this); 
frameRate (60); 
} 



void draw() { 
    text(frameRate,20,20); 
    // println (angleRotationIncrease); 
    background (0); 
    int posX = 0; 
    int posY = 0; 
    int angleRotation = 0; 

    float scaleFactor = 1; 
    float scaleFactorIncrease = -0.045; 
    for (int i=0; i<numRows; i++) { 
     for (int j=0; j<numColumns; j++) { 
      pushMatrix(); 
      translate (posX + quadSize/2, posY + quadSize/2); 
      // println (radians(angleRotation)); 
      rotate(radians(angleRotation)); 
      if (scaleFactor > 0) { 
      rect (-quadSize/2 * scaleFactor, -quadSize/2* scaleFactor, quadSize* scaleFactor, quadSize* scaleFactor); 
      } 
      popMatrix(); 
      posX += (quadSize + spacing); 
      angleRotation += angleRotationIncrease; 
      scaleFactor += scaleFactorIncrease; 
     } 
     // for each new line, reset or change params 
     scaleFactorIncrease -= 0.002; 
     scaleFactor = 1; 
     angleRotation = 0; 
     posX = 0; 
     posY += (quadSize + spacing); 
    } 
} 


void mousePressed() { 
    Ani.to(this, 20, "angleRotationIncrease", -3); 
} 

回答

1

解決。這是一個鑄造問題。 Anglerotation是一個int,所以當減去通過Ani的動畫值時,它會變圓

0

因爲你在很長的一段動畫的時間低範圍的值

Ani.to(this, 20, "angleRotationIncrease", -3); 

你的範圍是[3,-3]和時間爲20秒。只是儘量減少時間,增加範圍的,你會看到更流暢的動畫你的強大的機器:)這樣的:

Ani.to(this, 2, "angleRotationIncrease", -30); 

但在動畫的結尾是某種放緩又該由違約Ani指定的圖書館等更多信息閱讀文檔here

+0

thx,但它不能解釋爲什麼動畫會持續5幀。如果您取消註釋println(angleRotationIncrease),您將看到動畫應該有更多的步驟,您可以看到其中的更多步驟 –

+0

是的,但動畫更改了「float angleRotationIncrease」的值,該值被添加到了「int angleRotation」中,角度只有一次。嘗試改變角度'浮動',那麼你會看到更多的動畫步驟。 – Majlik

+0

交叉點,看看我自己的答案只是張貼:) –

相關問題