fill Arc - Java 2D Graphics

Java examples for 2D Graphics:Arc

Description

fill Arc

Demo Code

/* Mesquite source code.  Copyright 1997 and onward, W. Maddison and D. Maddison. 


Disclaimer:  The Mesquite source code is lengthy and we are few.  There are no doubt inefficiencies and goofs in this code. 
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.

Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org

This source code and its compiled class files are free and modifiable under the terms of 
GNU Lesser General Public License.  (http://www.gnu.org/copyleft/lesser.html)
 */// w  ww .  j  a  v a 2  s  .  c o  m
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;

public class Main{
    public static void fillArc(Graphics g, int x, int y, int w, int h,
            int startAngle, int arcAngle, boolean threeD) {
        if (arcAngle < 1)
            return;
        if (MesquiteTrunk.isWindows()) { //this is workaround to Windows problem by which goes all black if too close to 0 or 360
            int spotsize = MesquiteInteger.maximum(w, h);
            if (3.14 * spotsize * (360 - arcAngle) / 360 < 1) {
                fillOval(g, x, y, w, h, threeD);
                return;
            }
            if (3.14 * spotsize * arcAngle / 360 < 1)
                return;
        }
        if (threeD) {
            Color c = g.getColor();
            Color current = c;
            //         TODO: needs to define a polygon that clips to prevent upward curved edges on left side
            current = ColorDistribution.darker(current, 0.75);
            while (w > 0) {
                g.setColor(current);
                g.fillArc(x, y, w, h, startAngle, arcAngle);
                x++;
                y++;
                w -= 4;
                h -= 4;
                current = ColorDistribution.brighter(current, 0.75);
            }
            if (c != null)
                g.setColor(c);
        } else
            g.fillArc(x, y, w, h, startAngle, arcAngle);
    }
    public static void fillOval(Graphics g, int x, int y, int w, int h,
            boolean threeD) {
        try {
            Graphics2D g2 = (Graphics2D) g;
            Stroke st = g2.getStroke();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            if (threeD) {
                Color c = g.getColor();
                Color current = c;
                current = ColorDistribution.darker(current, 0.75);
                while (w > 0) {
                    g.setColor(current);
                    g.fillOval(x, y, w, h);
                    x++;
                    y++;
                    w -= 4;
                    h -= 4;
                    current = ColorDistribution.brighter(current, 0.75);
                }
                if (c != null)
                    g.setColor(c);
            } else
                g2.fillOval(x, y, w, h);
            g2.setStroke(st);

        } catch (NullPointerException e) {
            MesquiteMessage.warnProgrammer("npe in fill oval x " + x
                    + " y " + y + " w " + w + " h " + h);
        }
    }
}

Related Tutorials