コード例 #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));
 }
コード例 #2
0
ファイル: AWTDrawer.java プロジェクト: NetLand-NTU/NetLand
  /*
   * (non-Javadoc)
   *
   * @see org.math.plot.render.AbstractDrawer#fillPloygon(double[][])
   */
  public void fillPolygon(float alpha, double[]... pC) {
    int[][] c = new int[pC.length][2];
    for (int i = 0; i < pC.length; i++) {
      c[i] = projection.screenProjection(pC[i]);
    }

    int minx = c[0][0], miny = c[0][1], maxx = c[0][0] + 1, maxy = c[0][1] + 1;
    int[] x = new int[c.length];
    for (int i = 0; i < c.length; i++) {
      x[i] = c[i][0];
      minx = FastMath.min(minx, x[i]);
      maxx = FastMath.max(maxx, x[i]);
    }
    int[] y = new int[c.length];
    for (int i = 0; i < c.length; i++) {
      y[i] = c[i][1];
      miny = FastMath.min(miny, y[i]);
      maxy = FastMath.max(maxy, y[i]);
    }
    if (comp2D.hitClip(minx, miny, maxx - minx, maxy - miny)) {
      Composite cs = comp2D.getComposite();
      comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
      comp2D.fillPolygon(x, y, c.length);
      comp2D.setComposite(cs);
    }
  }
コード例 #3
0
ファイル: AWTDrawer.java プロジェクト: NetLand-NTU/NetLand
 public void drawImage(Image img, float alpha, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) {
   Composite cs = comp2D.getComposite();
   comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
   AffineTransform t =
       getAffineTransform(img.getWidth(canvas), img.getHeight(canvas), _xyzSW, _xyzSE, _xyzNW);
   if (t != null) {
     comp2D.drawImage(img, t, canvas);
   }
   comp2D.setComposite(cs);
 }
コード例 #4
0
ファイル: AWTDrawer.java プロジェクト: NetLand-NTU/NetLand
  public void drawShadowedText(String label, float alpha, double... pC) {
    int[] sC = projection.screenProjection(pC);

    // Corner offset adjustment : Text Offset is used Here
    FontRenderContext frc = comp2D.getFontRenderContext();
    Font font1 = comp2D.getFont();
    int x = sC[0];
    int y = sC[1];
    double w = font1.getStringBounds(label, frc).getWidth();
    double h = font1.getSize2D();
    x -= (int) (w * text_Eastoffset);
    y += (int) (h * text_Northoffset);

    int wc = (int) (w * FastMath.cos(text_angle) + h * FastMath.sin(text_angle));
    int hc = (int) (h * FastMath.cos(text_angle) + w * FastMath.sin(text_angle));
    if (!comp2D.hitClip(x, y, wc, hc)) {
      return;
    }

    if (text_angle != 0) {
      comp2D.rotate(text_angle, x + w / 2, y - h / 2);
    }

    Composite cs = comp2D.getComposite();
    Color c = comp2D.getColor();

    String[] lines = label.split("\n");
    for (int i = 0; i < lines.length; i++) {

      comp2D.setColor(Color.white);
      comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
      comp2D.fillRect(x, y - (int) h, (int) w, (int) h);
      comp2D.setComposite(cs);
      comp2D.setColor(c);

      comp2D.drawString(lines[i], x, y);
      y += h;
    }

    if (text_angle != 0) {
      comp2D.rotate(-text_angle, x + w / 2, y - h / 2);
    }
  }
コード例 #5
0
 public Composite getComposite() {
   return (AlphaComposite.getInstance(AlphaComposite.SRC));
 }
コード例 #6
0
  public void run() {
    Thread me = Thread.currentThread();
    while (getSize().width <= 0) {
      try {
        anim.sleep(500);
      } catch (InterruptedException e) {
        return;
      }
    }

    Graphics2D g2d = null;
    Graphics2D BufferG2D = null;
    Graphics2D ScreenG2D = null;
    BasicStroke solid = new BasicStroke(9.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 9.0f);
    GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    int rule = AlphaComposite.SRC_OVER;
    AlphaComposite opaque = AlphaComposite.SrcOver;
    AlphaComposite blend = AlphaComposite.getInstance(rule, 0.9f);
    AlphaComposite set = AlphaComposite.Src;
    int frame = 0;
    int frametmp = 0;
    Dimension oldSize = getSize();
    Shape clippath = null;
    while (anim == me) {
      Dimension size = getSize();
      if (size.width != oldSize.width || size.height != oldSize.height) {
        img = null;
        clippath = null;
        if (BufferG2D != null) {
          BufferG2D.dispose();
          BufferG2D = null;
        }
        if (ScreenG2D != null) {
          ScreenG2D.dispose();
          ScreenG2D = null;
        }
      }
      oldSize = size;

      if (img == null) {
        img = (BufferedImage) createImage(size.width, size.height);
      }

      if (BufferG2D == null) {
        BufferG2D = img.createGraphics();
        BufferG2D.setRenderingHint(
            RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
        BufferG2D.setClip(clippath);
      }
      g2d = BufferG2D;

      float[] ctrlpts;
      for (int i = 0; i < animpts.length; i += 2) {
        animate(animpts, deltas, i + 0, size.width);
        animate(animpts, deltas, i + 1, size.height);
      }
      ctrlpts = animpts;
      int len = ctrlpts.length;
      gp.reset();
      int dir = 0;
      float prevx = ctrlpts[len - 2];
      float prevy = ctrlpts[len - 1];
      float curx = ctrlpts[0];
      float cury = ctrlpts[1];
      float midx = (curx + prevx) / 2.0f;
      float midy = (cury + prevy) / 2.0f;
      gp.moveTo(midx, midy);
      for (int i = 2; i <= ctrlpts.length; i += 2) {
        float x1 = (midx + curx) / 2.0f;
        float y1 = (midy + cury) / 2.0f;
        prevx = curx;
        prevy = cury;
        if (i < ctrlpts.length) {
          curx = ctrlpts[i + 0];
          cury = ctrlpts[i + 1];
        } else {
          curx = ctrlpts[0];
          cury = ctrlpts[1];
        }
        midx = (curx + prevx) / 2.0f;
        midy = (cury + prevy) / 2.0f;
        float x2 = (prevx + midx) / 2.0f;
        float y2 = (prevy + midy) / 2.0f;
        gp.curveTo(x1, y1, x2, y2, midx, midy);
      }
      gp.closePath();

      g2d.setComposite(set);
      g2d.setBackground(backgroundColor);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

      if (bgChanged || bounds == null) {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      // g2d.clearRect(bounds.x-5, bounds.y-5, bounds.x + bounds.width + 5, bounds.y + bounds.height
      // + 5);
      g2d.clearRect(0, 0, getWidth(), getHeight());

      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setColor(outerColor);
      g2d.setComposite(opaque);
      g2d.setStroke(solid);
      g2d.draw(gp);
      g2d.setPaint(gradient);

      if (!bgChanged) {
        bounds = gp.getBounds();
      } else {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      gradient =
          new GradientPaint(
              bounds.x,
              bounds.y,
              gradientColorA,
              bounds.x + bounds.width,
              bounds.y + bounds.height,
              gradientColorB,
              true);
      g2d.setComposite(blend);
      g2d.fill(gp);

      if (g2d == BufferG2D) {
        repaint();
      }
      ++frame;
      Thread.yield();
    }
    if (g2d != null) {
      g2d.dispose();
    }
  }