Package geomerative

Examples of geomerative.RPoint


    float x = 0;
    float y = 0;
    RShape allLines = new RShape();
    while (x < MAX_X*2 && y < MAX_X*2) {     
      RShape s = new RShape();
      s.addMoveTo(new RPoint(0, y));
      s.addLineTo(new RPoint(x, 0));
      RPoint[] points = shape.getIntersections(s);
      if (points != null) {
        List<MyPoint> pointsList = new ArrayList<MyPoint>();     
        for (RPoint p : points) {
          pointsList.add(new MyPoint(p));
        }
        Collections.sort(pointsList);
        if (pointsList.size() % 2 == 0) {
          int i = 0;
          while (i <  pointsList.size()) {
            RPoint p1 = pointsList.get(i++);
            RPoint p2 = pointsList.get(i++);
            RShape l = new RShape();
            l.addMoveTo(p1);
            l.addLineTo(p2);
            allLines.addChild(l);
          }
View Full Code Here


    System.out.println("intersection lines: " + allLines.countChildren());
    return allLines;
  }
 
  private void print(RShape p, String msg) {
    RPoint p1 = p.getTopLeft();
    RPoint p2 = p.getBottomRight();
    System.out.println(msg + " (" + p1.x + ", " + p1.y + "), (" + p2.x + ", " + p2.y + ")");
  }
View Full Code Here

    graphics.translate(dx, dy);       

    // Draw the bounding box of the current shape
    if (drawBoundingBox && shape != null) {
      // Bounding box
      RPoint bounds[] = shape.getBoundsPoints();
      graphics.strokeWeight(STROKE_WEIGHT_GRID);
      graphics.stroke(255,0,0);
      graphics.line( bounds[0].x, bounds[0].y, bounds[1].x, bounds[1].y );
      graphics.line( bounds[1].x, bounds[1].y, bounds[2].x, bounds[2].y );
      graphics.line( bounds[2].x, bounds[2].y, bounds[3].x, bounds[3].y );
      graphics.line( bounds[3].x, bounds[3].y, bounds[0].x, bounds[0].y );

      // Center cross hairs
      RPoint center = shape.getCenter();
      graphics.line( center.x, bounds[0].y, center.x, bounds[0].y - 200 );
      graphics.line( center.x, bounds[3].y, center.x, bounds[3].y + 200 );
      graphics.line( bounds[0].x, center.y, bounds[0].x - 200, center.y );
      graphics.line( bounds[1].x, center.y, bounds[1].x + 200, center.y );
    }
View Full Code Here

    // Generate Instruction objects for every path of shape
    for (int i = 0; i < shape.countPaths(); i++) {
      // Get the first point of this path
      RPath p = shape.paths[i];
      RPoint[] points = p.getPoints();
      RPoint p1 = points[0];

      // Move to that point
      instructions.add(new Instruction(Instruction.MOVE_ABS, p1.x, p1.y));

      // Draw lines to any subsequent points
      for (int k = 0; k < points.length - 1; k++) {
        RPoint p2 = points[k];
        instructions.add(new Instruction(Instruction.LINE_ABS, p2.x, p2.y));
      }
    }   
  }
View Full Code Here

  }

  public void convertToInstructions(List<Instruction> instructions, List<RPath> paths) {
    for (RPath p : paths) {
      RPoint[] points = p.getPoints();
      RPoint p1 = points[0];

      // Move to that point
      instructions.add(new Instruction(Instruction.MOVE_ABS, p1.x, p1.y));

      // Draw lines to any subsequent points
      for (int k = 0; k < points.length - 1; k++) {
        RPoint p2 = points[k];
        instructions.add(new Instruction(Instruction.LINE_ABS, p2.x, p2.y));
      }     
    }
  }
