Пример #1
0
  public ImagePanel(Kdu_coords viewSize) throws KduException {
    int width = Math.min(viewSize.Get_x(), 1600);
    int height = Math.min(viewSize.Get_y(), 1200);

    setPreferredSize(new Dimension(width, height));

    getInputMap().put(KeyStroke.getKeyStroke("UP"), "pressedUpArrow");
    getActionMap()
        .put(
            "pressedUpArrow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent evt) {
                // placeholder
              }
            });
    getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "pressedDownArrow");
    getActionMap()
        .put(
            "pressedDownArrow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent evt) {
                // placeholder
              }
            });
  }
Пример #2
0
 public void printLoop(int n, float x[], float y[]) {
   // Need to swap the y component
   Polygon P = new Polygon();
   for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i]));
   poly_draw.add(P);
   poly_draw_color.add(curColor);
 }
Пример #3
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;
  }
Пример #4
0
  public void fitSpline(int evaluationPoints) {
    if (xpf == null) {
      xpf = toFloat(xp);
      ypf = toFloat(yp);
      subPixel = true;
    }
    if (xSpline == null || splinePoints != evaluationPoints) {
      splinePoints = evaluationPoints;
      xSpline = new float[splinePoints];
      ySpline = new float[splinePoints];
    }
    int nNodes = nPoints;
    if (type == POLYGON) {
      nNodes++;
      if (nNodes >= xpf.length) enlargeArrays();
      xpf[nNodes - 1] = xpf[0];
      ypf[nNodes - 1] = ypf[0];
    }
    float[] xindex = new float[nNodes];
    for (int i = 0; i < nNodes; i++) xindex[i] = i;
    SplineFitter sfx = new SplineFitter(xindex, xpf, nNodes);
    SplineFitter sfy = new SplineFitter(xindex, ypf, nNodes);

    // Evaluate the splines at all points
    double scale = (double) (nNodes - 1) / (splinePoints - 1);
    float xs = 0f, ys = 0f;
    float xmin = Float.MAX_VALUE, xmax = -xmin, ymin = xmin, ymax = xmax;
    for (int i = 0; i < splinePoints; i++) {
      double xvalue = i * scale;
      xs = (float) sfx.evalSpline(xindex, xpf, nNodes, xvalue);
      if (xs < xmin) xmin = xs;
      if (xs > xmax) xmax = xs;
      xSpline[i] = xs;
      ys = (float) sfy.evalSpline(xindex, ypf, nNodes, xvalue);
      if (ys < ymin) ymin = ys;
      if (ys > ymax) ymax = ys;
      ySpline[i] = ys;
    }
    int ixmin = (int) Math.floor(xmin + 0.5f);
    int ixmax = (int) Math.floor(xmax + 0.5f);
    int iymin = (int) Math.floor(ymin + 0.5f);
    int iymax = (int) Math.floor(ymax + 0.5f);
    if (ixmin != 0) {
      for (int i = 0; i < nPoints; i++) xpf[i] -= ixmin;
      for (int i = 0; i < splinePoints; i++) xSpline[i] -= ixmin;
    }
    if (iymin != 0) {
      for (int i = 0; i < nPoints; i++) ypf[i] -= iymin;
      for (int i = 0; i < splinePoints; i++) ySpline[i] -= iymin;
    }
    x += ixmin;
    y += iymin;
    width = ixmax - ixmin;
    height = iymax - iymin;
    bounds = null;
    cachedMask = null;
    // update protected xp and yp arrays for backward compatibility
    xp = toInt(xpf, xp, nPoints);
    yp = toInt(ypf, yp, nPoints);
  }
Пример #5
0
 public double cval(double td) {
   if (td == 0) return (1.0);
   else if ((td < -sz) || (td > sz)) return (0.0);
   double tdp = td * Math.PI;
   double wtdp = tdp / sz;
   return ((Math.sin(tdp) / tdp) * (Math.sin(wtdp) / wtdp));
 }
Пример #6
0
  /** @param override true if should kill even if invulerable, false if not */
  public void kill(boolean override) {
    if (!override) {
      if (star || invulerable || piped) return;
    }
    deathPos.setLocation(pos);
    if (deathPos.y < 0) {
      deathPos.y = 0;
    }
    if (metal) {
      metal = false;
      startInvulnerable();
      invulerableTime = 3000 / 15;
      Point2D.Double v = new Point2D.Double(Math.random() * 8 - 4, Math.random() * 4 + 7);

      TMetalCap cap = new TMetalCap();
      cap.setPos(pos.x, pos.y);
      cap.kill(v);
      this.addSpawn(cap);
      return;
    }
    cape = false;
    dead = true;
    numBullets = 0;
    falling = false;
    acc = new Point2D.Double();
    vel = new Point2D.Double();
    deadTime = 25;
  }
