예제 #1
0
  /**
   * This function randomly picks a point along the x-axis and y-axis then draws a line across it
   *
   * @param BL bottom-left
   * @param TR top-right
   * @param HL # of horizontal lines
   * @param VL # of vertical lines
   */
  public ArrayList Draw_Random_Lines(Point BL, Point TR, int HL, int VL) {

    int min_x = BL.x; // parse the Points
    int min_y = BL.y;
    int max_x = TR.x;
    int max_y = TR.y;
    int x, y;

    Random rd = new Random();

    /*
     * The purpose of the algorithm is to prevent any odd number integers to be randomized
     * By dividing the random number by 2 and flooring it will force the random number to be an even integer
     * Then multiplying it by 2 will bring it back to its original value or +/-1 if the number was odd to begin with
     * This will make error checking a lot easier because we can take out any duplicate numbers that are being generated
     * Also not needing to worry about lines being generated right next to each other
     */
    for (int i = 0; i < HL; i++) { // draw horizontal lines
      y =
          (int) Math.floor((double) (rd.nextInt(max_y - min_y) + min_y) / 3)
              * 3; // pick a point on the y-axis to draw the horizontal line
      if (HL_list.contains(y)
          || y < min_y + 2
          || y > max_y - 2) // check to see if the y-axis generated is already in the list
      i--;
      else {
        HL_list.add(y);
        LineObject LO = new LineObject(BL.x, y, TR.x, y);
        line_list.add(LO); // put into array to check for errors
        // drawLine(BL.x,y,TR.x,y);
      }
    }

    for (int j = 0; j < VL; j++) { // draw vertical lines
      x =
          (int) Math.floor((double) (rd.nextInt(max_x - min_x) + min_x) / 3)
              * 3; // pick a point on the x-axis to draw the vertical line
      if (VL_list.contains(x) || x < min_x + 2 || x > max_x - 2) j--;
      else {
        VL_list.add(x);
        LineObject LO = new LineObject(x, BL.y, x, TR.y);
        line_list.add(LO);
        // drawLine(x,BL.y,x,TR.y);
      }
    }

    return line_list;
  }
 private int getCurrentPageFloor() {
   return (int) Math.floor(mFlipDistance / FLIP_DISTANCE_PER_PAGE);
 }