Exemplo n.º 1
0
  public float generate(CA c, int start, int end, boolean stopOnSame, boolean over, Updater u) {
    if (_b == null || _b.getWidth() != c.getWidth() || _b.getHeight() != c.getHeight()) {
      _b = new CA(c.getWidth(), c.getHeight());
    }
    int times = end - start;
    CA b1 = c, b2 = _b; // double buffer
    // int[] sur = new int[_len*_len];
    int[] sur = new int[_len - 1];
    int dim = _len;
    int offset = (dim - 1) / 2;
    Selector sel = selector();
    for (int t = 0; t < times; t++) {
      for (int x = 0; x < b1.getWidth(); x++) {
        for (int y = 0; y < b1.getHeight(); y++) {
          int idx = 0;
          int dx = x - offset;
          int dy = y - offset;
          if (false
              && dx >= 0
              && dy >= 0
              && dx + dim < b1.getWidth()
              && dy + dim < b1.getHeight()) {
            b1.getBlock(sur, dx, dy, _len);
          } else {
            for (int i = x - 1; i <= x + 1; i++) {
              for (int j = y - 1; j <= y + 1; j++) {
                sur[idx++] = get(b1, i, j);
              }
            }
          }
          int n = sel.next(sur, 0);
          if (n != -1) {
            b2.set(x, y, _colors[n]);
            if (_interceptor != null) {
              _interceptor.set(x, y, _colors[n]);
            }
            // System.err.print(" "+n);
          }
          /*
          int dx = x - offset;
          int dy = y - offset;
          if(dx>=0&&dy>=0&&dx+dim<b1.getWidth()&&dy+dim<b1.getHeight()) {
              b1.getBlock(sur, dx, dy, _len);
          }
          int n = sel.next(sur, 0);
          if(n!=-1) {
              b2.set(x, y, n);
          }
          */
        }
      }

      // swap
      CA temp = b1;
      b1 = b2;
      b2 = temp;
    }
    c.setData(b1.getData());
    // System.err.print(".");
    return 0f;
  }