Пример #7
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) {
    }
  }
Пример #8
0
  public double getHu2(int region) {

    double eta20 = this.getEta(region, 2, 0);
    double eta02 = this.getEta(region, 0, 2);
    double eta11 = this.getEta(region, 1, 1);
    return Math.pow(eta20 - eta02, 2) + Math.pow(2 * eta11, 2);
  }
Пример #9
0
  /** Returns the supported cursor size */
  static Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {

    // Fix for bug 4212593 The Toolkit.createCustomCursor does not
    //                     check absence of the image of cursor
    // We use XQueryBestCursor which accepts unsigned ints to obtain
    // the largest cursor size that could be dislpayed
    // Dimension d = new Dimension(Math.abs(preferredWidth), Math.abs(preferredHeight));
    Dimension d;

    XToolkit.awtLock();
    try {
      long display = XToolkit.getDisplay();
      long root_window = XlibWrapper.RootWindow(display, XlibWrapper.DefaultScreen(display));

      XlibWrapper.XQueryBestCursor(
          display,
          root_window,
          Math.abs(preferredWidth),
          Math.abs(preferredHeight),
          XlibWrapper.larg1,
          XlibWrapper.larg2);
      d =
          new Dimension(
              XlibWrapper.unsafe.getInt(XlibWrapper.larg1),
              XlibWrapper.unsafe.getInt(XlibWrapper.larg2));
    } finally {
      XToolkit.awtUnlock();
    }
    return d;
  }
Пример #10
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);
     }
 }
Пример #11
0
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
Пример #12
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;
    }
  }
Пример #13
0
 public int filterRGB(int x, int y, int rgb) {
   int r = ((rgb >> 16) & 0xff);
   int g = ((rgb >> 8) & 0xff);
   int b = (rgb & 0xff);
   int gray = Math.max(Math.max(r, g), b);
   return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray << 0);
 }
Пример #14
0
 /** Frees memory by deleting a few slices from the end of the stack. */
 public void trim() {
   int n = (int) Math.round(Math.log(nSlices) + 1.0);
   for (int i = 0; i < n; i++) {
     deleteLastSlice();
     System.gc();
   }
 }
Пример #15
0
 public static WritableRaster glowmask(Raster img) {
   Coord sz = imgsz(img);
   int nb = img.getNumBands();
   WritableRaster ret = alpharaster(sz);
   float[] hsv = new float[3];
   float max = 0;
   for (int y = 0; y < sz.y; y++) {
     for (int x = 0; x < sz.x; x++) {
       Color.RGBtoHSB(img.getSample(x, y, 0), img.getSample(x, y, 1), img.getSample(x, y, 2), hsv);
       float a = (nb > 3) ? (img.getSample(x, y, 3) / 255f) : 1f;
       float val = ((1f - hsv[1]) * hsv[2]) * a;
       max = Math.max(max, val);
     }
   }
   float imax = 1f / max;
   for (int y = 0; y < sz.y; y++) {
     for (int x = 0; x < sz.x; x++) {
       Color.RGBtoHSB(img.getSample(x, y, 0), img.getSample(x, y, 1), img.getSample(x, y, 2), hsv);
       float a = (nb > 3) ? (img.getSample(x, y, 3) / 255f) : 1f;
       float val = ((1f - hsv[1]) * hsv[2]) * a;
       ret.setSample(x, y, 0, Math.min(Math.max((int) (Math.sqrt(val * imax) * 255), 0), 255));
     }
   }
   return (ret);
 }
Пример #16
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;
  }
Пример #17
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
 private void initialize() {
   sinTable = new float[256];
   cosTable = new float[256];
   for (int i = 0; i < 256; i++) {
     float angle = ImageMath.TWO_PI * i / 256f * turbulence;
     sinTable[i] = (float) (-yScale * Math.sin(angle));
     cosTable[i] = (float) (yScale * Math.cos(angle));
   }
 }
Пример #19
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));
 }
Пример #20
0
 void ajustarYCentrar(JComponent porAjustar, JComponent ajustador) {
   // Se agregan 30 de alto y 6 de ancho por adornos de la ventana
   porAjustar.setSize(
       ajustador.getMinimumSize().getSize().width + 16,
       ajustador.getMinimumSize().getSize().height + 44);
   int x = Math.round(Principal.sysAncho / 2) - Math.round(porAjustar.getBounds().width / 2);
   int y = Math.round(Principal.sysAlto / 2) - Math.round(porAjustar.getBounds().height / 2);
   porAjustar.setLocation(x, y);
 }
