Example #1
0
 /**
  * Compile this mosaic into an optimal arrangement.
  *
  * @return true if this mosaic is used for images, false if it's empty
  */
 public boolean compile(Component progressComponent) {
   this.progressComponent = progressComponent;
   parts = partsList.toArray(new MosaicPart[partsList.size()]);
   Arrangement arrangement = new Arrangement(maxHeight, parts);
   int lastWidth = -1;
   double widthFactor = Math.log(((double) maxWidth) / minWidth);
   for (int i = 0; i < numWidths; i++) {
     int width;
     if (numWidths > 1) {
       // Increase width geometrically from minWidth to maxWidth
       double f = widthFactor * ((double) i) / (numWidths - 1);
       f = Math.exp(f) * minWidth;
       width = (int) (f + 0.5);
     } else {
       width = maxWidth;
     }
     if (width == lastWidth) {
       continue; // Don't try same width twice
     }
     lastWidth = width;
     arrangement.arrangeWithin(width);
     int pixels = arrangement.getPixelsUsed();
     if (pixels < currPixels) {
       setBestArrangement(arrangement);
     }
   }
   return currPixels > 0;
 }
Example #2
0
 //
 // Sets the best arrangement seen so far to the argument.
 // Copies all needed data from arrangement, so that Arrangement
 // can be subsequently modified.
 //
 void setBestArrangement(Arrangement arrangement) {
   currPixels = arrangement.getPixelsUsed();
   synchronized (parts) {
     arrangement.positionParts(parts);
     currWidth = arrangement.getWidthUsed();
     currHeight = arrangement.getHeightUsed();
   }
   Component c = progressComponent;
   if (c != null) {
     c.repaint(100L);
   }
 }
Example #3
0
  public static void main(String[] arg) {
    if (arg.length != 2) {
      System.out.println("Args: n p");
      System.exit(1);
    }
    int n = Integer.parseInt(arg[0]);
    int p = Integer.parseInt(arg[1]);
    Arrangement c = new Arrangement(n, p);
    int max = c.size() + 1;

    for (int i = 0; i < max; i++) {
      int[] res = c.next();
      System.out.print((i + 1) + ":");
      for (int j = 0; j < res.length; j++) {
        System.out.print(" " + res[j]);
      }
      System.out.println("");
    }
  }