Search in sources :

Example 6 with RadialGradientPaint

use of java.awt.RadialGradientPaint in project poi by apache.

the class DrawPaint method createRadialGradientPaint.

protected Paint createRadialGradientPaint(GradientPaint fill, Graphics2D graphics) {
    Rectangle2D anchor = DrawShape.getAnchor(graphics, shape);
    Point2D pCenter = new Point2D.Double(anchor.getX() + anchor.getWidth() / 2, anchor.getY() + anchor.getHeight() / 2);
    float radius = (float) Math.max(anchor.getWidth(), anchor.getHeight());
    float[] fractions = fill.getGradientFractions();
    Color[] colors = new Color[fractions.length];
    int i = 0;
    for (ColorStyle fc : fill.getGradientColors()) {
        colors[i++] = applyColorTransform(fc);
    }
    return new RadialGradientPaint(pCenter, radius, fractions, colors);
}
Also used : Point2D(java.awt.geom.Point2D) ColorStyle(org.apache.poi.sl.usermodel.ColorStyle) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) RadialGradientPaint(java.awt.RadialGradientPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint)

Example 7 with RadialGradientPaint

use of java.awt.RadialGradientPaint in project jdk8u_jdk by JetBrains.

the class RenderTests method makeRadial.

private RadialGradientPaint makeRadial(int numColors, boolean alpha) {
    float interval = 1.0f / (numColors - 1);
    float[] fractions = new float[numColors];
    for (int i = 0; i < fractions.length; i++) {
        fractions[i] = i * interval;
    }
    Color[] colors = makeGradientColors(numColors, alpha);
    return new RadialGradientPaint(0.0f, 0.0f, 10.0f, fractions, colors, CycleMethod.REFLECT);
}
Also used : Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) TexturePaint(java.awt.TexturePaint) RadialGradientPaint(java.awt.RadialGradientPaint) MultipleGradientPaint(java.awt.MultipleGradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 8 with RadialGradientPaint

use of java.awt.RadialGradientPaint in project gephi-plugins-bootcamp by gephi.

the class GlowRenderer method renderJava2D.

public void renderJava2D(Item item, G2DTarget target, PreviewProperties properties) {
    //Params
    Float x = item.getData(NodeItem.X);
    Float y = item.getData(NodeItem.Y);
    Float size = item.getData(NodeItem.SIZE);
    Color color = item.getData(NodeItem.COLOR);
    Color startColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), 32);
    Color endColor = new Color(startColor.getRed(), startColor.getGreen(), startColor.getBlue(), 0);
    float radius = size * 6;
    //Get Java2D canvas
    Graphics2D g2 = target.getGraphics();
    RadialGradientPaint p = new RadialGradientPaint(new Point2D.Double(x, y), radius, new float[] { 0.0f, 1.0f }, new Color[] { startColor, endColor });
    g2.setPaint(p);
    g2.fillOval((int) (x - radius), (int) (y - radius), (int) (radius * 2), (int) (radius * 2));
}
Also used : Point2D(java.awt.geom.Point2D) Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) Graphics2D(java.awt.Graphics2D)

Example 9 with RadialGradientPaint

use of java.awt.RadialGradientPaint in project jdk8u_jdk by JetBrains.

the class BufferedPaints method setRadialGradientPaint.

/********************** RadialGradientPaint support *************************/
/**
     * This method calculates six m** values and a focusX value that
     * are used by the native fragment shader.  These techniques are
     * based on a whitepaper by Daniel Rice on radial gradient performance
     * (attached to the bug report for 6521533).  One can refer to that
     * document for the complete set of formulas and calculations, but
     * the basic goal is to compose a transform that will convert an
     * (x,y) position in device space into a "u" value that represents
     * the relative distance to the gradient focus point.  The resulting
     * value can be used to look up the appropriate color by linearly
     * interpolating between the two nearest colors in the gradient.
     */