View Full Code Here

 
  public List<RPath> sortPaths(List<RPath> paths) {
    println("sorting paths ...");
    List<RPath> resultPath = new ArrayList<RPath>();
    PathComparator comparator = new PathComparator();
    RPoint tl = shape.getTopLeft();
    RPoint br = shape.getBottomRight();
   
    float y = tl.y;
    while (y < br.y) {
      List<RPath> sortedRow = new ArrayList<RPath>();
      for (int i = 0; i < paths.size(); i++) {
        RPath path = paths.get(i);
        RPoint p = path.getPoints()[0];
        if (p.y < y + MAX_COMPARE_DELTA && p.y >= y) {
          sortedRow.add(path);
        }
      }
      Collections.sort(sortedRow, comparator);
View Full Code Here

   *            RShape to acquire extents from
   * @param msg
   *            Message to print to console
   */
  private void print(RShape p, String msg) {
    RPoint p1 = p.getTopLeft();
    RPoint p2 = p.getBottomRight();
    System.out.println(msg + " (" + p1.x + ", " + p1.y + "), (" + p2.x + ", " + p2.y + ")");
  }
View Full Code Here

 
  private class PathComparator implements Comparator<RPath> {

    @Override
    public int compare(RPath path1, RPath path2) {
      RPoint p1 = path1.getPoints()[0];
      RPoint p2 = path2.getPoints()[0];
      float dx = p1.x - p2.x;
      float dy = p1.y - p2.y;
      if (abs(dy) < MAX_COMPARE_DELTA) {
        return p1.x > p2.x ? 1 : p1.x < p2.x ? -1 : 0;
      }
View Full Code Here

  private void drawShape() {
    int i = 0;
    shape = new RShape();
    for (int y = 0; y < img.height; y++) {
      RShape s = new RShape();
      s.addMoveTo(new RPoint(0*TILE_SIZE, y*TILE_SIZE));
      for (int x = 0; x < img.width; x++) {
        pushMatrix();
        int c = img.pixels[i++];
        int r = (c >> 16) & 0xff;
        int g = (c >> 8) & 0xff;
        int b = c & 0xff
        // 76.5 + 150.45 + 28.05 = 255;
        //float bright = (float)(0.3F * r + 0.59F * g + 0.11F * b);
        float bright = (r + g + b) / 768F;
        bright = 1 - (bright);
        bright *= brightScale;
        // bright = circleSize - bright;
        // println(bright);
        translate(x*TILE_SIZE, y*TILE_SIZE);
        if (bright < 0.2) {
          s.addMoveTo(new RPoint((x+1)*TILE_SIZE, y*TILE_SIZE+4));
        }
        else if (bright < 0.4) {
          line(0, 3, TILE_SIZE, 3);
          s.addLineTo(new RPoint((x+1)*TILE_SIZE, y*TILE_SIZE+4));
        }
        else if (bright < 0.6) {
          line(0, 4, 2, 1);
          line(2, 1, 4, 5);
          line(4, 5, 8, 4);
          s.addLineTo(new RPoint(x*TILE_SIZE+2, y*TILE_SIZE+1));
          s.addLineTo(new RPoint(x*TILE_SIZE+4, y*TILE_SIZE+5));
          s.addLineTo(new RPoint(x*TILE_SIZE+8, y*TILE_SIZE+4));
        }
        else if (bright < 0.8) {
          line(0, 4, 2, 1);
          line(2, 1, 4, 8);
          line(4, 8, 8, 4);
          s.addLineTo(new RPoint(x*TILE_SIZE+2, y*TILE_SIZE+1));
          s.addLineTo(new RPoint(x*TILE_SIZE+4, y*TILE_SIZE+8));
          s.addLineTo(new RPoint(x*TILE_SIZE+8, y*TILE_SIZE+4));
        }
        else {
          line(0, 4, 2, 0);
          line(2, 0, 3, 7);
          line(3, 7, 4, 1);
          line(4, 1, 6, 7);
          line(6, 7, 8, 4);
          s.addLineTo(new RPoint(x*TILE_SIZE+2, y*TILE_SIZE+0));
          s.addLineTo(new RPoint(x*TILE_SIZE+3, y*TILE_SIZE+7));
          s.addLineTo(new RPoint(x*TILE_SIZE+4, y*TILE_SIZE+1));
          s.addLineTo(new RPoint(x*TILE_SIZE+6, y*TILE_SIZE+7));
          s.addLineTo(new RPoint(x*TILE_SIZE+8, y*TILE_SIZE+4));
        }
        popMatrix();      
      }
      shape.addChild(s);
    }   
View Full Code Here

TOP

Related Classes of geomerative.RPoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.