class SimpleCover(): ''' This class is a simplified version of class Cover for the practice mode. ''' COVER, SHOW = range(2) def __init__(self, win, pos, name, width=0.15, height=0.1, color=(178, 178, 178)): self.rect = Rect(win, height=height, width=width, units='norm', pos=pos) self.rect.setFillColor(color=color, colorSpace='rgb255') self.rect.setLineColor(color=color, colorSpace='rgb255') self.mouse = event.Mouse(win=win) self.state = self.COVER def draw(self): if self.state == self.COVER: self.rect.draw() elif self.state == self.SHOW: pass def process(self): x, y = self.mouse.getPos() # if need to click to see the information, uncomment the following line and comment the line after the following line if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1: # if self.rect.contains(x, y, units='norm'): self.state = self.SHOW elif not self.rect.contains(x, y, units='norm'): self.state = self.COVER
def cue(self, location): y = 0 if location == "left": left_cue = Rect(disp, pos=(self.left_x, y), width=self.width, height=self.height, lineColor=self.cue_color, lineWidth=self.cue_line) right_box = Rect(disp, pos=(self.right_x, y), width=self.width, height=self.height, lineColor=convertRGB(BLACK), lineWidth=self.normal_line) right_box.draw() left_cue.draw() if location == "right": left_box = Rect(disp, pos=(self.left_x, y), width=self.width, height=self.height, lineColor=convertRGB(BLACK), lineWidth=self.normal_line) right_cue = Rect(disp, pos=(self.right_x, y), width=self.width, height=self.height, lineColor=self.cue_color, lineWidth=self.cue_line) right_cue.draw() left_box.draw()
def default_draw(self): y = 0 left_box = Rect(disp, pos=(self.left_x, y), width=self.width, height=self.height, lineColor=self.normal_color, lineWidth=self.normal_line) right_box = Rect(disp, pos=(self.right_x, y), width=self.width, height=self.height, lineColor=self.normal_color, lineWidth=self.normal_line) left_box.draw() right_box.draw()
class Cover(): COVER, SHOW = range(2) def __init__(self, win, pos, name, detail_file, sub_id, test_id, width=0.15, height=0.1, color=(178, 178, 178)): self.name = name self.rect = Rect(win, height=height, width=width, units='norm', pos=pos) self.rect.setFillColor(color=color, colorSpace='rgb255') self.rect.setLineColor(color=color, colorSpace='rgb255') self.mouse = event.Mouse(win=win) self.state = self.COVER self.time = 0 self.single_time = 0 self.last_state = self.COVER self.last_time = 0 self.clk = clock.Clock() self.detail_file = detail_file self.sub_id = sub_id self.test_id = test_id def draw(self): if self.state == self.COVER: self.rect.draw() elif self.state == self.SHOW: pass def process(self): x, y = self.mouse.getPos() # if need to click to see the information, uncomment the following line and comment the line after the following line if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1: # if self.rect.contains(x, y, units='norm'): self.state = self.SHOW elif not self.rect.contains(x, y, units='norm'): self.state = self.COVER if self.last_state == self.SHOW: this_time = self.clk.getTime() - self.last_time self.time += this_time self.single_time += this_time # time记录累加时间,single_time记录单次时间 if self.state == self.COVER: self.detail_file.write(','.join((str(self.sub_id), str(self.test_id), str(self.name), str(self.single_time)))) self.detail_file.write('\n') self.single_time = 0 self.last_time = self.clk.getTime() self.last_state = self.state
def displayRecordResponse(on, trialStart, autoResp, StimLength): # take autoResp and trialStart and returns humanResp and humanRT while True: (button, time) = myMouse.getPressed(getTime=True) autoRT = 0.25 if on > 0: if clock.getTime() > (trialStart + autoRT): if autoResp == 1: target2 = Rect(win, units="deg", width=0.5, height=StimLength, fillColor="FireBrick", lineColor="FireBrick", pos=targpos) else: target2 = Rect(win, units="deg", width=0.5, height=StimLength, fillColor="Lime", lineColor="Lime", pos=targpos) background.draw() target2.draw() win.flip() #Record response (either left or right click) if button[0]: #Left click humanResp = 0 humanRT = time[0] break elif button[2]: #Right click humanResp = 1 humanRT = time[2] break return (humanResp, humanRT)
class Button(): START, END = range(2) def __init__(self, win, pos, width, height, name, text='选择'): self.name = name self.rect = Rect(win, height=height, width=width, units='norm', pos=pos) self.mouse = event.Mouse(win=win) self.caption = TextStim(win, text=text, height=height - 0.01 , pos=pos, units='norm', color=(0, 0, 0), colorSpace='rgb255') self.state = self.START def draw(self): x, y = self.mouse.getPos() if self.rect.contains(x, y, units='norm'): self.rect.setLineColor(color=(0, 0, 204), colorSpace='rgb255') self.caption.setColor(color=(0, 0, 204), colorSpace='rgb255') else: self.rect.setLineColor(color=(0, 0, 0), colorSpace='rgb255') self.caption.setColor(color=(0, 0, 0), colorSpace='rgb255') self.rect.draw() self.caption.draw() def process(self): x, y = self.mouse.getPos() if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1: self.state = self.END
if not mouse.isPressedIn(lbox, buttons=[0]) and lpressed == True: lpressed = False R1 += 1 if p == p_list[1]: score += 1 #process right schedule if mouse.isPressedIn(rbox, buttons=[0]): rpressed = True if not mouse.isPressedIn(rbox, buttons=[0]) and rpressed == True: rpressed = False R2 += 1 if p == p_list[0]: score += 1 lbox.draw() rbox.draw() #target text.text = u'Вы часто видите число 1?' text.pos = (0, -0.2) text.draw() #responses text.text = u'Да' text.pos = (-0.3, -0.6) text.draw() text.text = u'Нет' text.pos = (+0.3, -0.6) text.draw()
units=units, pos=item3_pos) item4 = visual.ImageStim(win, image=i[3], size=size, units=units, pos=item4_pos) item1.draw() item2.draw() item3.draw() item4.draw() win.flip() core.wait(1) win.flip() core.wait(1) yes.draw() no.draw() win.flip() key = event.waitKeys(keyList=['s', 'k']) win.flip() if i in displays_mem: in_mem = 1 else: in_mem = 0 if i in congruent_displays: disp_type = "CS" else: disp_type = "IS" row = info['ID'], info['language'], trial, i[0], i[1], i[2], i[ 3], in_mem, key, disp_type, info['age'], info['gender'] print(row)
win.mouseVisible = True megprac.draw() meg.draw() startButton.draw() win.flip() while myMouse.isPressedIn(startButton) == False: pass for trial in range(startPracticeTrials, endPracticeTrials): win.mouseVisible = False #Create the Aid's response (signal, autoResp, StimLength) = aidResponse(.15, .95) #easy, low FA wait(.5) #Trial begins with the onset of pointers trialStart = clock.getTime() myMouse.clickReset() background.draw() #Draw target targpos = [random.uniform(-1, 1), random.uniform(-1, 1)] target = Rect(win, units="deg", width=0.5, height=StimLength, fillColor=(-1, -1, -1), lineColor=(-1, -1, -1), pos=targpos) target.draw() win.flip() (humanResp, humanRT) = displayRecordResponse(a[condition], trialStart, autoResp, StimLength) #Feedback (trialACC, feedback) = decideFeedback(a[condition], humanResp, signal)
len(durations * reps) - trialnum) + ' left)\nDuration: ' + str( current_stim['duration']) + '\nBackground: ' + bg_color + '' def t_start(): global time_start time_start = kb.clock.getTime() def t_end(): global time_end time_end = kb.clock.getTime() # begin with red rectangle therect.draw() my_win.flip() wait(3) kb.clock.reset() therect.fillColor = bg_color # change to the given background color at start trialnum = 0 therect.draw() my_win.flip() xstart = kb.waitKeys(keyList='x')[0].rt # start with keypress "x" for i in range(reps): # repeat cycle for the given number of repetitions shuffle(durations) for dur in durations: trialnum += 1 current_stim['duration'] = dur disp_text() # display the trial info
pos=item3_pos) item4 = visual.ImageStim(win, image=i[3], size=size, units=units, pos=item4_pos) item1.draw() item2.draw() item3.draw() item4.draw() win.flip() core.wait(1) win.flip() core.wait(1) #Instead of proceeding to the next display we want to collect yes/no answers yes.draw( ) # the green "yes" button (that we created as a rectangular object no.draw() # the red "no" button win.flip() key = event.waitKeys( keyList=['s', 'k']) # participant must press 's' (no) or 'k' (yes) win.flip() if i in displays_mem: # if the i'th (current) displays is in the memorisation set.. in_mem = 1 # we set a variable called in_mem to 1 else: # otherwise.. in_mem = 0 # 0 if i in congruent_displays: # if the i'th (current) displays is found in the list of "congruent" displays disp_type = "CS" # we set a variable "disp_type" to "CS" (congruent set) else: # otherwise disp_type = "IS" # IS # we then define what data to include + the order in each row in our csv file row = info['ID'], info['language'], trial, i[0], i[1], i[2], i[
# show instructions instructionsStim.draw() win.flip() # wait for any key waitKeys(maxWait=float('inf'), keyList=None, timeStamped=True) # 64 trials, randomly selected that are valid # 12 trials that are not valid validData = [] invalidData = [] shuffle(trialsPossible) for trial in trialsPossible: # show initial screen fixStim.draw() leftboxStim.draw() rightboxStim.draw() win.flip() wait(FIXATION_TIME) # show the cue fixStim.draw() leftboxStim.draw() rightboxStim.draw() shuffle(cues) currentCue = cues[0] if currentCue == 'cueleft': cueleftStim.draw()
fbstim = {} fbstim[0] = TextStim(disp, text='Incorrect', height=24, color=(1, 1, -1)) fbstim[1] = TextStim(disp, text='Correct', height=24, color=(-1, 1, -1)) # present instructions inststim.draw() disp.flip() waitKeys(maxWait=float('inf'), keyList=None, timeStamped=True) # wait for key press for cueside in ['left', "right"]: # draw fixation mark and left and right boxes fixstim.draw() lboxstim.draw() rboxstim.draw() fixonset = disp.flip() wait(FIXTIME) fixstim.draw() lboxstim.draw() rboxstim.draw() cuestim[cueside].draw() cueonset = disp.flip() wait(CUETIME) fixstim.draw() lboxstim.draw() rboxstim.draw() cueoffset = disp.flip() wait(0.1 - CUETIME)