예제 #1
0
  public Shape prune() {
    Polygon result = new Polygon();

    for (int i = 0; i < getPointCount(); i++) {
      int next = i + 1 >= getPointCount() ? 0 : i + 1;
      int prev = i - 1 < 0 ? getPointCount() - 1 : i - 1;

      float dx1 = getPoint(i)[0] - getPoint(prev)[0];
      float dy1 = getPoint(i)[1] - getPoint(prev)[1];
      float dx2 = getPoint(next)[0] - getPoint(i)[0];
      float dy2 = getPoint(next)[1] - getPoint(i)[1];

      float len1 = MathUtils.sqrt((dx1 * dx1) + (dy1 * dy1));
      float len2 = MathUtils.sqrt((dx2 * dx2) + (dy2 * dy2));
      dx1 /= len1;
      dy1 /= len1;
      dx2 /= len2;
      dy2 /= len2;

      if ((dx1 != dx2) || (dy1 != dy2)) {
        result.addPoint(getPoint(i)[0], getPoint(i)[1]);
      }
    }

    return result;
  }
예제 #2
0
 protected final synchronized void checkPoints() {
   if (pointsDirty) {
     createPoints();
     findCenter();
     calculateRadius();
     if (points == null) {
       return;
     }
     synchronized (points) {
       final int size = points.length;
       if (size > 0) {
         maxX = points[0];
         maxY = points[1];
         minX = points[0];
         minY = points[1];
         for (int i = 0; i < size / 2; i++) {
           maxX = MathUtils.max(points[i * 2], maxX);
           maxY = MathUtils.max(points[(i * 2) + 1], maxY);
           minX = MathUtils.min(points[i * 2], minX);
           minY = MathUtils.min(points[(i * 2) + 1], minY);
         }
       }
       pointsDirty = false;
       trianglesDirty = true;
     }
   }
 }
예제 #3
0
 private float[] getNormal(float[] start, float[] end) {
   float dx = start[0] - end[0];
   float dy = start[1] - end[1];
   float len = MathUtils.sqrt((dx * dx) + (dy * dy));
   dx /= len;
   dy /= len;
   return new float[] {-dy, dx};
 }
예제 #4
0
  protected void calculateRadius() {
    boundingCircleRadius = 0;

    for (int i = 0; i < points.length; i += 2) {
      float temp =
          ((points[i] - center[0]) * (points[i] - center[0]))
              + ((points[i + 1] - center[1]) * (points[i + 1] - center[1]));
      boundingCircleRadius = (boundingCircleRadius > temp) ? boundingCircleRadius : temp;
    }
    boundingCircleRadius = MathUtils.sqrt(boundingCircleRadius);
  }
예제 #5
0
  public float[] getNormal(int index) {
    float[] current = getPoint(index);
    float[] prev = getPoint(index - 1 < 0 ? getPointCount() - 1 : index - 1);
    float[] next = getPoint(index + 1 >= getPointCount() ? 0 : index + 1);

    float[] t1 = getNormal(prev, current);
    float[] t2 = getNormal(current, next);

    if ((index == 0) && (!closed())) {
      return t2;
    }
    if ((index == getPointCount() - 1) && (!closed())) {
      return t1;
    }

    float tx = (t1[0] + t2[0]) / 2;
    float ty = (t1[1] + t2[1]) / 2;
    float len = MathUtils.sqrt((tx * tx) + (ty * ty));
    return new float[] {tx / len, ty / len};
  }
예제 #6
0
 public float length() {
   return MathUtils.sqrt(x * x + y * y);
 }
예제 #7
0
  private final float[] arc(float t, float cx, float cy, float radius, float start, float end) {
    float point = (end - start) * t + start;

    return new float[] {(MathUtils.cos(point) * radius) + cx, (MathUtils.sin(point) * radius) + cy};
  }
