Exemplo n.º 1
0
 protected void drawImageMosaic(Graphics2D g2) {
   // Break the image up into tiles. Draw each
   //   tile with its own transparency, allowing
   //   the background to show through to varying
   //   degrees.
   int side = 36;
   int width = mImage.getWidth();
   int height = mImage.getHeight();
   for (int y = 0; y < height; y += side) {
     for (int x = 0; x < width; x += side) {
       // Calculate an appropriate transparency value.
       float xBias = (float) x / (float) width;
       float yBias = (float) y / (float) height;
       float alpha = 1.0f - Math.abs(xBias - yBias);
       g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
       // Draw the subimage.
       int w = Math.min(side, width - x);
       int h = Math.min(side, height - y);
       BufferedImage tile = mImage.getSubimage(x, y, w, h);
       g2.drawImage(tile, x, y, null);
     }
   }
   // Reset the composite.
   g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
 }
Exemplo n.º 2
0
  public void method352(
      int i, int j, int ai[], int k, int ai1[], int i1, int j1, int k1, int l1, int i2) {
    try {
      int j2 = -l1 / 2;
      int k2 = -i / 2;
      int l2 = (int) (Math.sin((double) j / 326.11000000000001D) * 65536D);
      int i3 = (int) (Math.cos((double) j / 326.11000000000001D) * 65536D);
      l2 = l2 * k >> 8;
      i3 = i3 * k >> 8;
      int j3 = (i2 << 16) + (k2 * l2 + j2 * i3);
      int k3 = (i1 << 16) + (k2 * i3 - j2 * l2);
      int l3 = k1 + j1 * DrawingArea.width;
      for (j1 = 0; j1 < i; j1++) {
        int i4 = ai1[j1];
        int j4 = l3 + i4;
        int k4 = j3 + i3 * i4;
        int l4 = k3 - l2 * i4;
        for (k1 = -ai[j1]; k1 < 0; k1++) {
          DrawingArea.pixels[j4++] = myPixels[(k4 >> 16) + (l4 >> 16) * myWidth];
          k4 += i3;
          l4 -= l2;
        }

        j3 += l2;
        k3 += i3;
        l3 += DrawingArea.width;
      }

    } catch (Exception _ex) {
    }
  }
Exemplo n.º 3
0
  private void spawnRandomers() {
    for (int i = 0; i < randomN; i++) {
      float x = (float) Math.random() * width;
      float y = (float) Math.random() * height;
      float r =
          (float)
              Math.sqrt(
                  Math.pow(((Player) players.get(0)).getX() - x, 2)
                      + Math.pow(((Player) players.get(0)).getY() - x, 2));

      while (r < distanceLimit) {
        x = (float) Math.random() * width;
        y = (float) Math.random() * height;
        r =
            (float)
                Math.sqrt(
                    Math.pow(((Player) players.get(0)).getX() - x, 2)
                        + Math.pow(((Player) players.get(0)).getY() - y, 2));
      }

      enemies.add(new EnemyTypes.Random(x, y, 0.5f, borders));
    }

    spawnRandomersB = false;
  }
Exemplo n.º 4
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
Exemplo n.º 5
0
  /**
   * Reads image meta data.
   *
   * @param oimage
   * @return
   */
  public static Map<String, String> readImageData(IIOImage oimage) {
    Map<String, String> dict = new HashMap<String, String>();

    IIOMetadata imageMetadata = oimage.getMetadata();
    if (imageMetadata != null) {
      IIOMetadataNode dimNode = (IIOMetadataNode) imageMetadata.getAsTree("javax_imageio_1.0");
      NodeList nodes = dimNode.getElementsByTagName("HorizontalPixelSize");
      int dpiX;
      if (nodes.getLength() > 0) {
        float dpcWidth = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue());
        dpiX = (int) Math.round(25.4f / dpcWidth);
      } else {
        dpiX = Toolkit.getDefaultToolkit().getScreenResolution();
      }
      dict.put("dpiX", String.valueOf(dpiX));

      nodes = dimNode.getElementsByTagName("VerticalPixelSize");
      int dpiY;
      if (nodes.getLength() > 0) {
        float dpcHeight = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue());
        dpiY = (int) Math.round(25.4f / dpcHeight);
      } else {
        dpiY = Toolkit.getDefaultToolkit().getScreenResolution();
      }
      dict.put("dpiY", String.valueOf(dpiY));
    }

    return dict;
  }
Exemplo n.º 6
0
  /**
   * Spawn a character on the map
   *
   * @param MiX Minimum X value
   * @param MiY Minimum Y value
   * @param MaX Maximum X value
   * @param MaY Maximum Y value
   */
  public void Spawn(int MiX, int MiY, int MaX, int MaY) {
    double Nx = 0, Ny = 0;

    // Random coordinate
    Nx = Math.random() * MaX + MiX;
    Ny = Math.random() * MaY + MiY;

    // Store block number
    int BNum = MAP.elementAt(0).getBlockNum(Nx + W / 2, Ny + H / 2);

    // if invalid block number
    if (BNum == -1) {
      Spawn(MiX, MiY, MaX, MaY);
    }

    // if invalid surface
    else if (!isValidSurface(MAP.elementAt(0).Fill[BNum])) {
      Spawn(MiX, MiY, MaX, MaY);
    }

    // if colliding with something
    else if (this.Collision(Nx + W / 2, Ny + H / 2)) {
      Spawn(MiX, MiY, MaX, MaY);
    } else {
      X = Nx;
      Y = Ny;
    }
  }
Exemplo n.º 7
0
 /**
  * Find the distance between two characters
  *
  * @param Targ Target character
  * @return distance
  */
 public double Dist(GameObject Targ) {
   // find x squared and y squared
   double dx =
       Math.pow(((X + W / 2 * GROWTHFACTOR) - (Targ.X + Targ.W / 2 * Targ.GROWTHFACTOR)), 2);
   double dy =
       Math.pow(((Y + H / 2 * GROWTHFACTOR) - (Targ.Y + Targ.H / 2 * Targ.GROWTHFACTOR)), 2);
   // find distance
   return (Math.sqrt(dx + dy));
 }
Exemplo n.º 8
0
  public static ArthurImage multiply(ArthurImage one, ArthurImage two) {
    BufferedImage image = JavaImageMath.clone(one.bf);
    BufferedImage image2 = JavaImageMath.clone(two.bf);

    WritableRaster r1 = image.getRaster();
    WritableRaster r2 = image2.getRaster();
    int newWidth = Math.max(r1.getWidth(), r2.getWidth());
    int newHeight = Math.max(r1.getHeight(), r2.getHeight());

    BufferedImage collage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
    WritableRaster raster = collage.getRaster();

    int[] p1 = new int[3];
    int[] p2 = new int[3];
    int[] pixelArray = new int[3];
    for (int y = 0; y < newHeight; y++) {
      for (int x = 0; x < newWidth; x++) {
        p1 = null;
        p2 = null;

        if (x < r1.getWidth() && y < r1.getHeight()) {
          p1 = r1.getPixel(x, y, p1);
        }

        if (x < r2.getWidth() && y < r2.getHeight()) {
          p2 = r2.getPixel(x, y, p2);
        }

        for (int i = 0; i < 3; i++) {
          if (p1 == null && p2 == null) {
            pixelArray[i] = 0;
          } else if (p1 == null && p2 != null) {
            pixelArray[i] = p2[i];
          } else if (p1 != null && p2 == null) {
            pixelArray[i] = p1[i];
          } else {
            pixelArray[i] = (int) ((p1[i] + p2[i]) / 2);
          }
        }
        raster.setPixel(x, y, pixelArray);
      }
    }

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "X"
            + // filename can't contain the / or *characters; decide later
            two.filename.substring(0, two.filename.indexOf(".jpg"))
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(collage, outputFn);
  }
Exemplo n.º 9
0
 private void spawnBomb() {
   float x, y;
   for (int i = 0; i < bombN; i++) {
     if (Math.random() > .5) { // top/bottom
       y = (Math.random() > .5) ? borders[1] : borders[3];
       x = (float) Math.random() * borders[2] - borders[0]; // width
     } else {
       x = (Math.random() > .5) ? borders[0] : borders[2];
       y = (float) Math.random() * borders[3] - borders[1]; // height
     }
     enemies.add(new EnemyTypes.Bomb(x, y, 1f, borders, scbInstance));
   }
 }
