質問

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:

enter image description here

I'd like to get a smoother gradient, like:

enter image description here

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!

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top