0

I'm trying to write a paint program using pygame. I'm using a color wheel to allow the user to choose their preferred color to draw with. First i confirm that they've clicked on the color wheel, get their location

> if colorRect.collidepoint((mx,my)) and mb[0]==1: #if clicked on colorhwheel
>         pos=mx,my

I don't know how to set the x and y limits for each color, so that i can sense the color they've clicked on. here's an image of the color wheel i'm using.

https://i.stack.imgur.com/IjLZq.png

thanks for your help!

  • 2
    If you consider the center to be `(0,0)` you can get the coordinate of their mouse click, then find the angle from the origin `ang = math.atan2(dy, dx)`. Then say you have 10 colors, your areas will be 0 to 36 deg, 36 to 72, 72 to 108, etc. – Cory Kramer Dec 21 '14 at 22:17
  • 1
    I think you may run into be some issues using `math.atan()`. One of which being due to the fact that the regions on your color wheel don't appear to start at 0°, so you'll need to adjust for that. A better approach might be to just read the color of the pixel where the user clicked. That would more or less be independent of the exact layout and shape of the wheel. The answer to the question [_Getting pixel color at location with pygame_](http://stackoverflow.com/q/10215803/355230) describes how to do that. – martineau Dec 22 '14 at 02:24

0 Answers0