Exemplo n.º 10
0
  private void levelSetup() {
    reset();

    switch (level) {
      case 1:
        distance = 600;
        monsterN = 0;
        randomN = 0;
        rainN = 30;
        defaultDistance = 600;
        timeLast = 10000;
        spawnCircleB = true;
        break;
      case 2:
        distance = 600;
        monsterN = 0;
        randomN = 30;
        rainN = 30;
        defaultDistance = 600;
        timeLast += 10000;
        spawnCircleB = true;
        break;
      case 3:
        distance = 600;
        monsterN = 30;
        randomN = 0;
        rainN = 0;
        defaultDistance = 600;
        timeLast += 10000;
        spawnCircleB = true;
        break;
      default:
        distance = (float) (Math.random() * 200 + 400 - level * 5);
        monsterN = (int) (Math.random() * 25 + 10 + level);
        randomN = (int) (Math.random() * 25 + 10 + level);
        rainN = (int) (Math.random() * 10 + 10 + level);
        defaultDistance = distance;
        timeLast += 5000 + level * 1000;
        spawnCircleB = true;
    }

    monsterN *= monsterMultiplier;
    randomN *= monsterMultiplier;
    spawnMonsterB = true;
    spawnRandomersB = true;
    spawnIncrease = true;
    spawnRainB = true;
  }
Exemplo n.º 11
0
  /** *****************************Connected Component Recursive ***************************** */
  void connect(int y, int x) {

    if (conect_output[y][x] == 0) {
      conect_output[y][x] = 175;
      obj_size++;

      // System.out.println("Size :" +obj_size);
      s = x + 1;
      t = y;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }

      s = x;
      t = y - 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x + 1;
      t = y - 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x + 1;
      t = y + 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x - 1;
      t = y - 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x - 1;
      t = y + 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x + 1;
      t = y;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x - 1;
      t = y;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
    }
  }
Exemplo n.º 12
0
  public static ArthurImage multiply(
      ArthurImage one, ArthurNumber two) { // change to ArthurNumber later
    double f = Math.abs(two.val);
    // get image
    BufferedImage image = JavaImageMath.clone(one.bf);

    // manipulate image
    WritableRaster raster = image.getRaster();
    int width = (int) (raster.getWidth() * f);
    int height = (int) (raster.getHeight() * f);

    BufferedImage collage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = collage.createGraphics();
    g2d.drawImage(image, 0, 0, width, height, null);
    g2d.dispose();

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "X"
            + // filename can't contain the / or *characters; decide later
            f
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(collage, outputFn);
  }
Exemplo n.º 13
0
  /** Prototype give player a leveled up look */
  public void Opify(double Fac) {

    for (int i = 0; i < imgCHARAC.getWidth(); i++) {
      for (int j = 0; j < imgCHARAC.getHeight(); j++) {
        if (imgCHARAC.getRGB(i, j) != imgCHARAC.getRGB(2, 2)) {
          imgCHARAC.setRGB(i, j, (int) Math.round(imgCHARAC.getRGB(i, j) * Fac));
        }
      }
    }
  }
Exemplo n.º 14
0
  /**
   * do damage to character
   *
   * @param Dmg Amount of Damage
   */
  public void Damage(int Dmg, int Type) {
    // If character is already dead then dont do damage
    if (ISDEAD) return;

    // Do damage
    if (Type == 1) {
      // DAMAGE FROM PHYSICAL ATTACK
      if (STATS.ARMOR > Dmg) return;
      HEALTH = HEALTH - Dmg + STATS.ARMOR;
    } else if (Type == 2) {
      // DAMAGE FROM MAGIC ATTACK
      if (STATS.MAGIC_RESIST > Dmg) return;
      HEALTH = HEALTH - Dmg + STATS.MAGIC_RESIST;
    }
    // If an Npc then run and hide
    if (NAI != null) {
      NAI.State = "alarmed";
    }

    // Death condition
    if (HEALTH <= 0) {
      // If player is dead
      if (this.CLASS.equals("Player")) {

        HEALTH = 0;

        // Quit game
        JOptionPane.showMessageDialog(null, "You are dead");
        X = 100;
        Y = 100;
        Opify(50);
        HEALTH = (int) MAX_HEALTH;

      } else {
        // If other character
        // set Death stats
        ISDEAD = true;
        HEALTH = 0;
        // display death
        CLASS = Cl + " (Dead)";

        // Rot effect
        for (int i = 0; i < imgCHARAC.getWidth(); i++) {
          for (int j = 0; j < imgCHARAC.getHeight(); j++) {
            imgCHARAC.setRGB(i, j, imgCHARAC.getRGB(i, j) * (int) Math.pow(3, 3));
          }
        }

        // Make inventory open to looting
        INVENTORY.OPEN_INVEN = true;
      }
    }
  }
Exemplo n.º 15
0
 static BufferedImage addMagnitudes(BufferedImage img1, BufferedImage img2) {
   BufferedImage dst = new BufferedImage(img1.getWidth(), img1.getHeight(), img1.getType());
   for (int y = 0; y < img1.getHeight(); ++y) {
     for (int x = 0; x < img1.getWidth(); ++x) {
       int rgb1 = img1.getRGB(x, y);
       int rgb2 = img2.getRGB(x, y);
       int r1 = (rgb1 & 0x00FF0000) >> 16;
       int r2 = (rgb2 & 0x00FF0000) >> 16;
       int r = (int) (Math.sqrt(r1 * r1 + r2 * r2) / Math.sqrt(2.0));
       if (r > 255) r = 255;
       if (r < 0) r = 0;
       int g1 = (rgb1 & 0x0000FF00) >> 8;
       int g2 = (rgb2 & 0x0000FF00) >> 8;
       int g = (int) (Math.sqrt(g1 * g1 + g2 * g2) / Math.sqrt(2.0));
       if (g > 255) g = 255;
       if (g < 0) g = 0;
       int b1 = rgb1 & 0x000000FF;
       int b2 = rgb2 & 0x000000FF;
       int b = (int) (Math.sqrt(b1 * b1 + b2 * b2) / Math.sqrt(2.0));
       if (b > 255) b = 255;
       if (b < 0) b = 0;
       int rgb = b + (g << 8) + (r << 16);
       dst.setRGB(x, y, rgb);
     }
   }
   return dst;
 }
Exemplo n.º 16
0
  public Color getColorAt(double x, double y) {
    int col = img.getRGB((int) x, (int) y);
    double r = col >> 16 & 0xff;
    double g = col >> 8 & 0xff;
    double b = col & 0xff;

    int col_r = img.getRGB((int) x + 1, (int) y);
    double rr = col_r >> 16 & 0xff;
    double gr = col_r >> 8 & 0xff;
    double br = col_r & 0xff;

    double fact = x - Math.floor(x);

    double rf = r + (rr - r) * fact;
    double gf = g + (gr - g) * fact;
    double bf = b + (br - b) * fact;

    col = img.getRGB((int) x, (int) y + 1);
    r = col >> 16 & 0xff;
    g = col >> 8 & 0xff;
    b = col & 0xff;

    col_r = img.getRGB((int) x + 1, (int) y + 1);
    rr = col_r >> 16 & 0xff;
    gr = col_r >> 8 & 0xff;
    br = col_r & 0xff;

    double rf2 = r + (rr - r) * fact;
    double gf2 = g + (gr - g) * fact;
    double bf2 = b + (br - b) * fact;

    fact = y - Math.floor(y);

    double rff = rf + (rf2 - rf) * fact;
    double gff = gf + (gf2 - gf) * fact;
    double bff = bf + (bf2 - bf) * fact;

    return new Color((int) rff, (int) gff, (int) bff);
  }
Exemplo n.º 17
0
  public void method353(int i, double d, int l1) {
    // all of the following were parameters
    int j = 15;
    int k = 20;
    int l = 15;
    int j1 = 256;
    int k1 = 20;
    // all of the previous were parameters
    try {
      int i2 = -k / 2;
      int j2 = -k1 / 2;
      int k2 = (int) (Math.sin(d) * 65536D);
      int l2 = (int) (Math.cos(d) * 65536D);
      k2 = k2 * j1 >> 8;
      l2 = l2 * j1 >> 8;
      int i3 = (l << 16) + (j2 * k2 + i2 * l2);
      int j3 = (j << 16) + (j2 * l2 - i2 * k2);
      int k3 = l1 + i * DrawingArea.width;
      for (i = 0; i < k1; i++) {
        int l3 = k3;
        int i4 = i3;
        int j4 = j3;
        for (l1 = -k; l1 < 0; l1++) {
          int k4 = myPixels[(i4 >> 16) + (j4 >> 16) * myWidth];
          if (k4 != 0) DrawingArea.pixels[l3++] = k4;
          else l3++;
          i4 += l2;
          j4 -= k2;
        }

        i3 += k2;
        j3 += l2;
        k3 += DrawingArea.width;
      }

    } catch (Exception _ex) {
    }
  }
Exemplo n.º 18
0
 /**
  * All other write methods delegate their work to here.
  */
 public void write(OutputStream out, java.util.List<Figure> figures) throws IOException {
     Rectangle2D.Double drawingRect = null;
     
     for (Figure f : figures) {
         if (drawingRect == null) {
             drawingRect = f.getBounds();
         } else {
             drawingRect.add(f.getBounds());
         }
     }
     
     AffineTransform drawingTransform = new AffineTransform();
     drawingTransform.translate(
             -Math.min(0, drawingRect.x),
             -Math.min(0, drawingRect.y)
             );
     
     write(out, figures, drawingTransform,
             new Dimension(
             (int) (Math.abs(drawingRect.x) + drawingRect.width),
             (int) (Math.abs(drawingRect.y) + drawingRect.height))
             );
 }
