Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
python3

What is colorsys.hsv_to_rgb(h, s, v) in Python?

Kainat Asif

The colorsys.hsv_to_rgb(r, g, b) function converts HSV (Hue Saturation Value) coordinates to RGB (Red Green Blue) coordinates.

Declaration

The colorsys module stores the definition of the hsv_to_rgb() function. The colorsys module can be imported using the following code:

import colorsys

colorsys.hsv_to_rgb(h, s, v)

h, s, and v can have any value between 0 and 1 inclusive.

Code

The following code snippet demonstrates the use of hsv_to_rgb():

import colorsys

if __name__ == '__main__':
  h = 0.32
  s = 0.76
  v = 0.29

  r, g, b = colorsys.hsv_to_rgb(h, s, v)

  print('HSV:-')
  print('h: ' + str(h) + '\ns: ' + str(s) + '\nv: ' + str(v))
  print('\nRGB:-')
  print('r: ' + str(r) + '\ng: ' + str(g) + '\nb: ' + str(b))

RELATED TAGS

python
python3

CONTRIBUTOR

Kainat Asif
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring