Jump to content
  • Advertisement
Sign in to follow this  
tallano

filled circle with gradient

This topic is 2574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone,
I couldn't find anything so sorry for this probably classic question : I am looking for an algorithm for drawing a 2D circle filled with a gradient.
Thanks guys! wink.gif

Share this post


Link to post
Share on other sites
Advertisement
What kind of gradient? Left to right, bottom to top, from the center outwards, linear, quadratic, ...

What kind of API do you have? Can you draw triangles (like in DirectX, OpenGL) or do you only have a framebuffer and thus must do the rasterisation yourself?

Share this post


Link to post
Share on other sites
define the centre of the circle and use a distance function to control the colour? (assuming radial gradient)

Share this post


Link to post
Share on other sites
Oops, sorry for the lack of details.
The gradient has to be radial, and i have to do it from scratch, e.g. i can only use a "putPixel" function.

Share this post


Link to post
Share on other sites
use Pythagoras theorem to get the distance of the pixel from the centre, then use that to get a value from 0-1 by dividing it by the radius of your gradient then use the result to choose a colour

Share this post


Link to post
Share on other sites
[color=#1C2837][size=2]Wouldn't Pythagoras imply the use of square root and power functions? Isn't there a less cpu consuming method?

Share this post


Link to post
Share on other sites

[color="#1C2837"]Wouldn't Pythagoras imply the use of square root and power functions? Isn't there a less cpu consuming method?


Just a square root. The "power functions" in these case are only a couple of multiplications, which are no big deal. You should probably start doing it that way, and then try to optimize it if you have to. For instance, as a preprocessing step, you can create a 1D texture that is indexed by the distance squared. That way you don't need to take a square root per pixel.

To find the pixels that belong in the circle, you can try to use the midpoint circle algorithm.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!