Exemplo n.º 19
0
  private void spawnCircles() {
    if (circular) {
      for (int i = 0; i < ballN; i++) {
        double degree = Math.random() * 2 * Math.PI;
        float x = ((Player) players.get(0)).getX() + distance * (float) Math.sin(degree * i);
        float y = ((Player) players.get(0)).getY() + distance * (float) Math.cos(degree * i);
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    } else {
      for (int i = 1; i < (ballN / 2); i++) {
        float x = (i * 2 * width) / (ballN);
        float y = 0;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }

      for (int i = (ballN / 2) + 1; i < ballN; i++) {
        float x = ((i - ballN / 2) * 2 * width) / ballN;
        float y = height;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    }
    spawnIncrease = false;
  }
Exemplo n.º 20
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and rectangle.
  *
  * @return Returns true, if the rect is inside of the image bounds.
  */
 private boolean writeRectAttributes(IXMLElement elem, SVGFigure f, Rectangle2D.Double rect) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType()
             ) {
         
         Point2D.Double start = new Point2D.Double(rect.x, rect.y);
         Point2D.Double end = new Point2D.Double(rect.x + rect.width, rect.y + rect.height);
         t.transform(start, start);
         t.transform(end, end);
         Rectangle r = new Rectangle(
                 (int) Math.min(start.x, end.x),
                 (int) Math.min(start.y, end.y),
                 (int) Math.abs(start.x - end.x),
                 (int) Math.abs(start.y - end.y)
                 );
         
         elem.setAttribute("shape", "rect");
         elem.setAttribute("coords",
                 r.x + ","+
                 r.y + ","+
                 (r.x + r.width) + ","+
                 (r.y + r.height)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(r);
     } else {
         return writePolyAttributes(elem, f, (Shape) rect);
     }
 }
Exemplo n.º 21
0
  public static ArthurImage addition(ArthurImage one, ArthurImage two, int op) {
    BufferedImage image = JavaImageMath.clone(one.bf);
    BufferedImage image2 = JavaImageMath.clone(two.bf);

    WritableRaster r1 = image.getRaster();
    WritableRaster r2 = image2.getRaster();
    int newWidth = r1.getWidth() + r2.getWidth();
    int newHeight = Math.max(r1.getHeight(), r2.getHeight());

    BufferedImage collage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = collage.createGraphics();
    // g2d.setBackground(Color.BLACK);
    g2d.drawImage(image, 0, 0, null);
    g2d.drawImage(image2, r1.getWidth(), 0, null);
    g2d.dispose();

    // save image
    String outputFn;
    if (op == 0) {
      outputFn =
          one.filename.substring(0, one.filename.indexOf(".jpg"))
              + "+"
              + two.filename.substring(0, two.filename.indexOf(".jpg"))
              + counter
              + ".jpg";
    } else {
      outputFn =
          two.filename.substring(0, two.filename.indexOf(".jpg"))
              + "-"
              + one.filename.substring(0, one.filename.indexOf(".jpg"))
              + counter
              + ".jpg";
    }

    counter++;

    return new ArthurImage(collage, outputFn);
  }
Exemplo n.º 22
0
  public static ArthurImage divide(
      ArthurImage one, ArthurNumber two) { // change to ArthurNumber later
    int f = Math.abs(two.intval());
    // get image
    BufferedImage image = JavaImageMath.clone(one.bf);

    // manipulate image
    WritableRaster raster = image.getRaster();
    int width0 = raster.getWidth();
    int height0 = raster.getHeight();
    int width = width0 / f;
    int height = height0 / f;

    BufferedImage temp = new BufferedImage(width * f, height * f, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = temp.createGraphics();
    for (int i = 0; i < f; i++) {
      for (int j = 0; j < f; j++) {
        g2d.drawImage(image, j * width, i * height, width, height, null);
      }
    }
    g2d.dispose();
    BufferedImage collage = new BufferedImage(width0, height0, BufferedImage.TYPE_INT_RGB);
    g2d = collage.createGraphics();
    g2d.drawImage(temp, 0, 0, width0, height0, null);
    g2d.dispose();

    // save image
    String outputFn =
        one.filename.substring(0, one.filename.indexOf(".jpg"))
            + "D"
            + // filename can't contain the / or *characters; decide later
            f
            + counter
            + ".jpg";
    counter++;

    return new ArthurImage(collage, outputFn);
  }
Exemplo n.º 23
0
  /** Get an image based on index numbers */
  public BufferedImage getIndexedImage(
      int x, int y, int zoom, int cacheZoom, GMapListener listener) {

    if (listener != null) {
      if (!getGDataSource().isCached(x, y, zoom)) {
        listener.updateGMapPainting();
        listener.updateGMapMessage(GMap.MESSAGE_DOWNLOADING);
      } else {
        listener.updateGMapMessage(GMap.MESSAGE_PAINTING);
      }
    }

    BufferedImage thumbImage = getGDataSource().getImage(x, y, zoom, true);

    if (thumbImage == null) return defaultImage;

    // if we dont have to paint cache, return here
    if (cacheZoom == (GPhysicalPoint.MIN_ZOOM - 1) || cacheZoom >= zoom) return thumbImage;

    BufferedImage paintedImage =
        new BufferedImage(
            GDataSource.sourceSize.width,
            GDataSource.sourceSize.height,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = paintedImage.createGraphics();
    graphics2D.drawImage(
        thumbImage, 0, 0, GDataSource.sourceSize.width, GDataSource.sourceSize.height, null);

    // now lets move to painting the cache
    double imageNum = Math.pow(2, zoom - cacheZoom);

    // draw cache lines
    int startX = (int) (imageNum * x);
    int startY = (int) (imageNum * y);

    // get composite to restore later, set new transparent composite
    Composite originalComposite = graphics2D.getComposite();
    graphics2D.setComposite(opacity40);

    // draw grid
    for (int i = 0; i < imageNum; i++) {
      for (int j = 0; j < imageNum; j++) {
        // points
        Point upperLeft =
            new Point(
                (int) (GDataSource.sourceSize.width / imageNum) * i,
                (int) (GDataSource.sourceSize.height / imageNum) * j);
        Dimension size =
            new Dimension(
                (int) (GDataSource.sourceSize.width / imageNum),
                (int) (GDataSource.sourceSize.height / imageNum));

        // draw lines
        graphics2D.setColor(new Color(100, 100, 100));
        graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x + size.width, upperLeft.y);
        graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x, upperLeft.y + size.height);

        // check if file exists
        if (getGDataSource().isCached(startX + i, startY + j, cacheZoom))
          graphics2D.setColor(Color.RED);
        else graphics2D.setColor(new Color(155, 155, 155));

        // shade rectangle
        graphics2D.fillRect(upperLeft.x, upperLeft.y, size.width, size.height);
      }
    }

    // restore composite
    graphics2D.setComposite(originalComposite);

    return paintedImage;
  }
Exemplo n.º 24
0
  private void prepareToDraw() {

    if (forwardSlot0 != null) {
      forwardSlot0.setCgview(p);
      forwardSlot0.setFeatureThickness(featureThickness);
    }
    if (forwardSlot1 != null) {
      forwardSlot1.setCgview(p);
      forwardSlot1.setFeatureThickness(featureThickness);
    }
    if (forwardSlot2 != null) {
      forwardSlot2.setCgview(p);
      forwardSlot2.setFeatureThickness(featureThickness);
    }
    if (forwardSlot3 != null) {
      forwardSlot3.setCgview(p);
      forwardSlot3.setFeatureThickness(featureThickness);
    }
    if (forwardSlot4 != null) {
      forwardSlot4.setCgview(p);
      forwardSlot4.setFeatureThickness(featureThickness);
    }
    if (forwardSlot5 != null) {
      forwardSlot5.setCgview(p);
      forwardSlot5.setFeatureThickness(featureThickness);
    }
    if (forwardSlot6 != null) {
      forwardSlot6.setCgview(p);
      forwardSlot6.setFeatureThickness(featureThickness);
    }
    if (forwardSlot7 != null) {
      forwardSlot7.setCgview(p);
      forwardSlot7.setFeatureThickness(featureThickness);
    }

    if (reverseSlot0 != null) {
      reverseSlot0.setCgview(p);
      reverseSlot0.setFeatureThickness(featureThickness);
    }
    if (reverseSlot1 != null) {
      reverseSlot1.setCgview(p);
      reverseSlot1.setFeatureThickness(featureThickness);
    }
    if (reverseSlot2 != null) {
      reverseSlot2.setCgview(p);
      reverseSlot2.setFeatureThickness(featureThickness);
    }
    if (reverseSlot3 != null) {
      reverseSlot3.setCgview(p);
      reverseSlot3.setFeatureThickness(featureThickness);
    }
    if (reverseSlot4 != null) {
      reverseSlot4.setCgview(p);
      reverseSlot4.setFeatureThickness(featureThickness);
    }
    if (reverseSlot5 != null) {
      reverseSlot5.setCgview(p);
      reverseSlot5.setFeatureThickness(featureThickness);
    }
    if (reverseSlot6 != null) {
      reverseSlot6.setCgview(p);
      reverseSlot6.setFeatureThickness(featureThickness);
    }
    if (reverseSlot7 != null) {
      reverseSlot7.setCgview(p);
      reverseSlot7.setFeatureThickness(featureThickness);
    }

    if (restrictionSlot != null) {
      restrictionSlot.setCgview(p);
      restrictionSlot.setFeatureThickness(featureThickness);
    }

    // send settings to p
    if (showTitle) {
      p.setTitle(title);
    }
    p.setWidth(imageWidth);
    p.setHeight(imageHeight);
    p.setLabelsToKeep(MAXLABELS);
    p.setDrawTickMarks(drawTickMarks);
    p.setTitleFont(titleFont);
    p.setLabelFont(labelFont);
    p.setFeatureThickness(featureThickness);
    p.setBackboneThickness(backboneThickness);
    p.setFeatureSlotSpacing(featureSpacing);
    p.setLegendFont(legendFont);
    p.setTickLength(tickLength);
    p.setLabelLineLength(labelLineLength);
    p.setLabelPlacementQuality(labelPlacementQuality);
    p.setUseColoredLabelBackgrounds(useColoredLabelBackground);
    p.setShowBorder(showBorder);
    p.setShowShading(showShading);
    p.setShadingProportion(shadingProportion);
    p.setUseInnerLabels(useInnerLabels);
    p.setMoveInnerLabelsToOuter(moveInnerLabelsToOuter);
    p.setWarningFont(rulerFont);
    p.setRulerFont(rulerFont);

    // if not drawing labels, don't show message.
    if (!(showLabels)) {
      p.setShowWarning(false);
    }

    // set backboneRadius based on smallest image dimension
    int smallestDimension = Math.min(imageWidth, imageHeight);
    if (smallestDimension <= 750) {
      p.setBackboneRadius(0.50d * (double) smallestDimension / 2.0d);
    } else {
      p.setBackboneRadius(0.50d * 750.0d / 2.0d);
    }

    // check coloredLabels
    if (!(useColoredLabels)) {
      if (colorScheme == REGULAR) {
        p.setGlobalLabelColor((Color) MAP_ITEM_COLORS.get("titleFont"));
      } else if (colorScheme == INVERSE) {
        p.setGlobalLabelColor((Color) MAP_ITEM_COLORS_INVERSE.get("titleFont"));
      }
    }

    // set map item colors
    if (colorScheme == REGULAR) {
      p.setLongTickColor((Color) MAP_ITEM_COLORS.get("tick"));
      p.setShortTickColor((Color) MAP_ITEM_COLORS.get("partialTick"));
      p.setZeroTickColor((Color) MAP_ITEM_COLORS.get("zeroLine"));
      p.setRulerFontColor((Color) MAP_ITEM_COLORS.get("rulerFont"));
      p.setBackboneColor((Color) MAP_ITEM_COLORS.get("backbone"));
      p.setTitleFontColor((Color) MAP_ITEM_COLORS.get("titleFont"));
      p.setWarningFontColor((Color) MAP_ITEM_COLORS.get("titleFont"));
      p.setBackgroundColor((Color) MAP_ITEM_COLORS.get("background"));
    } else if (colorScheme == INVERSE) {
      p.setLongTickColor((Color) MAP_ITEM_COLORS_INVERSE.get("tick"));
      p.setShortTickColor((Color) MAP_ITEM_COLORS_INVERSE.get("partialTick"));
      p.setZeroTickColor((Color) MAP_ITEM_COLORS_INVERSE.get("zeroLine"));
      p.setRulerFontColor((Color) MAP_ITEM_COLORS_INVERSE.get("rulerFont"));
      p.setBackboneColor((Color) MAP_ITEM_COLORS_INVERSE.get("backbone"));
      p.setTitleFontColor((Color) MAP_ITEM_COLORS_INVERSE.get("titleFont"));
      p.setWarningFontColor((Color) MAP_ITEM_COLORS_INVERSE.get("titleFont"));
      p.setBackgroundColor((Color) MAP_ITEM_COLORS_INVERSE.get("background"));
    }

    // build legend
    if ((showLegend) && (DRAW_LEGEND_ITEMS.size() > 0)) {
      // create legend
      legend = new Legend(p);
      legend.setAllowLabelClash(allowLabelClashLegend);
      legend.setBackgroundOpacity(0.5f);
      legend.setFont(legendFont);
      legend.setPosition(legendPosition);
      if (colorScheme == REGULAR) {
        legend.setBackgroundColor((Color) MAP_ITEM_COLORS.get("background"));
        legend.setFontColor((Color) MAP_ITEM_COLORS.get("titleFont"));
      } else if (colorScheme == INVERSE) {
        legend.setBackgroundColor((Color) MAP_ITEM_COLORS_INVERSE.get("background"));
        legend.setFontColor((Color) MAP_ITEM_COLORS_INVERSE.get("titleFont"));
      }

      LegendItem legendItem;

      Enumeration legendEntries = DRAW_LEGEND_ITEMS.keys();
      ArrayList list = new ArrayList();
      while (legendEntries.hasMoreElements()) {
        list.add(legendEntries.nextElement());
      }
      Collections.sort(list);
      Iterator i = list.iterator();

      while (i.hasNext()) {
        String key = (String) i.next();
        legendItem = new LegendItem(legend);
        legendItem.setDrawSwatch(SWATCH_SHOW);
        legendItem.setLabel((String) LEGEND_ITEM_NAMES.get(key));
        if (colorScheme == REGULAR) {
          legendItem.setSwatchColor((Color) FEATURE_COLORS.get(key));
        } else if (colorScheme == INVERSE) {
          legendItem.setSwatchColor((Color) FEATURE_COLORS_INVERSE.get(key));
        }
      }
    }

    // set message
    if (showMessage) {
      legend = new Legend(p);
      legend.setAllowLabelClash(false);
      legend.setBackgroundOpacity(0.5f);
      legend.setFont(messageFont);
      legend.setPosition(LEGEND_LOWER_RIGHT);
      LegendItem legendItem;

      if (colorScheme == REGULAR) {
        legend.setBackgroundColor((Color) MAP_ITEM_COLORS.get("background"));
        legend.setFontColor((Color) MAP_ITEM_COLORS.get("titleFont"));
        legendItem = new LegendItem(legend);
        legendItem.setLabel(message);
        legendItem.setDrawSwatch(SWATCH_NO_SHOW);
      } else if (colorScheme == INVERSE) {
        legend.setBackgroundColor((Color) MAP_ITEM_COLORS_INVERSE.get("background"));
        legend.setFontColor((Color) MAP_ITEM_COLORS_INVERSE.get("titleFont"));
        legendItem = new LegendItem(legend);
        legendItem.setLabel(message);
        legendItem.setDrawSwatch(SWATCH_NO_SHOW);
      }
    }
  }
Exemplo n.º 25
0
  public void build_bricks() {

    ImagePlus imp;
    ImagePlus orgimp;
    ImageStack stack;
    FileInfo finfo;

    if (lvImgTitle.isEmpty()) return;
    orgimp = WindowManager.getImage(lvImgTitle.get(0));
    imp = orgimp;

    finfo = imp.getFileInfo();
    if (finfo == null) return;

    int[] dims = imp.getDimensions();
    int imageW = dims[0];
    int imageH = dims[1];
    int nCh = dims[2];
    int imageD = dims[3];
    int nFrame = dims[4];
    int bdepth = imp.getBitDepth();
    double xspc = finfo.pixelWidth;
    double yspc = finfo.pixelHeight;
    double zspc = finfo.pixelDepth;
    double z_aspect = Math.max(xspc, yspc) / zspc;

    int orgW = imageW;
    int orgH = imageH;
    int orgD = imageD;
    double orgxspc = xspc;
    double orgyspc = yspc;
    double orgzspc = zspc;

    lv = lvImgTitle.size();
    if (filetype == "JPEG") {
      for (int l = 0; l < lv; l++) {
        if (WindowManager.getImage(lvImgTitle.get(l)).getBitDepth() != 8) {
          IJ.error("A SOURCE IMAGE MUST BE 8BIT GLAYSCALE");
          return;
        }
      }
    }

    // calculate levels
    /*		int baseXY = 256;
    		int baseZ = 256;

    		if (z_aspect < 0.5) baseZ = 128;
    		if (z_aspect > 2.0) baseXY = 128;
    		if (z_aspect >= 0.5 && z_aspect < 1.0) baseZ = (int)(baseZ*z_aspect);
    		if (z_aspect > 1.0 && z_aspect <= 2.0) baseXY = (int)(baseXY/z_aspect);

    		IJ.log("Z_aspect: " + z_aspect);
    		IJ.log("BaseXY: " + baseXY);
    		IJ.log("BaseZ: " + baseZ);
    */

    int baseXY = 256;
    int baseZ = 128;
    int dbXY = Math.max(orgW, orgH) / baseXY;
    if (Math.max(orgW, orgH) % baseXY > 0) dbXY *= 2;
    int dbZ = orgD / baseZ;
    if (orgD % baseZ > 0) dbZ *= 2;
    lv = Math.max(log2(dbXY), log2(dbZ)) + 1;

    int ww = orgW;
    int hh = orgH;
    int dd = orgD;
    for (int l = 0; l < lv; l++) {
      int bwnum = ww / baseXY;
      if (ww % baseXY > 0) bwnum++;
      int bhnum = hh / baseXY;
      if (hh % baseXY > 0) bhnum++;
      int bdnum = dd / baseZ;
      if (dd % baseZ > 0) bdnum++;

      if (bwnum % 2 == 0) bwnum++;
      if (bhnum % 2 == 0) bhnum++;
      if (bdnum % 2 == 0) bdnum++;

      int bw = (bwnum <= 1) ? ww : ww / bwnum + 1 + (ww % bwnum > 0 ? 1 : 0);
      int bh = (bhnum <= 1) ? hh : hh / bhnum + 1 + (hh % bhnum > 0 ? 1 : 0);
      int bd = (bdnum <= 1) ? dd : dd / bdnum + 1 + (dd % bdnum > 0 ? 1 : 0);

      bwlist.add(bw);
      bhlist.add(bh);
      bdlist.add(bd);

      IJ.log("LEVEL: " + l);
      IJ.log("  width: " + ww);
      IJ.log("  hight: " + hh);
      IJ.log("  depth: " + dd);
      IJ.log("  bw: " + bw);
      IJ.log("  bh: " + bh);
      IJ.log("  bd: " + bd);

      int xyl2 = Math.max(ww, hh) / baseXY;
      if (Math.max(ww, hh) % baseXY > 0) xyl2 *= 2;
      if (lv - 1 - log2(xyl2) <= l) {
        ww /= 2;
        hh /= 2;
      }
      IJ.log("  xyl2: " + (lv - 1 - log2(xyl2)));

      int zl2 = dd / baseZ;
      if (dd % baseZ > 0) zl2 *= 2;
      if (lv - 1 - log2(zl2) <= l) dd /= 2;
      IJ.log("  zl2: " + (lv - 1 - log2(zl2)));

      if (l < lv - 1) {
        lvImgTitle.add(lvImgTitle.get(0) + "_level" + (l + 1));
        IJ.selectWindow(lvImgTitle.get(0));
        IJ.run(
            "Scale...",
            "x=- y=- z=- width="
                + ww
                + " height="
                + hh
                + " depth="
                + dd
                + " interpolation=Bicubic average process create title="
                + lvImgTitle.get(l + 1));
      }
    }

    for (int l = 0; l < lv; l++) {
      IJ.log(lvImgTitle.get(l));
    }

    Document doc = newXMLDocument();
    Element root = doc.createElement("BRK");
    root.setAttribute("version", "1.0");
    root.setAttribute("nLevel", String.valueOf(lv));
    root.setAttribute("nChannel", String.valueOf(nCh));
    root.setAttribute("nFrame", String.valueOf(nFrame));
    doc.appendChild(root);

    for (int l = 0; l < lv; l++) {
      IJ.showProgress(0.0);

      int[] dims2 = imp.getDimensions();
      IJ.log(
          "W: "
              + String.valueOf(dims2[0])
              + " H: "
              + String.valueOf(dims2[1])
              + " C: "
              + String.valueOf(dims2[2])
              + " D: "
              + String.valueOf(dims2[3])
              + " T: "
              + String.valueOf(dims2[4])
              + " b: "
              + String.valueOf(bdepth));

      bw = bwlist.get(l).intValue();
      bh = bhlist.get(l).intValue();
      bd = bdlist.get(l).intValue();

      boolean force_pow2 = false;
      /*			if(IsPowerOf2(bw) && IsPowerOf2(bh) && IsPowerOf2(bd)) force_pow2 = true;

      			if(force_pow2){
      				//force pow2
      				if(Pow2(bw) > bw) bw = Pow2(bw)/2;
      				if(Pow2(bh) > bh) bh = Pow2(bh)/2;
      				if(Pow2(bd) > bd) bd = Pow2(bd)/2;
      			}

      			if(bw > imageW) bw = (Pow2(imageW) == imageW) ? imageW : Pow2(imageW)/2;
      			if(bh > imageH) bh = (Pow2(imageH) == imageH) ? imageH : Pow2(imageH)/2;
      			if(bd > imageD) bd = (Pow2(imageD) == imageD) ? imageD : Pow2(imageD)/2;

      */
      if (bw > imageW) bw = imageW;
      if (bh > imageH) bh = imageH;
      if (bd > imageD) bd = imageD;

      if (bw <= 1 || bh <= 1 || bd <= 1) break;

      if (filetype == "JPEG" && (bw < 8 || bh < 8)) break;

      Element lvnode = doc.createElement("Level");
      lvnode.setAttribute("lv", String.valueOf(l));
      lvnode.setAttribute("imageW", String.valueOf(imageW));
      lvnode.setAttribute("imageH", String.valueOf(imageH));
      lvnode.setAttribute("imageD", String.valueOf(imageD));
      lvnode.setAttribute("xspc", String.valueOf(xspc));
      lvnode.setAttribute("yspc", String.valueOf(yspc));
      lvnode.setAttribute("zspc", String.valueOf(zspc));
      lvnode.setAttribute("bitDepth", String.valueOf(bdepth));
      root.appendChild(lvnode);

      Element brksnode = doc.createElement("Bricks");
      brksnode.setAttribute("brick_baseW", String.valueOf(bw));
      brksnode.setAttribute("brick_baseH", String.valueOf(bh));
      brksnode.setAttribute("brick_baseD", String.valueOf(bd));
      lvnode.appendChild(brksnode);

      ArrayList<Brick> bricks = new ArrayList<Brick>();
      int mw, mh, md, mw2, mh2, md2;
      double tx0, ty0, tz0, tx1, ty1, tz1;
      double bx0, by0, bz0, bx1, by1, bz1;
      for (int k = 0; k < imageD; k += bd) {
        if (k > 0) k--;
        for (int j = 0; j < imageH; j += bh) {
          if (j > 0) j--;
          for (int i = 0; i < imageW; i += bw) {
            if (i > 0) i--;
            mw = Math.min(bw, imageW - i);
            mh = Math.min(bh, imageH - j);
            md = Math.min(bd, imageD - k);

            if (force_pow2) {
              mw2 = Pow2(mw);
              mh2 = Pow2(mh);
              md2 = Pow2(md);
            } else {
              mw2 = mw;
              mh2 = mh;
              md2 = md;
            }

            if (filetype == "JPEG") {
              if (mw2 < 8) mw2 = 8;
              if (mh2 < 8) mh2 = 8;
            }

            tx0 = i == 0 ? 0.0d : ((mw2 - mw + 0.5d) / mw2);
            ty0 = j == 0 ? 0.0d : ((mh2 - mh + 0.5d) / mh2);
            tz0 = k == 0 ? 0.0d : ((md2 - md + 0.5d) / md2);

            tx1 = 1.0d - 0.5d / mw2;
            if (mw < bw) tx1 = 1.0d;
            if (imageW - i == bw) tx1 = 1.0d;

            ty1 = 1.0d - 0.5d / mh2;
            if (mh < bh) ty1 = 1.0d;
            if (imageH - j == bh) ty1 = 1.0d;

            tz1 = 1.0d - 0.5d / md2;
            if (md < bd) tz1 = 1.0d;
            if (imageD - k == bd) tz1 = 1.0d;

            bx0 = i == 0 ? 0.0d : (i + 0.5d) / (double) imageW;
            by0 = j == 0 ? 0.0d : (j + 0.5d) / (double) imageH;
            bz0 = k == 0 ? 0.0d : (k + 0.5d) / (double) imageD;

            bx1 = Math.min((i + bw - 0.5d) / (double) imageW, 1.0d);
            if (imageW - i == bw) bx1 = 1.0d;

            by1 = Math.min((j + bh - 0.5d) / (double) imageH, 1.0d);
            if (imageH - j == bh) by1 = 1.0d;

            bz1 = Math.min((k + bd - 0.5d) / (double) imageD, 1.0d);
            if (imageD - k == bd) bz1 = 1.0d;

            int x, y, z;
            x = i - (mw2 - mw);
            y = j - (mh2 - mh);
            z = k - (md2 - md);
            bricks.add(
                new Brick(
                    x, y, z, mw2, mh2, md2, 0, 0, tx0, ty0, tz0, tx1, ty1, tz1, bx0, by0, bz0, bx1,
                    by1, bz1));
          }
        }
      }

      Element fsnode = doc.createElement("Files");
      lvnode.appendChild(fsnode);

      stack = imp.getStack();

      int totalbricknum = nFrame * nCh * bricks.size();
      int curbricknum = 0;
      for (int f = 0; f < nFrame; f++) {
        for (int ch = 0; ch < nCh; ch++) {
          int sizelimit = bdsizelimit * 1024 * 1024;
          int bytecount = 0;
          int filecount = 0;
          int pd_bufsize = Math.max(sizelimit, bw * bh * bd * bdepth / 8);
          byte[] packed_data = new byte[pd_bufsize];
          String base_dataname =
              basename
                  + "_Lv"
                  + String.valueOf(l)
                  + "_Ch"
                  + String.valueOf(ch)
                  + "_Fr"
                  + String.valueOf(f);
          String current_dataname = base_dataname + "_data" + filecount;

          Brick b_first = bricks.get(0);
          if (b_first.z_ != 0) IJ.log("warning");
          int st_z = b_first.z_;
          int ed_z = b_first.z_ + b_first.d_;
          LinkedList<ImageProcessor> iplist = new LinkedList<ImageProcessor>();
          for (int s = st_z; s < ed_z; s++)
            iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));

          //					ImagePlus test;
          //					ImageStack tsst;
          //					test = NewImage.createByteImage("test", imageW, imageH, imageD,
          // NewImage.FILL_BLACK);
          //					tsst = test.getStack();
          for (int i = 0; i < bricks.size(); i++) {
            Brick b = bricks.get(i);

            if (ed_z > b.z_ || st_z < b.z_ + b.d_) {
              if (b.z_ > st_z) {
                for (int s = 0; s < b.z_ - st_z; s++) iplist.pollFirst();
                st_z = b.z_;
              } else if (b.z_ < st_z) {
                IJ.log("warning");
                for (int s = st_z - 1; s > b.z_; s--)
                  iplist.addFirst(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
                st_z = b.z_;
              }

              if (b.z_ + b.d_ > ed_z) {
                for (int s = ed_z; s < b.z_ + b.d_; s++)
                  iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
                ed_z = b.z_ + b.d_;
              } else if (b.z_ + b.d_ < ed_z) {
                IJ.log("warning");
                for (int s = 0; s < ed_z - (b.z_ + b.d_); s++) iplist.pollLast();
                ed_z = b.z_ + b.d_;
              }
            } else {
              IJ.log("warning");
              iplist.clear();
              st_z = b.z_;
              ed_z = b.z_ + b.d_;
              for (int s = st_z; s < ed_z; s++)
                iplist.add(stack.getProcessor(imp.getStackIndex(ch + 1, s + 1, f + 1)));
            }

            if (iplist.size() != b.d_) {
              IJ.log("Stack Error");
              return;
            }

            //						int zz = st_z;

            int bsize = 0;
            byte[] bdata = new byte[b.w_ * b.h_ * b.d_ * bdepth / 8];
            Iterator<ImageProcessor> ipite = iplist.iterator();
            while (ipite.hasNext()) {

              //							ImageProcessor tsip = tsst.getProcessor(zz+1);

              ImageProcessor ip = ipite.next();
              ip.setRoi(b.x_, b.y_, b.w_, b.h_);
              if (bdepth == 8) {
                byte[] data = (byte[]) ip.crop().getPixels();
                System.arraycopy(data, 0, bdata, bsize, data.length);
                bsize += data.length;
              } else if (bdepth == 16) {
                ByteBuffer buffer = ByteBuffer.allocate(b.w_ * b.h_ * bdepth / 8);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                short[] data = (short[]) ip.crop().getPixels();
                for (short e : data) buffer.putShort(e);
                System.arraycopy(buffer.array(), 0, bdata, bsize, buffer.array().length);
                bsize += buffer.array().length;
              } else if (bdepth == 32) {
                ByteBuffer buffer = ByteBuffer.allocate(b.w_ * b.h_ * bdepth / 8);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                float[] data = (float[]) ip.crop().getPixels();
                for (float e : data) buffer.putFloat(e);
                System.arraycopy(buffer.array(), 0, bdata, bsize, buffer.array().length);
                bsize += buffer.array().length;
              }
            }

            String filename =
                basename
                    + "_Lv"
                    + String.valueOf(l)
                    + "_Ch"
                    + String.valueOf(ch)
                    + "_Fr"
                    + String.valueOf(f)
                    + "_ID"
                    + String.valueOf(i);

            int offset = bytecount;
            int datasize = bdata.length;

            if (filetype == "RAW") {
              int dummy = -1;
              // do nothing
            }
            if (filetype == "JPEG" && bdepth == 8) {
              try {
                DataBufferByte db = new DataBufferByte(bdata, datasize);
                Raster raster = Raster.createPackedRaster(db, b.w_, b.h_ * b.d_, 8, null);
                BufferedImage img =
                    new BufferedImage(b.w_, b.h_ * b.d_, BufferedImage.TYPE_BYTE_GRAY);
                img.setData(raster);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
                String format = "jpg";
                Iterator<javax.imageio.ImageWriter> iter =
                    ImageIO.getImageWritersByFormatName("jpeg");
                javax.imageio.ImageWriter writer = iter.next();
                ImageWriteParam iwp = writer.getDefaultWriteParam();
                iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwp.setCompressionQuality((float) jpeg_quality * 0.01f);
                writer.setOutput(ios);
                writer.write(null, new IIOImage(img, null, null), iwp);
                // ImageIO.write(img, format, baos);
                bdata = baos.toByteArray();
                datasize = bdata.length;
              } catch (IOException e) {
                e.printStackTrace();
                return;
              }
            }
            if (filetype == "ZLIB") {
              byte[] tmpdata = new byte[b.w_ * b.h_ * b.d_ * bdepth / 8];
              Deflater compresser = new Deflater();
              compresser.setInput(bdata);
              compresser.setLevel(Deflater.DEFAULT_COMPRESSION);
              compresser.setStrategy(Deflater.DEFAULT_STRATEGY);
              compresser.finish();
              datasize = compresser.deflate(tmpdata);
              bdata = tmpdata;
              compresser.end();
            }

            if (bytecount + datasize > sizelimit && bytecount > 0) {
              BufferedOutputStream fis = null;
              try {
                File file = new File(directory + current_dataname);
                fis = new BufferedOutputStream(new FileOutputStream(file));
                fis.write(packed_data, 0, bytecount);
              } catch (IOException e) {
                e.printStackTrace();
                return;
              } finally {
                try {
                  if (fis != null) fis.close();
                } catch (IOException e) {
                  e.printStackTrace();
                  return;
                }
              }
              filecount++;
              current_dataname = base_dataname + "_data" + filecount;
              bytecount = 0;
              offset = 0;
              System.arraycopy(bdata, 0, packed_data, bytecount, datasize);
              bytecount += datasize;
            } else {
              System.arraycopy(bdata, 0, packed_data, bytecount, datasize);
              bytecount += datasize;
            }

            Element filenode = doc.createElement("File");
            filenode.setAttribute("filename", current_dataname);
            filenode.setAttribute("channel", String.valueOf(ch));
            filenode.setAttribute("frame", String.valueOf(f));
            filenode.setAttribute("brickID", String.valueOf(i));
            filenode.setAttribute("offset", String.valueOf(offset));
            filenode.setAttribute("datasize", String.valueOf(datasize));
            filenode.setAttribute("filetype", String.valueOf(filetype));

            fsnode.appendChild(filenode);

            curbricknum++;
            IJ.showProgress((double) (curbricknum) / (double) (totalbricknum));
          }
          if (bytecount > 0) {
            BufferedOutputStream fis = null;
            try {
              File file = new File(directory + current_dataname);
              fis = new BufferedOutputStream(new FileOutputStream(file));
              fis.write(packed_data, 0, bytecount);
            } catch (IOException e) {
              e.printStackTrace();
              return;
            } finally {
              try {
                if (fis != null) fis.close();
              } catch (IOException e) {
                e.printStackTrace();
                return;
              }
            }
          }
        }
      }

      for (int i = 0; i < bricks.size(); i++) {
        Brick b = bricks.get(i);
        Element bricknode = doc.createElement("Brick");
        bricknode.setAttribute("id", String.valueOf(i));
        bricknode.setAttribute("st_x", String.valueOf(b.x_));
        bricknode.setAttribute("st_y", String.valueOf(b.y_));
        bricknode.setAttribute("st_z", String.valueOf(b.z_));
        bricknode.setAttribute("width", String.valueOf(b.w_));
        bricknode.setAttribute("height", String.valueOf(b.h_));
        bricknode.setAttribute("depth", String.valueOf(b.d_));
        brksnode.appendChild(bricknode);

        Element tboxnode = doc.createElement("tbox");
        tboxnode.setAttribute("x0", String.valueOf(b.tx0_));
        tboxnode.setAttribute("y0", String.valueOf(b.ty0_));
        tboxnode.setAttribute("z0", String.valueOf(b.tz0_));
        tboxnode.setAttribute("x1", String.valueOf(b.tx1_));
        tboxnode.setAttribute("y1", String.valueOf(b.ty1_));
        tboxnode.setAttribute("z1", String.valueOf(b.tz1_));
        bricknode.appendChild(tboxnode);

        Element bboxnode = doc.createElement("bbox");
        bboxnode.setAttribute("x0", String.valueOf(b.bx0_));
        bboxnode.setAttribute("y0", String.valueOf(b.by0_));
        bboxnode.setAttribute("z0", String.valueOf(b.bz0_));
        bboxnode.setAttribute("x1", String.valueOf(b.bx1_));
        bboxnode.setAttribute("y1", String.valueOf(b.by1_));
        bboxnode.setAttribute("z1", String.valueOf(b.bz1_));
        bricknode.appendChild(bboxnode);
      }

      if (l < lv - 1) {
        imp = WindowManager.getImage(lvImgTitle.get(l + 1));
        int[] newdims = imp.getDimensions();
        imageW = newdims[0];
        imageH = newdims[1];
        imageD = newdims[3];
        xspc = orgxspc * ((double) orgW / (double) imageW);
        yspc = orgyspc * ((double) orgH / (double) imageH);
        zspc = orgzspc * ((double) orgD / (double) imageD);
        bdepth = imp.getBitDepth();
      }
    }

    File newXMLfile = new File(directory + basename + ".vvd");
    writeXML(newXMLfile, doc);

    for (int l = 1; l < lv; l++) {
      imp = WindowManager.getImage(lvImgTitle.get(l));
      imp.changes = false;
      imp.close();
    }
  }
Exemplo n.º 26
0
  public VolatileImage render() {

    Graphics2D g2d = renderImage.createGraphics();

    try {

      // Draw background layer:
      for (int i = 0; i < backgroundLayer.length; i++) {
        g2d.drawImage(
            backgroundLayer[i],
            -(int) (camera.position.x * Math.pow(0.5, backgroundLayer.length - i)),
            -(int) (camera.position.y * Math.pow(0.5, backgroundLayer.length - i))
                + backgroundLayer[i].getHeight(this)
                - backgroundLayer[i].getHeight(this) / (i + 1),
            this);
      }

    } catch (Exception e) {
    }

    // Draw Tiles: (new)
    try {
      g2d.drawImage(
          tileLayer,
          camera.center.x - camera.position.x,
          camera.center.y - camera.position.y,
          this);
    } catch (Exception e) {
    }

    // Draw all kinds of Sprites:

    try {
      int a = 0;

      while (sprite[a] != null) {
        // Play Animation for sprite:
        if (sprite[a].animation.plays == true) {
          sprite[a].getAnimation().nextFrame();
        }

        // -- Draw sprite:
        g2d.drawImage(
            sprite[a].img,
            /*X1*/ sprite[a].posx
                + ((sprite[a].flipH - 1) / (-2)) * sprite[a].size.width /*camera*/
                - camera.position.x
                + camera.center.x, /*Y1*/
            sprite[a].posy
                + ((sprite[a].flipV - 1) / (-2)) * sprite[a].size.height /*camera*/
                - camera.position.y
                + camera.center.y,
            /*X2*/ sprite[a].posx
                + sprite[a].size.width * sprite[a].flipH
                + ((sprite[a].flipH - 1) / (-2)) * sprite[a].size.width /*camera*/
                - camera.position.x
                + camera.center.x, /*Y2*/
            sprite[a].posy
                + sprite[a].size.height * sprite[a].flipV
                + ((sprite[a].flipV - 1) / (-2)) * sprite[a].size.height /*camera*/
                - camera.position.y
                + camera.center.y, // destination
            sprite[a].getAnimation().col * sprite[a].size.width,
            sprite[a].getAnimation().row * sprite[a].size.height, // source
            (sprite[a].getAnimation().col + 1) * sprite[a].size.width,
            (sprite[a].getAnimation().row + 1) * sprite[a].size.height,
            this);

        a++;
      }
    } catch (Exception e) {
      g2d.drawString("Error drawing a Sprite", 20, 20);
    }

    // Draw "GUI":
    g2d.drawImage(coinSpriteSheet, 16, 16, 32, 32, 0, 0, 16, 16, this);
    g2d.setColor(Color.BLACK);
    g2d.drawString("x " + collectedCoins, 32, 30);
    g2d.setColor(Color.WHITE);
    g2d.drawString("x " + collectedCoins, 32, 29);

    if (showSpritePos == true) {
      for (int i = 0; i < numberOfSprites; i++) {
        g2d.setColor(Color.red);
        g2d.drawRect(
            /*X1*/ sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/
            sprite[i].posy /*camera*/ - camera.position.y + camera.center.y,
            1,
            1);
        g2d.setColor(Color.black);
      }
    }

    if (showSpriteNum == true) {
      for (int i = 0; i < numberOfSprites; i++) {
        g2d.setColor(Color.black);
        g2d.drawString(
            "" + i, /*X1*/
            sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/
            sprite[i].posy /*camera*/ - camera.position.y + camera.center.y);
        g2d.setColor(Color.white);
        g2d.drawString(
            "" + i, /*X1*/
            sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/
            sprite[i].posy /*camera*/ - camera.position.y + camera.center.y - 1);
      }
    }

    if (showSpritePos == true) {
      for (int i = 0; i < numberOfTiles; i++) {
        g2d.setColor(Color.red);
        g2d.drawRect(
            /*X1*/ tile[i].posx
                + ((tile[i].flipH - 1) / (-2)) * tile[i].size.width /*camera*/
                - camera.position.x
                + camera.center.x, /*Y1*/
            tile[i].posy
                + ((tile[i].flipV - 1) / (-2)) * tile[i].size.height /*camera*/
                - camera.position.y
                + camera.center.y,
            1,
            1);
        g2d.setColor(Color.black);
      }
    }

    if (showCamera == true) {
      g2d.setColor(Color.red);
      g2d.drawLine(
          0,
          camera.prefHeight - camera.position.y + camera.center.y,
          loadedLevel.getWidth() * 16,
          camera.prefHeight - camera.position.y + camera.center.y);
      g2d.setColor(new Color(1, 0, 0, 0.33f));
      g2d.fillRect(
          0,
          camera.prefHeight - camera.position.y + camera.tolerance,
          loadedLevel.getWidth() * 16,
          camera.tolerance);
      g2d.setColor(new Color(0, 1, 0, 0.33f));
      g2d.fillRect(
          camera.center.x - camera.position.x + camera.center.x,
          camera.center.y - camera.position.y + camera.center.y,
          camera.bounds.width - 2 * camera.center.x,
          camera.bounds.height);
      g2d.setColor(Color.green);
      g2d.drawLine(
          camera.center.x - camera.position.x + camera.center.x,
          0,
          camera.center.x - camera.position.x + camera.center.x,
          999);
      g2d.drawLine(
          camera.bounds.width - camera.center.x - camera.position.x + camera.center.x,
          0,
          camera.bounds.width - camera.center.x - camera.position.x + camera.center.x,
          999);
    }

    return renderImage;
  }
Exemplo n.º 27
0
 private int scy(int py) {
   return (int) Math.round(py * scaley);
 }
Exemplo n.º 28
0
 private int scx(int px) {
   return (int) Math.round(px * scalex);
 }
Exemplo n.º 29
0
  public GroundTexture(int size, Ground grnd) {

    System.out.println("Calculating Ground Texture...");

    img = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);

    double r, g, b;
    Random rnd = new Random();

    System.out.print("Initializing...");

    for (int x = 0; x < size; x++) {
      for (int y = 0; y < size; y++) {
        double slope = 0;
        for (int nx = x - 1; nx < x + 1; nx++)
          for (int ny = y - 1; ny < y + 1; ny++)
            if ((nx >= 0) && (nx < size))
              if ((ny >= 0) && (ny < size)) slope += Math.abs(grnd.topo[nx][ny] - grnd.topo[x][y]);
        if (slope < 1) slope = 1;
        g = 5d + 80d / (grnd.topo[x][y] / 2000d + 1d) + rnd.nextDouble() * 30d / (slope);
        r =
            g
                * (1.17
                    + (-.3 + (rnd.nextDouble() * .3))
                        / (grnd.topo[x][y] / 200d + 1d)
                        / (slope / 5 + 1));
        b =
            r
                * (.7
                    + (-.3 + (rnd.nextDouble() * .2))
                        / (grnd.topo[x][y] / 200d + 1d)
                        / (slope / 5 + 1));

        img.setRGB(x, y, colorRGB((int) r, (int) g, (int) b));
      }
    }

    /**/

    //		save("bodentextur2","png");

    System.out.print("                \rRandom Growth");

    for (int i = 0; i < size * size * 8; i++) {
      if (i % (size * size / 2) == 0) System.out.print(".");
      int x = 3 + rnd.nextInt(size - 6);
      int y = 3 + rnd.nextInt(size - 6);
      int nx = x - 1 + rnd.nextInt(3);
      int ny = y - 1 + rnd.nextInt(3);
      while ((nx < 0) || (nx >= size) || (ny < 0) || (ny >= size)) {
        nx = x - 1 + rnd.nextInt(3);
        ny = y - 1 + rnd.nextInt(3);
      }
      Color dis = getColorAt(x, y);
      Color col = getColorAt(nx, ny);
      if (grnd.topo[nx][ny] >= 4.5)
        if (col.getGreen() / col.getRed() > dis.getGreen() / dis.getRed())
          if (Math.abs(grnd.topo[x][y] - grnd.topo[nx][ny]) < .65) {
            int c = colorRGB(col.getRed(), col.getGreen(), col.getBlue());
            // img.setRGB(x,y, colorRGB(col.getRed(), col.getGreen(), col.getBlue()));
            // img.setRGB(x-1+rnd.nextInt(3),y-1+rnd.nextInt(3), colorRGB(col.getRed(),
            // col.getGreen(), col.getBlue()));
            for (nx = x - 1 - rnd.nextInt(3); nx < 1 + x + rnd.nextInt(3); nx++)
              for (ny = y - 1 - rnd.nextInt(3); ny < y + 1 + rnd.nextInt(3); ny++) {
                img.setRGB(nx, ny, c);
                grnd.topo[nx][ny] += 1.8;
              }
          }
    }

    System.out.print("                 \rAntialiasing...");
    /*		for (int x = 0; x < size; x++){
    	for (int y = 0; y < size; y++){
    		double sumr = 0;
    		double sumg = 0;
    		double sumb = 0;
    		double div = 0;
    		for (int nx=x-1;nx<x+1;nx++)
    			for (int ny=y-1;ny<y+1;ny++)
    				if ((nx>=0) && (nx < size)) if ((ny>=0) && (ny < size)) {
    					Color col = getColorAt(nx,ny);
    					sumr+=col.getRed();
    					sumg+=col.getGreen();
    					sumb+=col.getBlue();
    					div++;
    				}
    		r=sumr/div;
    		g=sumg/div;
    		b=sumb/div;
    		img.setRGB(x,y, colorRGB((int)r, (int)g, (int)b) );

    	}
    }*/

    System.out.print("        \r");
    //		save("bodentextur3","png");
    save("bodentextur", "png");
  }
