How to draw a circle

Hi Everyone,

I need to draw a circle as below. But I have no idea how to do that.
I have 8 parts, and I can click on every part to change the color.
Please help!
Thank you

phraser_demo

The best thing is that you learn how it works and solve it yourself, since you will need it more times, it is not very difficult. Basically it is to convert from angle and distance to (x, y) to draw, and vice versa to detect clicks or collisions.

so once you know that, you can draw a line by converting the desired angle and distance to the 2 points (x, y). in the same way, you can detect that a point x, y is inside a circular section by converting to angle / distance, then checking that they are in the appropriate range.

to convert from angle/distance to (x, y)

ang_rad = ang_degrees / 360 * (PI * 2)
x = cos (ang_rad) * distance, y = sin (ang_rad) * distance

to convert from (x, y) to angle/distance

ang_rad = atan2 (y, x);
ang_degrees = ang_rad / (PI * 2) * 360
distance = sqrt (x * x + y * y);

2 Likes

Another option is to create a rotary slider going from 1 to 8 in steps of 1. Modify the Slider::RotaryParameters starting and ending angle so it goes full circle. Then override its paint methods. In the end you have all the power of a slider, but the look of a circle :slight_smile:

1 Like

Thank you @Marcusonic ,
Base on your suggestion, I can draw the picture now :+1: