代码之家  ›  专栏  ›  技术社区  ›  Sr.Richie

知道为什么这个加工草图运行如此缓慢吗?

  •  2
  • Sr.Richie  · 技术社区  · 11 年前

    我使用的是处理2.1。 知道为什么我的简单草图在我的(强大的)机器上运行缓慢吗?

    我只是在网格中绘制一些四边形,当按下鼠标时,我试图(通过Ani库)设置它们的动画,但动画很草率,而且非常低。。。。有什么提示吗?

    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);
    }
    
    2 回复  |  直到 11 年前
        1
  •  1
  •   Sr.Richie    11 年前

    解决了的。这是一个铸造问题。角度是一个整数,所以当减去我通过Ani设置动画的值时,它会被舍入

        2
  •  0
  •   Majlik    11 年前

    因为您在很长一段时间内为低范围的值设置动画

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

    你的射程是[3,-3],时间是20秒。只需尝试减少时间并增加范围,您将在强大的机器上看到更流畅的动画:)如下:

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

    但在动画结束时,会出现某种程度的减慢,默认情况下 Ani 有关更多信息,请阅读文档 here