Reputation: 357
So, I'm trying to create a radial gradient (for static lighting in a game). I came up with this:
int step = 4;
int forLen = (radius / step);
g.setColor(new Color(0, 0, 0, intensity));
for (int i = 0; i < forLen; i++)
g.fillOval(radius - i * step, radius - i * step, i * step * 2, i * step * 2);
But the result i get is this:
I'd like to get a smoother gradient, like:
I tried playing around with the step and the intensity, but i can't get something similar to the gradient above. What would be a good way of doing this?? Thanks in advance!
Upvotes: 2
Views: 3655
Reputation: 27220
I don't have a concrete answer, but the look of the second picture left me the impression that the intensity is not decreasing linearly, but rather exponentially.
Could you try instead of doing a linear decreasing function, use a exponential function instead? For every step outwards, multiply the intensity with a fixed number a
< 1.
Upvotes: 2