I'm trying to run a simple experiment with method of adjustment in psychopy so that the observer changes the luminance (or contrast) of a polygon with the right and left keys. I don't know what function I should use and how.
Edit: I'm using Builder.
If you're using code, just do something like this:
# Set things up
from psychopy import visual, event
win = visual.Window()
polygon = visual.Polygon(win, fillColor='black')
# Keep doing this until escape key is pressed
while True:
# React to responses by updating contrast
key = event.waitKeys(keyList=['left', 'right', 'escape'])[0]
if key == 'left' and not polygon.contrast < 0.1: # if left key is pressed, change contrast if wouldn't exceed the possible values
polygon.contrast -= 0.1
elif key == 'right' and not polygon.contrast > 0.9: # same here...
polygon.contrast += 0.1
elif key == 'escape':
break # stop the while loop
# Display stimulus with updated attributes.
polygon.draw()
win.flip()
If you're using Builder, you insert a code component under the other stimuli and paste this slightly modified code into the "every frame" tab:
# React to responses by updating contrast
key = event.getKeys(keyList=['left', 'right'])
if key and key[0] == 'left' and not polygon.contrast < 0.1: # if left key is pressed, change contrast if wouldn't exceed the possible values
polygon.contrast -= 0.1
elif key and key[0] == 'right' and not polygon.contrast > 0.9: # same here...
polygon.contrast += 0.1
Untested - see if it works.
To change luminance, you probably want to use the DKL colorspace where luminance is an independent variable. See the psychopy documentation on colorspaces. You can do this like this:
polygon = visual.Polygon(win, colorSpace='dkl', fillColor=[45, 180, 1], lineColor=None)
polygon.fillColor += [5, 0, 0] # increase luminance with constant hue and saturation
polygon.fillColor -= [5, 0, 0] # decrease luminance....