Color Picker Library
color_picker
CircuitPython helper library to select color using a color wheel in resistive displays using DisplayIO library
Author(s): Jose David M.
Implementation Notes
- class color_picker.color_picker.ColorPicker(*args: Any, **kwargs: Any)
A widget to be used to select colors from a heel.
- Parameters:
Quickstart: Importing and using the Color Picker
Here is one way of importing the
ColorPicker
class so you can use:from adafruit_displayio_color_picker import color_picker
Now you can create an Slider at pixel position x=20, y=30 using:
my_colorpicker=color_picker.ColorPicker(x=20, y=30)
Once you setup your display, you can now add
my_colorpicker
to your display using:display.show(my_colorpicker) # add the group to the display
If you want to have multiple display elements, you can create a group and then append the slider and the other elements to the group. Then, you can add the full group to the display as in this example:
my_colorpicker= ColorPicker(20, 30) my_group = displayio.Group(max_size=2) # make a group that can hold 2 items my_group.append(my_colorpicker) # Add my_colorpicker to the group # # Append other display elements to the group # display.show(my_group) # add the group to the display
Final Notes
Depending on the screen results may vary. Resolution of the bitmap will no be as seen in a PC. Sensitivity of the screen could also affect the behaviour of the library.
The Color Picker Widget
- contains(touch_point)
Checks if the ColorPicker was touched. Returns True if the touch_point is within the ColorPicker’s touch_boundary.
- Parameters:
touch_point (Tuple[x,y]) – x,y location of the screen, converted to local coordinates.
- Returns:
Boolean
- when_selected(touch_point, screen_height)
Response function when ColorPicker is selected. When selected, the ColorPicker will give the color corresponding with the position
- Parameters:
touch_point – x,y location of the screen, in absolute display coordinates.
screen_height (int) – screen height
- Returns:
Color
wheel_maker
Save a displayio.Bitmap (and associated displayio.Palette) in a BMP file.
This script is adapted in the works from Dave Astels on the adafruit_bitmapsaver
and the works of Jackson Glabbard
https://jg.gg/2012/05/28/generating-a-color-picker-style-color-wheel-in-python/
https://github.com/jacksongabbard/Python-Color-Gamut-Generator/blob/master/color-wheel-generator.py
and Kevin Matocha on the switch_round
for the _color_to_tuple
function
Author(s): Dave Astels, Jackson Glabbard, Kevin Matocha, Jose David M.
Implementation Notes
- color_picker.wheel_maker.color_to_tuple(value)
Converts a color from a 24-bit integer to a tuple. :param value: RGB LED desired value - can be a RGB tuple or a 24-bit integer.
- color_picker.wheel_maker.make_color(base, adj, ratio, shade)
Go through each bit of the colors adjusting blue with blue, red with red, green with green, etc.
- color_picker.wheel_maker.make_wheel(image_name, img_size, bg_color=0)
- Parameters:
image_name – Name of the ouput bitmap image
img_size – size of the bitmap image in pixels height=width
bg_color – color of the background in 24 bit format. Defaults 0x000000
- Returns:
color
Quickstart: Importing and using the make_wheel
Here is one way of importing the
make_wheel
module so you can use:from adafruit_displayio_color_picker import wheel_maker
Now you can create a wheel of 200 pixels with a black background using:
make_wheel("wheel200.bmp", 200 , 0x000000)