| Reference | Downloads | Github

How can I create a color picker with 2 color dimensions (hue and brightness)?

Hi everyone,

I’m currently trying to build a color picker tool that dynamically changes the color of a stimulus the subject sees on their screen. I used the slider tool in the Builder, but it seems like I can only set the color range to rgb, hsv, dkl, and lms, but those contain only the color hues, not different levels of brightness.
What I’d like to do is let the subject pick a certain hue (e.g. blue, yellow, green,…) and then adjust the brightness of the color using a color picker. Is there some way to do this in PsychoPy?

Thanks in advance!


This depends how you define “brightness” - you could set the colours in RGB and add/subtract equally from each value.

I’m currently working on a bit of a change to how colours work in PsychoPy, this is very much in the development stage but you’re welcome to give it a try! In 2020.2.5 (which should be out in the next few days) the classes and methods for colours will be included, but not linked to anything yet. You can however use these as a medium to edit colours as follows:

# Import the Color class
from psychopy.colors import Color
# Create a color (in this case, mid grey specified by name)
myColor = Color('grey', colorSpace='named')
# Set the stimulus to be this color in rgb by accessing its "rgb" property
myStim.color = myColor.rgb
# Check against whatever condition you're using
if someCondition:
    # Add whatever value to the brightness of the color - this will uniformly increase each rgb value
    myColor.brightness += 0.1
    # Once again set the color of the stimulus using rgb, this will supply it with the new value
    myStim.color = myColor.rgb

you’d link this to a slider like this:

myColor.brightness = mySlider.value

(assuming mySlider has a range of 0 to 1)

Once properly integrated (hopefully in 2021.0) you will be able to just do:

myStim.color = 'grey'
if someCondition:
    myStim._foreColor.brightness += 0.1

and the rest will happen behind the scenes, but I’ve got a bit of work to do to make that happen!