Пример #21
0
 /**
  * Zooms out by making the source rectangle (srcRect) larger and centering it on (x,y). If we
  * can't make it larger, then make the window smaller.
  */
 public void zoomOut(int x, int y) {
   if (magnification <= 0.03125) return;
   double oldMag = magnification;
   double newMag = getLowerZoomLevel(magnification);
   double srcRatio = (double) srcRect.width / srcRect.height;
   double imageRatio = (double) imageWidth / imageHeight;
   double initialMag = imp.getWindow().getInitialMagnification();
   if (Math.abs(srcRatio - imageRatio) > 0.05) {
     double scale = oldMag / newMag;
     int newSrcWidth = (int) Math.round(srcRect.width * scale);
     int newSrcHeight = (int) Math.round(srcRect.height * scale);
     if (newSrcWidth > imageWidth) newSrcWidth = imageWidth;
     if (newSrcHeight > imageHeight) newSrcHeight = imageHeight;
     int newSrcX = srcRect.x - (newSrcWidth - srcRect.width) / 2;
     int newSrcY = srcRect.y - (newSrcHeight - srcRect.height) / 2;
     if (newSrcX < 0) newSrcX = 0;
     if (newSrcY < 0) newSrcY = 0;
     srcRect = new Rectangle(newSrcX, newSrcY, newSrcWidth, newSrcHeight);
     // IJ.log(newMag+" "+srcRect+" "+dstWidth+" "+dstHeight);
     int newDstWidth = (int) (srcRect.width * newMag);
     int newDstHeight = (int) (srcRect.height * newMag);
     setMagnification(newMag);
     setMaxBounds();
     // IJ.log(newDstWidth+" "+dstWidth+" "+newDstHeight+" "+dstHeight);
     if (newDstWidth < dstWidth || newDstHeight < dstHeight) {
       // IJ.log("pack");
       setDrawingSize(newDstWidth, newDstHeight);
       imp.getWindow().pack();
     } else repaint();
     return;
   }
   if (imageWidth * newMag > dstWidth) {
     int w = (int) Math.round(dstWidth / newMag);
     if (w * newMag < dstWidth) w++;
     int h = (int) Math.round(dstHeight / newMag);
     if (h * newMag < dstHeight) h++;
     x = offScreenX(x);
     y = offScreenY(y);
     Rectangle r = new Rectangle(x - w / 2, y - h / 2, w, h);
     if (r.x < 0) r.x = 0;
     if (r.y < 0) r.y = 0;
     if (r.x + w > imageWidth) r.x = imageWidth - w;
     if (r.y + h > imageHeight) r.y = imageHeight - h;
     srcRect = r;
   } else {
     srcRect = new Rectangle(0, 0, imageWidth, imageHeight);
     setDrawingSize((int) (imageWidth * newMag), (int) (imageHeight * newMag));
     // setDrawingSize(dstWidth/2, dstHeight/2);
     imp.getWindow().pack();
   }
   // IJ.write(newMag + " " + srcRect.x+" "+srcRect.y+" "+srcRect.width+" "+srcRect.height+"
   // "+dstWidth + " " + dstHeight);
   setMagnification(newMag);
   // IJ.write(srcRect.x + " " + srcRect.width + " " + dstWidth);
   setMaxBounds();
   repaint();
 }
Пример #22
0
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape shape;

    if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      shape = new Ellipse2D.Float(0, 0, size, size);
    } else {
      Rectangle r = new Rectangle(0, 0, size, size);
      shape = r;
    }

    if (hasFocus()) {
      PaintUtils.paintFocus(g2, shape, 5);
    }

    if (!(shape instanceof Rectangle)) {
      // paint a circular shadow
      g2.translate(2, 2);
      g2.setColor(new Color(0, 0, 0, 20));
      g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4));
      g2.setColor(new Color(0, 0, 0, 40));
      g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2));
      g2.setColor(new Color(0, 0, 0, 80));
      g2.fill(new Ellipse2D.Float(0, 0, size, size));
      g2.translate(-2, -2);
    }

    g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null);

    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle) shape;
      PaintUtils.drawBevel(g2, r);
    } else {
      g2.setColor(new Color(0, 0, 0, 120));
      g2.draw(shape);
    }

    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(1));
    g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6));
    g2.setColor(Color.black);
    g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8));

    g.translate(-imagePadding.left, -imagePadding.top);
  }
Пример #23
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);
  }
Пример #24
0
 public void animate(float[] pts, float[] deltas, int index, int limit) {
   float newpt = pts[index] + deltas[index];
   if (newpt <= 0) {
     newpt = -newpt;
     deltas[index] = (float) (Math.random() * 3.0 + 2.0);
   } else if (newpt >= (float) limit) {
     newpt = 2.0f * limit - newpt;
     deltas[index] = -(float) (Math.random() * 3.0 + 2.0);
   }
   pts[index] = newpt;
 }
