File size: 1,214 Bytes
41dda1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

import numpy as np
from color_conversions import hsv_to_rgb


def generate_color_wheel(resolution=500) -> np.ndarray:
    """
    Generate a color wheel image using HSV to RGB conversion.

    :param resolution: The width/height of the square image
    :return: RGB image of the color wheel
    """
    # Create a 2D grid of indices (X, Y) to calculate the angle and radius
    x = np.linspace(-1, 1, resolution)
    y = np.linspace(-1, 1, resolution)
    xv, yv = np.meshgrid(x, y)

    # Calculate angle (hue) in degrees
    angle = np.arctan2(yv, xv) * (180 / np.pi) + 180  # Range from 0 to 360

    # Calculate radius from the center (used for saturation)
    radius = np.sqrt(xv**2 + yv**2)

    # Normalize radius to range [0, 1]
    radius = np.clip(radius, 0, 1)

    # HSV components
    hue = angle  # Hue is the angle
    saturation = radius  
    # Saturation is proportional to the distance from the center
    # Value is constant (1) for maximum brightness
    value = np.ones_like(radius)

    # Stack the HSV components into a single array
    hsv_image = np.stack((hue, saturation, value), axis=-1)

    # Convert the HSV image to RGB
    rgb_image = hsv_to_rgb(hsv_image)

    return rgb_image