Segmenting a color wheel I'm a fan of elegant ways to condense code. I find this ugly. Been staring at it for a while, can't think of a way to write this with less verbosity (ok, short of shorter var names but that's not what I mean). What do you guys think?

if angle &lt; 60:
    red = 1
    green = angle / 60
    blue = 0
elif angle &lt; 120:
    red = 1 - (angle - 60) / 60
    green = 1
    blue = 0
elif angle &lt; 180:
    red = 0
    green = 1
    blue = (angle - 120) / 60
elif angle &lt; 240:
    red = 0
    green = 1 - (angle - 180) / 60
    blue = 1
elif angle &lt; 300:
    red = (angle - 240) / 60
    green = 0
    blue = 1
else:
    red = 1
    green = 0
    blue = 1 - (angle - 300) / 60


Replying to a request for context:

# a color wheel is drawn using aggdraw like so (the list of 360 colors I've obviously omitted but is contained in 'colors', as are several self-evident vars

for i in range(360):
            brush = aggdraw.Brush(colors[i])
            center = surface_width // 2
            inner_radius = radius - 2
            surface.polygon((center, center,
                           int(round(inner_radius + math.sin((rotation - .25) * PI / 180) * inner_radius)),
                           int(round(inner_radius + math.cos((rotation - .25) * PI / 180) * inner_radius)),
                           int(round(inner_radius + math.sin((rotation + 1.25) * PI / 180) * inner_radius)),
                           int(round(inner_radius + math.cos((rotation + 1.25) * PI / 180) * inner_radius))),
                          brush)
            rotation += 1
            if rotation &gt; 360:
                rotation -= 360
Not a proper methodology nor a code-review but I'll try to explain what I've done.

First, I've put your code in a function returning the (red, green, blue) tuple.

Then, I wrote a tiny bit of code to find the different values taken by the different colors :

prev_t = None
for i in range(362):  # Going a bit further than 360 just out of curiosity
    red, green, blue = foo(i)
    t = blue  # Change this if you care about a different color
    if t != prev_t:
        print(i, t)
    prev_t = t


For the blue color, I got :

(0, 0)
(180, 1)
(360, 0)


which led me to think that the blue value was 1 for values bigger than 180 (because the comments talked about wheels, it made sense to apply a modulo 360).

I got a bit lucky because I started with the blue color which was the easiest. Now, the blue value can be computed with :

angle_blue = angle % 360
blue = angle_blue &gt;= 180


Then, I applied a pretty similar trick to other colors by changing the line t = blue and I realized that they could be computer with a similar logic but with an additional shifting.

Now, the code can be written :

def foo2(angle):
    angle_blue = angle % 360
    blue = angle_blue &gt;= 180

    angle_green = (angle - 60) % 360
    green = angle_green &lt; 180

    angle_red = (angle - 120) % 360
    red = angle_red &gt;= 180

    return red, green, blue


(This code could be written in a more concise way but this version corresponds to the fact that I've progressed by handling one color at a time).

This seems to be working for all tested values as per the assert added to the loop I originally wrote :

for i in range(362):  # Going a bit further than 360 just out of curiosity
    red, green, blue = foo(i)
    red2, green2, blue2 = foo2(i)
    assert red == red2
    assert green == green2
    assert blue == blue2