Пример #25
0
 private static Color getColorFromPallet(int[] pallet, float x) {
   if (x < 0f || x > 1f) {
     throw new IllegalArgumentException("Parameter outside of expected range");
   }
   int i = (int) (pallet.length * x);
   int max = pallet.length - 1;
   int index = Math.min(Math.max(i, 0), max);
   return new Color(pallet[index] & 0x00FFFFFF);
   // translucent
   // int pix = pallet[index] & 0x00FFFFFF | (0x64 << 24);
   // return new Color(pix), true);
 }
Пример #26
0
 public void fellipse(Coord c, Coord r, int a1, int a2) {
   st.set(cur2d);
   apply();
   gl.glBegin(GL.GL_TRIANGLE_FAN);
   vertex(c);
   for (int i = a1; i <= a2; i += 5) {
     double a = (i * Math.PI * 2) / 360.0;
     vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y)));
   }
   gl.glEnd();
   checkerr();
 }
Пример #27
0
  private void drawAWP(Graphics g, int x, int y) {
    if (System.currentTimeMillis() < shotTime + TAWP.SHOOT_TIME) {
      // System.out.println(true);
      double multi = 1.0 * (System.currentTimeMillis() - shotTime) / TAWP.SHOOT_TIME;
      g.setColor(new Color(255, 255, 255, 255 - (int) (multi * 256)));
      g.fillRect(0, 0, Wuigi.screenWidth, Wuigi.screenHeight);
    }
    if (numBullets <= 0) return;

    BufferedImage img = TAWP.IMAGE.getBuffer();
    AffineTransform xform = new AffineTransform();
    // g2d.setPaint(new TexturePaint(figureOutDrawImage(),
    //		new Rectangle2D.Float(0, 0, 32, 32)));
    // g2d.drawImage(figureOutDrawImage(),0,0,null);
    xform.setToIdentity();
    xform.translate(x - 5, y);

    double diffY = y + height / 2 - ScreenManager.mouse.y;
    double diffX = ScreenManager.mouse.x - x - width / 2;

    double angle;

    if (diffY > 0 && diffX > 0) {
      angle = Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX > 0) {
      angle = Math.PI / 2;
    } else if (diffY < 0 && diffX > 0) {
      angle = Math.PI / 2 + Math.atan(-diffY / diffX);
    } else if (diffY < 0 && diffX == 0) {
      angle = Math.PI;
    } else if (diffY < 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX < 0) {
      angle = 3 * Math.PI / 2;
    } else if (diffY > 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 + Math.atan(-diffY / diffX);
    } else {
      angle = 0;
    }
    angle -= Math.PI / 2;

    if (angle > Math.PI / 2 && angle < 3 * Math.PI / 2) {
      xform.scale(1, -1);
      xform.translate(0, -TAWP.IMAGE.getHeight());
      angle = -angle;
    }
    // xform.scale(/*width/img.getWidth(),height/img.getHeight()*/);
    xform.rotate(angle, 27, 13);

    ((Graphics2D) g).drawImage(img, xform, null);
    ammo.setPos(x + 10, y - 20);
    ammo.draw(g);
  }
Пример #28
0
  public NTSCRenderer() {
    int hue = -512;
    double col_adjust = 1.2 / .707;
    for (int j = 0; j < 12; ++j) {
      float angle = (float) (Math.PI * ((hue + (j << 8)) / (12 * 128.0) - 33.0 / 180));
      i_filter[j] = (float) (-col_adjust * Math.cos(angle));
      q_filter[j] = (float) (col_adjust * Math.sin(angle));
    }
    //        utils.printarray(i_filter);
    //        utils.printarray(q_filter);

  }
Пример #29
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y).
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");

    offscreen.drawImage(
        image, (int) Math.round(xs - ws / 2.0), (int) Math.round(ys - hs / 2.0), null);
    draw();
  }
Пример #30
0
 private void conicalGradient(int[] pixels, int y, int w, int h) {
   int off = 0;
   float angle0 = (float) Math.atan2(p2.x - p1.x, p2.y - p1.y);
   for (int x = 0; x < w; x++) {
     float angle = (float) (Math.atan2(x - p1.x, y - p1.y) - angle0) / (ImageMath.TWO_PI);
     angle += 1.0f;
     angle %= 1.0f;
     if (type == BICONICAL) angle = ImageMath.triangle(angle);
     int rgb = colormap.getColor(map(angle));
     pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode);
     off++;
   }
 }