Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This script shows two patches in rapid succession, to get a flicker fusion
- # effect. It requires the PsychoPy backend.
- from psychopy import visual
- from openexp.keyboard import keyboard
- import numpy as np
- size = 512 # Stimulus size
- n = 50 # Number of presentation cycles
- delay = 20 # Delay between presentations (the actual delay depends on the
- # display refresh as well!)
- # Initial colors in HSV color space. See http://www.psychopy.org/general/colours.html
- col1 = [0,1,.5]
- col2 = [180,1,.5]
- colD = .005 # Luminance change per step
- my_keyboard = keyboard(self.experiment, keylist=["up", "down", 'space'],
- timeout=1)
- # Create two stimuli, see
- # http://www.psychopy.org/api/visual/patchstim.html
- patch1 = visual.PatchStim(win, tex=None, mask='gauss', color=col1,
- size=size, colorSpace='hsv')
- patch2 = visual.PatchStim(win, tex=None, mask='gauss', color=col2,
- size=size, colorSpace='hsv')
- # Alternately show the stimuli. Also record the timestamps, so we can verify
- # the timing
- l = []
- while True:
- # Accept when space is pressed, and use up and down to calibrate colors
- resp, time = my_keyboard.get_key()
- if resp == 'space':
- break
- if resp == 'up':
- col1[2] = max(0, min(1, col1[2]+colD))
- col2[2] = max(0, min(1, col2[2]-colD))
- patch1.setColor(col1)
- patch2.setColor(col2)
- if resp == 'down':
- col1[2] = max(0, min(1, col1[2]-colD))
- col2[2] = max(0, min(1, col2[2]+colD))
- patch1.setColor(col1)
- patch2.setColor(col2)
- # Show the two patches
- patch1.draw()
- win.flip()
- self.sleep(delay)
- l.append(self.time())
- patch2.draw()
- win.flip()
- l.append(self.time())
- self.sleep(delay)
- l = l[-100:] # Make sure the list doesn't grow too long
- # Store the actual delay between the two stimuli, and the standard deviation
- # of the delay for offline verification
- a = np.array(l)
- exp.set('mean_soa', np.mean(a[1:]-a[:-1]))
- exp.set('sd_soa', np.std(a[1:]-a[:-1]))
- exp.set('col1', '%s' % col1)
- exp.set('col2', '%s' % col2)
Advertisement
Add Comment
Please, Sign In to add comment