1

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.

user3200664
  • 15
  • 1
  • 5

1 Answers1

0

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....
Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
  • 1
    Hi Jonas, I don't think adding a while loop in a code component in Builder is wise: it will muck up Builder's control of the timing and event loop. One should avoid putting in any code that will last longer than a reasonable proportion of a single screen refresh. You're also hijacking Builder's default response to the escape key to terminate the loop. – Michael MacAskill May 12 '15 at 21:36
  • @user3200664 : you should specify if you are using Builder or Coder in your question in order to get a specific answer. – Michael MacAskill May 12 '15 at 21:37
  • Thanks @Jonas Lindeløv, Builder code works. However the stimulus doesn't get brighter than the original stimulus luminance it just gets darker.(Once it's darker the 'right' button works but it only returns to its original lumiance). Is there anything I can do about that? – user3200664 May 13 '15 at 12:33
  • @user3200664, have you used the luminance code I posted? Naturally, you wouldn't use contrast to increase/decrease brightness. (Contrast just aligns the colors with grey (contrast=0) or with extremes (contrast=1)) – Jonas Lindeløv May 15 '15 at 09:31