예제 #8
0
  public static final Cycle getSample(
      int type,
      float srcWidth,
      float srcHeight,
      float width,
      float height,
      float offset,
      int padding) {

    Cycle cycle = new Cycle();
    float s = 1;
    if (srcWidth > srcHeight) {
      s = MathUtils.max(srcWidth / width, srcHeight / height);
    } else {
      s = MathUtils.min(srcWidth / width, srcHeight / height);
    }
    final float scale = s;
    switch (type) {
      case 0:
        cycle =
            new Cycle() {

              private static final long serialVersionUID = 1L;

              private Path path;

              public void step(
                  GLEx g,
                  float x,
                  float y,
                  float progress,
                  int index,
                  int frame,
                  GLColor color,
                  float alpha) {
                float cx = this.padding + 50,
                    cy = this.padding + 50,
                    angle = (MathUtils.PI / 180) * (progress * 360),
                    innerRadius = index == 1 ? 10 : 25;
                if (path == null) {
                  path = new Path(getX() + x * scale, getY() + y * scale);
                } else {
                  path.clear();
                  path.set(getX() + x * scale, getY() + y * scale);
                }
                path.lineTo(
                    getX() + ((MathUtils.cos(angle) * innerRadius) + cx) * scale,
                    getY() + ((MathUtils.sin(angle) * innerRadius) + cy) * scale);
                path.close();
                g.draw(path);
              }
            };
        cycle.setLineWidth(5);
        cycle.setDelay(45);
        cycle.setColor(0xFF2E82);
        cycle.setStepType(4);
        cycle.setStepsPerFrame(1);
        cycle.setTrailLength(1);
        cycle.setPointDistance(0.05f);
        cycle.addPath(Cycle.ARC, 50, 50, 40, 0, 360);
        break;
      case 1:
        cycle.setColor(0xFF7B24);
        cycle.setStepsPerFrame(1);
        cycle.setTrailLength(1);
        cycle.setPointDistance(0.10f);
        cycle.setMultiplier(2);
        cycle.addPath(Cycle.ARC, 10 * scale, 10 * scale, 10 * scale, -270, -90);
        cycle.addPath(
            Cycle.BEZIER,
            10 * scale,
            0 * scale,
            40 * scale,
            20 * scale,
            20 * scale,
            0,
            30 * scale,
            20 * scale);
        cycle.addPath(Cycle.ARC, 40 * scale, 10 * scale, 10 * scale, 90, -90);
        cycle.addPath(
            Cycle.BEZIER,
            40 * scale,
            0 * scale,
            10 * scale,
            20 * scale,
            30 * scale,
            0,
            20 * scale,
            20 * scale);
        break;
      case 2:
        cycle.setColor(0xD4FF00);
        cycle.setStepType(1);
        cycle.setDelay(55);
        cycle.setStepsPerFrame(2);
        cycle.setTrailLength(0.3f);
        cycle.setPointDistance(0.1f);
        cycle.addPath(Cycle.LINE, 0, 0, 30 * scale, 0);
        cycle.addPath(Cycle.LINE, 30 * scale, 0 * scale, 30 * scale, 30 * scale);
        cycle.addPath(Cycle.LINE, 30 * scale, 30 * scale, 0, 30 * scale);
        cycle.addPath(Cycle.LINE, 0, 30 * scale, 0, 0);
        break;
      case 3:
        cycle =
            new Cycle() {

              private static final long serialVersionUID = 1L;

              private Path path;

              public void step(
                  GLEx g,
                  float x,
                  float y,
                  float progress,
                  int index,
                  int frame,
                  GLColor color,
                  float alpha) {

                float cx = this.padding + 50,
                    cy = this.padding + 50,
                    angle = (MathUtils.PI / 180) * (progress * 360);
                alpha = MathUtils.max(0.5f, alpha);
                g.setAlpha(alpha);
                if (path == null) {
                  path = new Path(getX() + x * scale, getY() + y * scale);
                } else {
                  path.clear();
                  path.set(getX() + x * scale, getY() + y * scale);
                }
                path.lineTo(
                    getX() + ((MathUtils.cos(angle) * 35) + cx) * scale,
                    getY() + ((MathUtils.sin(angle) * 35) + cy) * scale);
                path.close();
                g.draw(path);
                if (path == null) {
                  path =
                      new Path(
                          getX() + ((MathUtils.cos(-angle) * 32) + cx) * scale,
                          getY() + ((MathUtils.sin(-angle) * 32) + cy) * scale);
                } else {
                  path.clear();
                  path.set(
                      getX() + ((MathUtils.cos(-angle) * 32) + cx) * scale,
                      getY() + ((MathUtils.sin(-angle) * 32) + cy) * scale);
                }
                path.lineTo(
                    getX() + ((MathUtils.cos(-angle) * 27) + cx) * scale,
                    getY() + ((MathUtils.sin(-angle) * 27) + cy) * scale);
                path.close();
                g.draw(path);
                g.setAlpha(1);
              }
            };
        cycle.setColor(0x05E2FF);
        cycle.setLineWidth(2);
        cycle.setStepType(4);
        cycle.setStepsPerFrame(1);
        cycle.setTrailLength(1);
        cycle.setPointDistance(0.025f);
        cycle.addPath(Cycle.ARC, 50, 50, 40, 0, 360);
        break;
      case 4:
        cycle.setColor(0xFFA50000);
        cycle.setStepsPerFrame(1);
        cycle.setTrailLength(1);
        cycle.setPointDistance(0.025f);
        cycle.addPath(Cycle.ARC, 50 * scale, 50 * scale, 40 * scale, 0, 360);
        break;
      case 5:
        cycle.setColor(0xFF2E82);
        cycle.setDelay(60);
        cycle.setStepType(1);
        cycle.setStepsPerFrame(1);
        cycle.setTrailLength(1);
        cycle.setPointDistance(0.1f);
        cycle.addPath(Cycle.LINE, 0, 20 * scale, 100 * scale, 20 * scale);
        cycle.addPath(Cycle.LINE, 100 * scale, 20 * scale, 0, 20 * scale);
        break;
      case 6:
        cycle.setStepsPerFrame(7);
        cycle.setTrailLength(0.7f);
        cycle.setPointDistance(0.01f);
        cycle.setDelay(35);
        cycle.setLineWidth(10);
        cycle.addPath(Cycle.LINE, 20 * scale, 70 * scale, 50 * scale, 20 * scale);
        cycle.addPath(Cycle.LINE, 50 * scale, 20 * scale, 80 * scale, 70 * scale);
        cycle.addPath(Cycle.LINE, 80 * scale, 70 * scale, 20 * scale, 70 * scale);
        break;
      case 7:
        cycle.setColor(0xD4FF00);
        cycle.setStepsPerFrame(3);
        cycle.setTrailLength(1);
        cycle.setPointDistance(0.01f);
        cycle.setLineWidth(6);
        cycle.setPadding(0);
        cycle.addPath(Cycle.ARC, 50 * scale, 50 * scale, 20 * scale, 360, 0);
        break;
      case 8:
        cycle.setColor(0x05E2FF);
        cycle.setStepsPerFrame(1);
        cycle.setTrailLength(1);
        cycle.setPointDistance(0.02f);
        cycle.addPath(Cycle.ARC, 50 * scale, 50 * scale, 30 * scale, 0, 360);
        break;
      case 9:
        cycle.setStepType(1);
        cycle.setColor(GLColor.yellow);
        cycle.addPath(Cycle.LINE, 10 * scale, 10 * scale, 90 * scale, 10 * scale);
        cycle.addPath(Cycle.LINE, 90 * scale, 10 * scale, 90 * scale, 90 * scale);
        cycle.addPath(Cycle.LINE, 90 * scale, 90 * scale, 10 * scale, 90 * scale);
        cycle.addPath(Cycle.LINE, 10 * scale, 90 * scale, 10 * scale, 10 * scale);
        break;
    }
    float size =
        MathUtils.min(
            srcWidth / (1 / cycle.getPointDistance()), srcHeight / (1 / cycle.getPointDistance()));
    cycle.setPadding(padding);
    cycle.setBlockWidth(size + offset);
    cycle.setBlockHeight(size + offset);
    cycle.setWidth(width * scale);
    cycle.setHeight(height * scale);
    return cycle;
  }