private static void setRadialGradientPaint(RenderQueue rq, SunGraphics2D sg2d, RadialGradientPaint paint, boolean useMask) {
    boolean linear = (paint.getColorSpace() == ColorSpaceType.LINEAR_RGB);
    int cycleMethod = paint.getCycleMethod().ordinal();
    float[] fractions = paint.getFractions();
    Color[] colors = paint.getColors();
    int numStops = colors.length;
    int[] pixels = convertToIntArgbPrePixels(colors, linear);
    Point2D center = paint.getCenterPoint();
    Point2D focus = paint.getFocusPoint();
    float radius = paint.getRadius();
    // save original (untransformed) center and focus points
    double cx = center.getX();
    double cy = center.getY();
    double fx = focus.getX();
    double fy = focus.getY();
    // transform from gradient coords to device coords
    AffineTransform at = paint.getTransform();
    at.preConcatenate(sg2d.transform);
    focus = at.transform(focus, focus);
    // transform unit circle to gradient coords; we start with the
    // unit circle (center=(0,0), focus on positive x-axis, radius=1)
    // and then transform into gradient space
    at.translate(cx, cy);
    at.rotate(fx - cx, fy - cy);
    at.scale(radius, radius);
    // invert to get mapping from device coords to unit circle
    try {
        at.invert();
    } catch (Exception e) {
        at.setToScale(0.0, 0.0);
    }
    focus = at.transform(focus, focus);
    // clamp the focus point so that it does not rest on, or outside
    // of, the circumference of the gradient circle
    fx = Math.min(focus.getX(), 0.99);
    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacity(20 + 28 + (numStops * 4 * 2));
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_RADIAL_GRADIENT_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(linear ? 1 : 0);
    buf.putInt(numStops);
    buf.putInt(cycleMethod);
    buf.putFloat((float) at.getScaleX());
    buf.putFloat((float) at.getShearX());
    buf.putFloat((float) at.getTranslateX());
    buf.putFloat((float) at.getShearY());
    buf.putFloat((float) at.getScaleY());
    buf.putFloat((float) at.getTranslateY());
    buf.putFloat((float) fx);
    buf.put(fractions);
    buf.put(pixels);
}
Also used : Point2D(java.awt.geom.Point2D) Color(java.awt.Color) AffineTransform(java.awt.geom.AffineTransform) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) MultipleGradientPaint(java.awt.MultipleGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 10 with RadialGradientPaint

use of java.awt.RadialGradientPaint in project jdk8u_jdk by JetBrains.

the class ReadingInterruptionTest method createTestFile.

private static void createTestFile() {
    int w = 1280;
    int h = 1024;
    BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = { 0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
    RadialGradientPaint p = new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();
    try {
        System.out.println("Create test image " + file.getAbsolutePath());
        boolean b = ImageIO.write(img, "JPEG", file);
        if (!b) {
            throw new RuntimeException("Failed to create test image.");
        }
    } catch (IOException e) {
        throw new RuntimeException("Test failed", e);
    }
}
Also used : Point2D(java.awt.geom.Point2D) Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) IOException(java.io.IOException) RadialGradientPaint(java.awt.RadialGradientPaint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

RadialGradientPaint (java.awt.RadialGradientPaint)12 Color (java.awt.Color)10 Point2D (java.awt.geom.Point2D)10 Graphics2D (java.awt.Graphics2D)7 BufferedImage (java.awt.image.BufferedImage)6 LinearGradientPaint (java.awt.LinearGradientPaint)4 GradientPaint (java.awt.GradientPaint)3 Paint (java.awt.Paint)3 TexturePaint (java.awt.TexturePaint)3 MultipleGradientPaint (java.awt.MultipleGradientPaint)2 Rectangle2D (java.awt.geom.Rectangle2D)2 IOException (java.io.IOException)2 Shape (java.awt.Shape)1 AffineTransform (java.awt.geom.AffineTransform)1 ColorStyle (org.apache.poi.sl.usermodel.ColorStyle)1 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)1