예제 #1
0
 public void point(float x, float y) {
   if (stroke) {
     //      if (strokeWeight > 1) {
     line(x, y, x + EPSILON, y + EPSILON);
     //      } else {
     //        set((int) screenX(x, y), (int) screenY(x, y), strokeColor);
     //      }
   }
 }
예제 #2
0
  public void vertex(float x, float y) {
    curveVertexCount = 0;
    // float vertex[];

    if (vertexCount == vertices.length) {
      float temp[][] = new float[vertexCount << 1][VERTEX_FIELD_COUNT];
      System.arraycopy(vertices, 0, temp, 0, vertexCount);
      vertices = temp;
      // message(CHATTER, "allocating more vertices " + vertices.length);
    }
    // not everyone needs this, but just easier to store rather
    // than adding another moving part to the code...
    vertices[vertexCount][X] = x;
    vertices[vertexCount][Y] = y;
    vertexCount++;

    switch (shape) {
      case POINTS:
        point(x, y);
        break;

      case LINES:
        if ((vertexCount % 2) == 0) {
          line(vertices[vertexCount - 2][X], vertices[vertexCount - 2][Y], x, y);
        }
        break;

      case TRIANGLES:
        if ((vertexCount % 3) == 0) {
          triangle(
              vertices[vertexCount - 3][X],
              vertices[vertexCount - 3][Y],
              vertices[vertexCount - 2][X],
              vertices[vertexCount - 2][Y],
              x,
              y);
        }
        break;

      case TRIANGLE_STRIP:
        if (vertexCount >= 3) {
          triangle(
              vertices[vertexCount - 2][X],
              vertices[vertexCount - 2][Y],
              vertices[vertexCount - 1][X],
              vertices[vertexCount - 1][Y],
              vertices[vertexCount - 3][X],
              vertices[vertexCount - 3][Y]);
        }
        break;

      case TRIANGLE_FAN:
        if (vertexCount == 3) {
          triangle(vertices[0][X], vertices[0][Y], vertices[1][X], vertices[1][Y], x, y);
        } else if (vertexCount > 3) {
          gpath = new GeneralPath();
          // when vertexCount > 3, draw an un-closed triangle
          // for indices 0 (center), previous, current
          gpath.moveTo(vertices[0][X], vertices[0][Y]);
          gpath.lineTo(vertices[vertexCount - 2][X], vertices[vertexCount - 2][Y]);
          gpath.lineTo(x, y);
          drawShape(gpath);
        }
        break;

      case QUADS:
        if ((vertexCount % 4) == 0) {
          quad(
              vertices[vertexCount - 4][X],
              vertices[vertexCount - 4][Y],
              vertices[vertexCount - 3][X],
              vertices[vertexCount - 3][Y],
              vertices[vertexCount - 2][X],
              vertices[vertexCount - 2][Y],
              x,
              y);
        }
        break;

      case QUAD_STRIP:
        // 0---2---4
        // |   |   |
        // 1---3---5
        if ((vertexCount >= 4) && ((vertexCount % 2) == 0)) {
          quad(
              vertices[vertexCount - 4][X],
              vertices[vertexCount - 4][Y],
              vertices[vertexCount - 2][X],
              vertices[vertexCount - 2][Y],
              x,
              y,
              vertices[vertexCount - 3][X],
              vertices[vertexCount - 3][Y]);
        }
        break;

      case POLYGON:
        if (gpath == null) {
          gpath = new GeneralPath();
          gpath.moveTo(x, y);
        } else if (breakShape) {
          gpath.moveTo(x, y);
          breakShape = false;
        } else {
          gpath.lineTo(x, y);
        }
        break;
    }
  }