Exemplo n.º 30
0
  public void initialize() {
    buffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    // #if (Black_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tank_Black.gif", "SP1");
    // #elif (Red_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tank_Red.gif", "SP1");
    // #elif (Red_Tier1_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tier1rot.gif", "SP1");
    // #elif (Yellow_Tier1_P1)
    player_1 = new Entity(100, 100, "imgs/Tier1gelb.gif", "SP1");
    // #elif (Blue_Tier2_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tier2blau.gif", "SP1");
    // #elif (Green_Tier2_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tier2gruen.gif", "SP1");
    // #endif

    // #if (Black_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tank_Black.gif", "SP2");
    // #elif (Red_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tank_Red.gif", "SP2");
    // #elif (Red_Tier1_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tier1rot.gif", "SP2");
    // #elif (Yellow_Tier1_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tier1gelb.gif", "SP2");
    // #elif (Blue_Tier2_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tier2blau.gif", "SP2");
    // #elif (Green_Tier2_P2)
    player_2 = new Entity(200, 100, "imgs/Tier2gruen.gif", "SP2");
    // #endif

    current_Player = player_1;
    other_Player = player_2;
    env = new Environment[amountEnv];
    powerUps = new PowerUp[9];

    for (int i = 0; i <= amountEnv - 1; i++) {
      // #if (Hinderniss_Set)
      // @                if (Math.random()>0.95) env[i] = new
      // Environment("imgs/HindernisseBearbeitet/_b.GIF");
      // @                else if (Math.random()>0.90)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerDunkelrot_b.gif");
      // @                else if (Math.random()>0.85)env[i] = new
      // Environment("imgs/mauer_hoch.gif");
      // @                else if (Math.random()>0.80)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumStamm.gif");
      // @                else if (Math.random()>0.75)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumKlein.gif");
      // @                else if (Math.random()>0.70)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumKlein_b.GIF");
      // @                else if (Math.random()>0.65)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumStamm.gif");
      // @                else if (Math.random()>0.60)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumStamm_b.GIF");
      // @                else if (Math.random()>0.55)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerDunkelrot_b.gif");
      // @                else if (Math.random()>0.50)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerDunkelrot.gif");
      // @                else if (Math.random()>0.45)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerDunkelrot_b.GIF");
      // @                else if (Math.random()>0.40)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauKurz.gif");
      // @                else if (Math.random()>0.35)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauKurz_b.GIF");
      // @                else if (Math.random()>0.30)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauKurzDick.gif");
      // @                else if (Math.random()>0.25)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauKurzDick_b.GIF");
      // @                else if (Math.random()>0.20)env[i] = new
      // Environment("imgs/Haus_vonOben.gif");
      // @                else if (Math.random()>0.15)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauLangDick.gif");
      // @                else if (Math.random()>0.10)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauLangDick_b.GIF");
      // @                else if (Math.random()>0.05)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerRot.gif");
      // @                else env[i] = new Environment("imgs/Haus_vonOben_b.GIF");
      // @            //}
      // #else
      if (Math.random() > 0.75)
        env[i] = new Environment("imgs/HindernisseBearbeitet/Pfuetze1.gif.gif");
      else if (Math.random() > 0.50)
        env[i] = new Environment("imgs/HindernisseBearbeitet/PfuetzeGross.gif");
      else if (Math.random() > 0.25)
        env[i] = new Environment("imgs/HindernisseBearbeitet/PfuetzeKlein.gif");
      else env[i] = new Environment("imgs/HindernisseBearbeitet/PfuetzeMittel.gif");
      // #endif

      env[i].setX((int) (150 + Math.random() * (w - 200)));
      env[i].setY((int) (50 + Math.random() * (h - 200)));
    }
    int i = 0;
    while (true) {
      // #if (Flower)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpBlume.gif");
      i++;
      // #endif
      // #if (Blue_Flower)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpBlumeBlau.gif");
      i++;
      // #endif
      // #if (Copy)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpCopy.gif");
      i++;
      // #endif
      // #if (Fire)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpFeuer.gif");
      // @        i++;
      // #endif
      // #if (Light_Bulb_Round)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpGluehbirneRund.gif");
      i++;
      // #endif
      // #if (Green)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpGruen.gif");
      // @        i++;
      // #endif
      // #if (Heart)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpHerz.gif");
      // @        i++;
      // #endif
      // #if (Circle)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpKreis.gif");
      // @        i++;
      // #endif
      // #if (Cow)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpKuh.gif");
      // @        i++;
      // #endif
      // #if (Light_Bulb)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpLightbulb.gif");
      i++;
      // #endif
      // #if (Octagonal)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpOctagonal.gif");
      // @        i++;
      // #endif
      // #if (Mushroom)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpPilz.gif");
      i++;
      // #endif
      // #if (Pumpkin_Pie)
      // @	       if (i == 9) break;
      // @	    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpPumpkinPie.gif");
      // @	        i++;
      // #endif
      // #if (Ring)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpRing.gif");
      i++;
      // #endif
      // #if (Ring_2)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpRingeZwei.gif");
      i++;
      // #endif
      // #if (Ring_Oval)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpRingOval.gif");
      i++;
      // #endif
      // #if (Ring_Oval_Small)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpRingOvalKlein.gif");
      i++;
      // #endif
      // #if (Sponge)
      // @    	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSchwamm.gif");
      // @    	i++;
      // #endif
      // #if (Spiral)
      // @    	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSpiral.gif");
      // @    	i++;
      // #endif
      // #if (Star_Oval)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSternOval.gif");
      i++;
      // #endif
      // #if (Star_Oval_Small)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSternOvalKlein.gif");
      i++;
      // #endif
      // #if (Star_Ring)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSternRing.gif");
      i++;
      // #endif
    }
    // #if (Nr1)
    powerUps[0].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[0].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[0].setX(-100);
    // @            powerUps[0].setY(-100);
    // #endif

    // #if (Nr2)
    powerUps[1].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[1].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[1].setX(-100);
    // @            powerUps[1].setY(-100);
    // #endif

    // #if (Nr3)
    powerUps[2].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[2].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[2].setX(-100);
    // @            powerUps[2].setY(-100);
    // #endif

    // #if (Nr4)
    powerUps[3].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[3].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[3].setX(-100);
    // @            powerUps[3].setY(-100);
    // #endif

    // #if (Nr5)
    powerUps[4].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[4].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[4].setX(-100);
    // @            powerUps[4].setY(-100);
    // #endif

    // #if (Nr6)
    powerUps[5].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[5].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[5].setX(-100);
    // @            powerUps[5].setY(-100);
    // #endif

    // #if (Nr7)
    powerUps[6].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[6].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[6].setX(-100);
    // @            powerUps[6].setY(-100);
    // #endif

    // #if (Nr8)
    powerUps[7].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[7].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[7].setX(-100);
    // @            powerUps[7].setY(-100);
    // #endif

  }