Thread: How to find each pixel in the circle?

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    6

    How to find each pixel in the circle?

    How can I find each and every pixel in a circle so that I can do some operations on it.

    Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Is this
    - a circle you need to draw?
    - a circle you've already drawn?
    - a circle someone else has drawn, and you need to find it in an image?

    Not to mention, which OS / Compiler / graphics library are you using.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    6
    I've already drawn a circle using mid-point algorithm. And I filled the circle, which is white. But I want to fill the circle by calculating the value of hue, saturation of each pixel. So that it shows the different color and intensity.
    I am using GLUT, C++ in windows.

  4. #4
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Lol use this : Fast Robust Predicates for Computational Geometry

    Use pixel indices as coordinates and boom! Because those routines are robust, they're never wrong. Never. Ever.

    Ever.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    So, in other words you want to draw a color wheel?

    Use the scanline method, and calculate the angle and distance from the centre for each pixel, then color it according to those values. You'll also want some HSV to RGB conversion code.
    What part of this do you now need help with?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Registered User
    Join Date
    Mar 2012
    Posts
    6
    Quote Originally Posted by iMalc View Post
    So, in other words you want to draw a color wheel?

    Use the scanline method, and calculate the angle and distance from the centre for each pixel, then color it according to those values. You'll also want some HSV to RGB conversion code.
    What part of this do you now need help with?

    I am stuck with this part that how can I calculate the angle and distance for each pixel? And how can I implement this in my code. I have HSVtoRGB conversion algorithm. But how can I do this entire process?

  7. #7
    Registered User
    Join Date
    Mar 2012
    Posts
    6
    For HSV to RGB conversion I am using following function.

    Code:
    void HSVtoRGB(float *r, float *g, float *b, float h, float s, float v){
        int i;
        float f, p, q, t;
        if(s == 0)
        {
            *r = *g = *b = v;       //acromatic
            return;
        }
    
    
        h /= 60;
        i = floor(h);
        f = h - i;
        p = v * (1 - s);
        q = v * (1 - s * f);
        t = v * (1 - s * (1 - f));
        switch(i)
        {
            case 0: *r = v; *g = t; *b = p; break;
            case 1: *r = q; *g = v; *b = p; break;
            case 2: *r = p; *g = v; *b = t; break;
            case 3: *r = p; *g = q; *b = v; break;
            case 4: *r = t; *g = p; *b = v; break;
            case 5: *r = v; *g = p; *b = q; break;
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pixel by pixel graphics, what's the name of this technique?
    By PedroTuga in forum Game Programming
    Replies: 6
    Last Post: 12-14-2012, 07:06 PM
  2. Find a pixel?
    By geniusisgenius in forum C Programming
    Replies: 10
    Last Post: 05-13-2010, 01:29 PM
  3. find x,y from pixel
    By JordanCason in forum C++ Programming
    Replies: 4
    Last Post: 11-20-2007, 06:40 PM
  4. Circle
    By rifatgunduz in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2005, 03:56 PM
  5. Whats wrong with my find Circle Area program?[compiles fine]
    By Golden Bunny in forum C++ Programming
    Replies: 22
    Last Post: 06-16-2002, 02:49 PM