public static void fillScaledArc(Graphics g, int x, int y, int r, float scale, int angle1, int angle2, Color c1, Color c2)
{
Graphics2D g2 = (Graphics2D) g;
GradientPaint gp = new GradientPaint(x, y, c1, x, y+(rscale), c2, false);
g2.setPaint(gp);
g.fillArc(x, y, (int)(rscale),(int)(r*scale),angle1,angle2);
}
The above code will draw an arc and then fill it with a gradient from top to bottom. Let’s say that I pass Color.green and Color.red as my c1 and c2 arguments. Now, let’s say that I want to only fill 50% of this arc. However, I want the color to range from half-way to green (in this case kind of greenish-orange) to red . How would I rewrite this function to do this by passing it a percentage (i.e. .5 or .75)?
I’m using this to dynamically draw a health meter on one half of a circle.