Esempio n. 1
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++;
   }
 }
Esempio n. 2
0
  // From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135
  void drawArrow(
      Graphics2D g2d,
      int xCenter,
      int yCenter,
      int x,
      int y,
      float stroke,
      BasicStroke drawStroke) {
    double aDir = Math.atan2(xCenter - x, yCenter - y);
    // Line can be dashed.
    g2d.setStroke(drawStroke);
    g2d.drawLine(x, y, xCenter, yCenter);
    // make the arrow head solid even if dash pattern has been specified
    g2d.setStroke(lineStroke);
    Polygon tmpPoly = new Polygon();
    int i1 = 12 + (int) (stroke * 2);
    // make the arrow head the same size regardless of the length length
    int i2 = 6 + (int) stroke;
    tmpPoly.addPoint(x, y);
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);

    // Remove this line to leave arrow head unpainted:
    g2d.fillPolygon(tmpPoly);
  }
Esempio n. 3
0
        public void mousePressed(MouseEvent e) {
          requestFocus();
          Point p = e.getPoint();
          int size =
              Math.min(
                  MAX_SIZE,
                  Math.min(
                      getWidth() - imagePadding.left - imagePadding.right,
                      getHeight() - imagePadding.top - imagePadding.bottom));
          p.translate(-(getWidth() / 2 - size / 2), -(getHeight() / 2 - size / 2));
          if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
            // the two circular views:
            double radius = ((double) size) / 2.0;
            double x = p.getX() - size / 2.0;
            double y = p.getY() - size / 2.0;
            double r = Math.sqrt(x * x + y * y) / radius;
            double theta = Math.atan2(y, x) / (Math.PI * 2.0);

            if (r > 1) r = 1;

            if (mode == ColorPicker.BRI) {
              setHSB((float) (theta + .25f), (float) (r), bri);
            } else {
              setHSB((float) (theta + .25f), sat, (float) (r));
            }
          } else if (mode == ColorPicker.HUE) {
            float s = ((float) p.x) / ((float) size);
            float b = ((float) p.y) / ((float) size);
            if (s < 0) s = 0;
            if (s > 1) s = 1;
            if (b < 0) b = 0;
            if (b > 1) b = 1;
            setHSB(hue, s, b);
          } else {
            int x2 = p.x * 255 / size;
            int y2 = p.y * 255 / size;
            if (x2 < 0) x2 = 0;
            if (x2 > 255) x2 = 255;
            if (y2 < 0) y2 = 0;
            if (y2 > 255) y2 = 255;

            if (mode == ColorPicker.RED) {
              setRGB(red, x2, y2);
            } else if (mode == ColorPicker.GREEN) {
              setRGB(x2, green, y2);
            } else {
              setRGB(x2, y2, blue);
            }
          }
        }
Esempio n. 4
0
 protected void transformInverse(int x, int y, float[] out) {
   float dx = x - icentreX;
   float dy = y - icentreY;
   float distance = dx * dx + dy * dy;
   if (distance > radius2) {
     out[0] = x;
     out[1] = y;
   } else {
     distance = (float) Math.sqrt(distance);
     float a = (float) Math.atan2(dy, dx) + angle * (radius - distance) / radius;
     out[0] = icentreX + distance * (float) Math.cos(a);
     out[1] = icentreY + distance * (float) Math.sin(a);
   }
 }
Esempio n. 5
0
  public int filterRGB(int x, int y, int rgb) {
    float dx = x - centreX;
    float dy = y - centreY;
    float distance = dx * dx + dy * dy;
    float angle = (float) Math.atan2(dy, dx);
    float d = (angle + ImageMath.PI) / (ImageMath.TWO_PI) * rays;
    int i = (int) d;
    float f = d - i;

    if (radius != 0) {
      float length = ImageMath.lerp(f, rayLengths[i % rays], rayLengths[(i + 1) % rays]);
      float g = length * length / (distance + 0.0001f);
      g = (float) Math.pow(g, (100 - amount) / 50.0);
      f -= 0.5f;
      //			f *= amount/50.0f;
      f = 1 - f * f;
      f *= g;
    }
    f = ImageMath.clamp(f, 0, 1);
    return ImageMath.mixColors(f, rgb, color);
  }
Esempio n. 6
0
  /** Regenerates the image. */
  private synchronized void regenerateImage() {
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
      float bri2 = this.bri;
      float sat2 = this.sat;
      float radius = ((float) size) / 2f;
      float hue2;
      float k = 1.2f; // the number of pixels to antialias
      for (int y = 0; y < size; y++) {
        float y2 = (y - size / 2f);
        for (int x = 0; x < size; x++) {
          float x2 = (x - size / 2f);
          double theta = Math.atan2(y2, x2) - 3 * Math.PI / 2.0;
          if (theta < 0) theta += 2 * Math.PI;

          double r = Math.sqrt(x2 * x2 + y2 * y2);
          if (r <= radius) {
            if (mode == ColorPicker.BRI) {
              hue2 = (float) (theta / (2 * Math.PI));
              sat2 = (float) (r / radius);
            } else { // SAT
              hue2 = (float) (theta / (2 * Math.PI));
              bri2 = (float) (r / radius);
            }
            row[x] = Color.HSBtoRGB(hue2, sat2, bri2);
            if (r > radius - k) {
              int alpha = (int) (255 - 255 * (r - radius + k) / k);
              if (alpha < 0) alpha = 0;
              if (alpha > 255) alpha = 255;
              row[x] = row[x] & 0xffffff + (alpha << 24);
            }
          } else {
            row[x] = 0x00000000;
          }
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    } else if (mode == ColorPicker.HUE) {
      float hue2 = this.hue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          row[x] = Color.HSBtoRGB(hue2, x2, y2);
        }
        image.getRaster().setDataElements(0, y, image.getWidth(), 1, row);
      }
    } else { // mode is RED, GREEN, or BLUE
      int red2 = red;
      int green2 = green;
      int blue2 = blue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          if (mode == ColorPicker.RED) {
            green2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else if (mode == ColorPicker.GREEN) {
            red2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else {
            red2 = (int) (x2 * 255 + .49);
            green2 = (int) (y2 * 255 + .49);
          }
          row[x] = 0xFF000000 + (red2 << 16) + (green2 << 8) + blue2;
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    }
    repaint();
  }