def __init__(self, win, xPos, index, container): self.xPos = xPos self.yPos = 0.65 self.index = index self.width = container.width / 10 self.height = container.height - 0.15 self.bottom = container.yPos - container.height + 0.142 self.inBin = 0 Verts = make_rectangle_vertices(self.xPos, self.yPos, self.width, self.height) self.Bin = visual.ShapeStim(win, lineWidth=2, lineColor=None, closeShape=True, vertices=Verts) if index == 0: lineCo = None else: lineCo = '#666666' self.Border = visual.ShapeStim( win, lineWidth=2, lineColor=lineCo, vertices=[[self.xPos, self.yPos], [self.xPos, self.yPos - self.height]]) self.Text = visual.TextStim( win, '%s-%s' % (self.index * 10, (self.index + 1) * 10) + '%', alignHoriz='center', color='black', pos=[self.xPos + (self.width / 2), self.yPos - self.height - 0.18], height=0.04)
def make_trial_stimuli(p_win, win_amount): lose_amount = 10 text_win = visual.TextStim(win=win, text='+%i' % win_amount, height=.025, pos=[0, .0375], color=black) text_lose = visual.TextStim(win=win, text='-%i' % lose_amount, height=.025, pos=[0, -.0375], color=black) win_angle = 360 * p_win arc_green = visual.ShapeStim(win=win, name='arc_green', pos=[0, 0], vertices=generate_arc_vertices(win_angle), depth=-1.0, fillColor=green, lineColor=black) arc_grey = visual.ShapeStim(win=win, name='arc_grey', pos=[0, 0], vertices=generate_arc_vertices(win_angle), depth=-1.0, fillColor=grey, lineColor=black) text_win_unknown = visual.TextStim(win=win, text='+??', height=.025, pos=[0, .03], color=black) return arc_green, text_win, text_lose, arc_grey
def __init__(self): """create visual components""" self.line1 = visual.ShapeStim(win, units = 'deg', vertices = ((grid13),(grid14)), lineColor='green', lineWidth=2.5) self.line2 = visual.ShapeStim(win, units = 'deg', vertices = ((grid15),(grid16)), lineColor='green', lineWidth=2.5) self.line3 = visual.ShapeStim(win, units = 'deg', vertices = ((grid17),(grid18)), lineColor='green', lineWidth=2.5) self.line4 = visual.ShapeStim(win, units = 'deg', vertices = ((grid19),(grid20)), lineColor='green', lineWidth=2.5) self.components = [self.line1, self.line2, self.line3, self.line4]
def __init__(self, window, version): self.window = window self.line = visual.ShapeStim(self.window, name='verticle line', lineColor=None, fillColor='black', vertices=[(-2.5, 250), (-2.5, -250), (2.5, -250), (2.5, 250)]) self.dash = visual.ShapeStim(self.window, name='dash line', lineColor=None, fillColor='black', vertices=[(-10, 2.5), (-10, -2.5), (10, -2.5), (10, 2.5)]) self.image_left = visual.ImageStim(self.window, name='stimPic-left', image=None, size=(250, 250), pos=(-250, 0)) self.image_right = visual.ImageStim(self.window, name='stimPic-right', image=None, size=(250, 250), pos=(250, 0)) self.image_mid = visual.ImageStim(self.window, name='stimPic-middle', image=None, size=(100, 100), pos=(0, 0)) self.quest_left = visual.TextStim(self.window, text='?', height=250, pos=(-250, 0), wrapWidth=500, color='black') self.quest_right = visual.TextStim(self.window, text='?', height=250, pos=(250, 0), wrapWidth=500, color='black') self.quest_mid = visual.TextStim(self.window, text='?', height=100, pos=(0, 0), wrapWidth=200, color='white') self.present_left = None self.present_right = None self.present_mid = None self.version = version self.keylist = [] self.keyans = []
def __init__(self, win, maxVal, instructions=None, maxTotal=50): self.win = win self.maxTotal = maxTotal self.container = Container(self.win, -0.75, 0.65, 1.5, 1.5) self.xp = self.container.xPos self.Bins = [] self.Coins = [] self.Deleters = [] self.coinIndexes = [] self.mouse = event.Mouse(win=self.win) self.clockT = core.Clock() self.lastClick = self.clockT.getTime() self.continueButton = visual.ImageStim( self.win, os.getcwd() + '/Resources/gameImages/right_arrow.png', pos=[0.85, 0], size=[0.1, 0.1]) self.BetCounter = visual.TextStim(self.win, '%s Bets' % 0, pos=[0, 0.68], color='black', height=0.06) if instructions: self.instructions = visual.TextStim(self.win, instructions, pos=[-0.9, 0.85], color='black', height=0.05, alignHoriz='left', wrapWidth=1.8) else: self.instructions = None self.otherstimList = [ visual.TextStim(self.win, '0', pos=[-0.77, -0.91], color='black', height=0.05), visual.ShapeStim(win, lineWidth=1, lineColor='black', vertices=[[-0.75, -0.85], [-0.76, -0.88]]), visual.TextStim(self.win, '%s' % maxVal, pos=[0.77, -0.91], color='black', height=0.05), visual.ShapeStim(win, lineWidth=1, lineColor='black', vertices=[[0.75, -0.85], [0.76, -0.88]]), visual.TextStim(self.win, 'Balloon size', pos=[0, -0.94], height=0.05, color='black') ]
def draw_table_lines(win): global con print('con', con) table_rectangle = visual.ShapeStim(win, units='pix', lineWidth=1.5, lineColor=(25,25,25),lineColorSpace='rgb255', vertices=((-225, 375), (200,375),(200,-395),(-225,-395)), closeShape=True, pos=(0, 0), size=1) table_rectangle2 = visual.ShapeStim(win, units='pix', lineWidth=1.5, lineColor=(25,25,25),lineColorSpace='rgb255', vertices=((235, 375), (650,375),(650,-395),(235,-395)), closeShape=True, pos=(0, 0), size=1) line1 = visual.ShapeStim(win, units='pix', lineWidth=1.5, lineColor=(25,25,25),lineColorSpace='rgb255', vertices=((-225, 327), (200,327)), pos=(0, 0), size=1) line2 = visual.ShapeStim(win, units='pix', lineWidth=1.5, lineColor=(25,25,25),lineColorSpace='rgb255', vertices=((235, 327), (650,327)), pos=(0, 0), size=1) line_dotted1 = visual.Line(win, start=(-660, 280), end=(650, 280),lineColor=(25,25,25),lineColorSpace='rgb255') line_dotted2 = visual.Line(win, start=(-660, 148), end=(650, 148),lineColor=(25,25,25),lineColorSpace='rgb255') line_dotted3 = visual.Line(win, start=(-660, 40), end=(650, 40),lineColor=(25,25,25),lineColorSpace='rgb255') line_dotted4 = visual.Line(win, start=(-660, -70), end=(650, -70),lineColor=(25,25,25),lineColorSpace='rgb255') line_dotted5 = visual.Line(win, start=(-660, -175), end=(650, -175),lineColor=(25,25,25),lineColorSpace='rgb255') line_dotted6 = visual.Line(win, start=(-660, -284), end=(650, -284),lineColor=(25,25,25),lineColorSpace='rgb255') text = ['Number of participating countries', 'Costs to average household per \n month', 'Share of emission represented by \nparticipating countries', 'Distribution of cost from \nimplementing the agreement', 'Sanctions for missing emission \nreduction targets', 'Monitoring: Emission reductions \nwill be monitored by'] #shuffle text, put text items in an array random.Random(con).shuffle(text) for i in range(6): start_message = visual.TextStim(win, text=text[i], pos = [-640,215-i*112], height=24,color=[25,25,25],colorSpace='rgb255' ,wrapWidth=win.size[0]*.9, alignHoriz='left') start_message.draw() agreement_message =('Agreement 1','Agreement 2') agreement_message1 = visual.TextStim(win, text=agreement_message[0], pos = [-15,355], height=24,color=[25,25,25],colorSpace='rgb255',wrapWidth=win.size[0]*.9) agreement_message1.draw() agreement_message2 = visual.TextStim(win, text=agreement_message[1], pos = [440,355], height=24,color=[25,25,25],colorSpace='rgb255',wrapWidth=win.size[0]*.9) agreement_message2.draw() table_rectangle.draw() table_rectangle2.draw() line1.draw() line2.draw() line_dotted1.draw() line_dotted2.draw() line_dotted3.draw() line_dotted4.draw() line_dotted5.draw() line_dotted6.draw()
def stimPresent(SSD): # clear event buffer, screen and start ITI event.clearEvents(eventType="keyboard") win.flip() core.wait(ITI) # prepare the stimuli orient = [0, 180] # left: orient[0] = 0; right: orient[1] = 180 arrow_go = visual.ShapeStim(win, vertices=XY, fillColor=CLRS[0], lineWidth=0, pos=(0, 0), ori=orient[trial["goStim"]]) arrow_stop = visual.ShapeStim(win, vertices=XY, fillColor=CLRS[1], lineWidth=0, pos=(0, 0), ori=orient[trial["goStim"]]) # present the go stimulus arrow_go.draw() win.flip() # reset timer and variables exp_timer.reset() signalPresent = False signalTime = 0 # start timer loop trial_continue = True while trial_continue: lapse = exp_timer.getTime() # elapsed time response = event.getKeys( keyList=keys) # check responses; only allow keys listed above # abort experiment when escape key is pressed if response and response[0] == "escape": print("*** EXPERIMENT ABORTED BY USER ***") core.quit() # stop trial if MAXRT has elapsed or when a response is executed if lapse > MAXRT or response: trial_continue = False # check if we have to present a stop signal (take some drawing time into consideration) if lapse > (SSD - .010) and trial["signal"] == 1 and signalPresent == False: arrow_stop.draw() win.flip() signalTime = exp_timer.getTime() signalPresent = True # return some stuff return (response, lapse, signalTime)
def seq_to_stim_binary(mystring, color, win, size): """ Translate sequence to squares. """ myseq = string_to_seq(mystring) length = len(myseq)*size seq_pos = length - size #print(myseq) square_list = [] for mychord in myseq: for mykey in mychord: square = visual.Rect(win, height=size, width=size, lineWidth=0, fillColor=color, pos=((int(mykey) - 2.5)*1.5*size, seq_pos)) square_list.append(square) seq_pos = seq_pos - 2*size lines = [] for x in [-3, -1.5, 0, 1.5, 3]: vertices = [(size*x, length + 0.25*size), (size*x, - length + 0.25*size)] lines.append(visual.ShapeStim(win, vertices=vertices, lineWidth=0.5, closeShape=False, lineColor='black', pos = (0, 0)) ) arrowVertLeft = [(-size*3.2 , - length + 0.25*size ), (-size*3, - length ), (-size*2.8, - length + 0.25*size)] arrowVertRight = [(size*3.2, - length + 0.25*size), (size*3, - length ), (size*2.8, - length + 0.25*size)] arrowLeft = visual.ShapeStim(win, vertices=arrowVertLeft, lineColor='black', fillColor='black', lineWidth=0.5) arrowRight = visual.ShapeStim(win, vertices=arrowVertRight, lineColor='black', fillColor='black', lineWidth=0.5) square_list = square_list + lines + [arrowLeft, arrowRight] return(square_list)
def __init__(self, win): ''' Args: win - psychopy window handle ''' self.win = win # Define colors blue = tuple(np.array([37, 97, 163]) / 255.0 * 2 - 1) green = tuple(np.array([0, 120, 0]) / 255.0 * 2 - 1) red = tuple(np.array([150, 0, 0]) / 255.0 * 2 - 1) yellow = tuple(np.array([255, 255, 0]) / 255.0 * 2 - 1) yellow_linecolor = tuple(np.array([255, 255, 0]) / 255.0 * 2 - 1) # Head parameters HEAD_POS_CIRCLE_FIXED_COLOR = blue HEAD_POS_CIRCLE_FIXED_RADIUS = 0.20 self.HEAD_POS_ELLIPSE_MOVING_HEIGHT = 0.20 self.HEAD_POS_ELLIPSE_MOVING_MIN_HEIGHT = 0.05 # Eye parameters self.EYE_SIZE = 0.03 # Setup control circles for head position self.static_circ = visual.Circle(win, radius = HEAD_POS_CIRCLE_FIXED_RADIUS, lineColor = HEAD_POS_CIRCLE_FIXED_COLOR, lineWidth=4, units='height') self.moving_ellipse = visual.ShapeStim(win, lineColor = yellow_linecolor, lineWidth=4, units='height', fillColor=yellow, opacity=0.1) # Ellipses for eyes self.eye_l = visual.ShapeStim(win, lineColor = 'white', fillColor='white', lineWidth=2, units='height') self.eye_r = visual.ShapeStim(win, lineColor = 'white', fillColor='white', lineWidth=2, units='height') # Ellipses for pupils self.pupil_l = visual.ShapeStim(win, fillColor = 'black', lineColor = 'black', units='height') self.pupil_r = visual.ShapeStim(win, fillColor = 'black', lineColor = 'black', units='height') self.eye_l_closed = visual.Rect(win, fillColor=(1,1,1), lineColor=(1,1,1), units='height') self.eye_r_closed = visual.Rect(win, fillColor=(1,1,1), lineColor=(1,1,1), units='height') self.head_width = 0.25 self.head_height = 0.25
def test_GroupStim(self): win = visual.Window([128,128]) line1 = visual.ShapeStim(win) line2 = visual.ShapeStim(win) group1 = exp.GroupStim(stimuli=line1, name='group1') group2 = exp.GroupStim(stimuli=[line1, line2]) group1.draw() group1.setPos((10, 8)) group2.setOri(10) group1.draw() group2.draw() win.close()
def __init__(self, win, session, fixType="cross", pos=(0.0, 0.0), size=20, lineWidth=1.0, lineColor='white'): """ :Parameters: win : a :class:`~psychopy.visual.Window` object (required) fixType : type of fixation shape size : sizes of fixation shape """ self.ss = session session.setFixation(self) self.dur = session.getExpdata(session.fixDur) if type(size) in [tuple, list]: self.size = np.array(size, float) else: self.size = np.array((size, size), float) self.shapes = [] if fixType == "cross": xy = [[-self.size[0] / 2, 0], [self.size[0] / 2, 0]] h = visual.ShapeStim(win=win, units="pix", vertices=xy, lineWidth=lineWidth, lineColor=lineColor, closeShape=False, pos=pos) self.shapes.append(h) xy = [[0, -self.size[1] / 2], [0, self.size[1] / 2]] v = visual.ShapeStim(win=win, units="pix", vertices=xy, lineWidth=lineWidth, lineColor=lineColor, closeShape=False, pos=pos) self.shapes.append(v)
def create_stimuli(self): """Define stimuli """ self.create_fixation() stim1 = visual.ShapeStim(self.win) stim2 = visual.ShapeStim(self.win) self.s = { 'fix': self.fixation, 'stim1': stim1, 'both': exp.GroupStim(stimuli=[stim1, stim2], name='both') }
def fixture(): line1 = visual.ShapeStim(win, lineWidth=5, lineColor='White', vertices=((-0.2, 0), (0.2, 0), (-0.2, 0), (0.2, 0))) line2 = visual.ShapeStim(win, lineWidth=5, lineColor='White', vertices=((0, 0.2), (0, -0.2), (0, 0.2), (0, -0.2))) line1.draw() line2.draw() win.flip()
def monitor_coordinate_check(win): for i in range(90): texti = str(-450 + 10 * i) #-display_resolution[1]/2 pixel_line_y = visual.ShapeStim( win, units='pix', lineWidth=1.5, lineColor=(55, 255, 255), lineColorSpace='rgb255', vertices=((-750, -450 + 10 * i), (750, -450 + 10 * i)), closeShape=False, pos=(0, 0), size=1.2) pixel_name_y = visual.TextStim(win, text='y=' + texti, height=10, units='pix', pos=[0, -450 + 10 * i], color=[255, 55, 255], colorSpace='rgb255') texti = str(-800 + i * 20) #-display_resolution[0]/2 pixel_line_x = visual.ShapeStim( win, units='pix', lineWidth=1.5, lineColor=(155, 255, 55), lineColorSpace='rgb255', vertices=((-800 + i * 20, -450), (-800 + i * 20, 450)), closeShape=False, pos=(0, 0), size=1) #what size param pixel_name_x = visual.TextStim(win, text=texti, height=9, units='pix', pos=[-800 + i * 20, 0], color=[255, 55, 55], colorSpace='rgb255') pixel_line_x.draw() pixel_line_y.draw() pixel_name_x.draw() pixel_name_y.draw() win.flip()
def test_shape(self): win = self.win arrow = [(-0.4, 0.05), (-0.4, -0.05), (-.2, -0.05), (-.2, -0.1), (0, 0), (-.2, 0.1), (-.2, 0.05)] shape = visual.ShapeStim(win, lineColor='white', lineWidth=1.0, fillColor='red', vertices=arrow, pos=[0, 0], ori=0.0, opacity=1.0, depth=0, interpolate=True) shape.draw() #NB shape rendering can differ a little, depending on aliasing utils.compareScreenshot('shape2_1_%s.png' % (self.contextName), win, crit=12.5) win.flip() # Using .set() shape.contrast = 0.8 shape.opacity = 0.8 shape.ori = 90 shape.draw() assert 'Shape' in "{}".format(shape) # check that str(xxx) is working utils.compareScreenshot('shape2_2_%s.png' % (self.contextName), win, crit=12.5)
def fixation_cross(window: visual.window.Window, x_pos_cross: float, cross_size: float): """ Purpose ------- Define and display the fixation cross. Parameters ---------- window : visual.window.Window Psychopy window. x_pos_cross : float x-position of the dot in pixels. cross_size : float Length of the cross arms in pixels. Returns ------- None. """ fixation_cross = visual.ShapeStim(window, vertices=((0, -cross_size), (0, cross_size), (0, 0), (-cross_size, 0), (cross_size, 0)), lineWidth=20, closeShape=False, lineColor="white", pos=(x_pos_cross, cross_size), units='pix') fixation_cross.draw() window.flip() return
def draw_input(win, item_array_text, item_array_x, item_array_y): global con item_left = item_array_text[1:7] item_right = item_array_text[7:13] print(item_array_text, item_left, item_right) random.Random(con).shuffle(item_left) random.Random(con).shuffle(item_right) print(item_array_text, item_left, item_right) item_array_text_shuffled = item_left + item_right print(item_array_text_shuffled) for i in range(len(item_array_x)): #print(item_array_x[i], item_array_y[i], i, len(item_array_x), len(item_array_text), item_array_text) whitebox = visual.ShapeStim(win, units='pix', lineWidth=1.5, lineColor=(255,255,255),lineColorSpace='rgb255', vertices=((item_array_x[i]+20, item_array_y[i]+20), (item_array_x[i]+20, item_array_y[i]-20), (item_array_x[i]-20, item_array_y[i]-20), (item_array_x[i]-20, item_array_y[i]+20)), closeShape=True, fillColor = (255,255,255), fillColorSpace='rgb255', pos=(0, 0), size=1) #what size param #uncomment white box in case want to create different background on values #whitebox.draw() item_value = visual.TextStim(win, text=item_array_text_shuffled[i], height=14, units='pix', #here we use i+1 because the first number is numbers item pos = [item_array_x[i],item_array_y[i]],color=[0,0,0],colorSpace='rgb255') item_value.draw() win.flip(clearBuffer=False)
def __init__(self, G, st, CP): ''' This will start up, for a period specified within the G, changes to the shapes for the LINESTIM type of NF ''' super(LineCalculations, self).__init__() self.win = G['win'] # our window.. self.tmax = G[ 'EX_TFB'] # this is how long we should display the stimulus on screen. self.thrContainer = CP[ 'thrContainer'] # this is the threshold -- probably also set by on_control_event... self.nfvalueContainer = CP[ 'nfsignalContainer'] # so this will be set (hopefully) by the handle_control_event... self.scaling = G[ 'EX_SCALING'] # to scale... implementation of pos to be done later.. self.st = st # this contains points to all the stimuli. self.patch_color = G['EX_PATCHCOLOR'] self.hb, self.he = G['EX_THERMOCLIMS'] self.colorgap = G['EX_COLORGAP'] self._vert = [] # reset the NFLINE and PATCHES self.st['nf_line'][0] = visual.ShapeStim(self.win, vertices=[(0, 0)], closeShape=False, lineColor='lightblue', size=self.scaling, lineWidth=0) self.st['patches'][:] = []
def draw_lozenge(self, x, y, width, height, colorindex): ''' draw a lozenge to show the defined search limits (x,y) is top-left corner of the bounding box ''' if self.pylinkMinorVer == '1': # Mac version x = x/2; y=y/2; width=width/2;height=height/2; width = width * self.img_scaling_factor height = height* self.img_scaling_factor y = (-y + self.size[1]/2)* self.img_scaling_factor x = (+x - self.size[0]/2)* self.img_scaling_factor color = self.getColorFromIndex(colorindex) if width > height: rad = height / 2 if rad == 0: return #cannot draw the circle with 0 radius Xs1 = [rad*cos(t) + x + rad for t in linspace(pi/2, pi/2+pi, 72)] Ys1 = [rad*sin(t) + y - rad for t in linspace(pi/2, pi/2+pi, 72)] Xs2 = [rad*cos(t) + x - rad + width for t in linspace(pi/2+pi, pi/2+2*pi, 72)] Ys2 = [rad*sin(t) + y - rad for t in linspace(pi/2+pi, pi/2+2*pi, 72)] else: rad = width / 2 if rad == 0: return #cannot draw sthe circle with 0 radius Xs1 = [rad*cos(t) + x + rad for t in linspace(0, pi, 72)] Ys1 = [rad*sin(t) + y - rad for t in linspace(0, pi, 72)] Xs2 = [rad*cos(t) + x + rad for t in linspace(pi, 2*pi, 72)] Ys2 = [rad*sin(t) + y + rad - height for t in linspace(pi, 2*pi, 72)] lozenge = visual.ShapeStim(self.display, vertices = list(zip(Xs1+Xs2, Ys1+Ys2)), lineWidth=2.0, lineColor=color, closeShape=True, units='pix') lozenge.draw()
def __init__(self, win, patch_size, element_size, element_tex, element_sf, drift_rate): xys = poisson_disc_sample(patch_size * 2, element_size / 4) self.xys = xys self.drift_step = drift_rate / win.framerate self.element_size = element_size self.element_tex = element_tex self.element_sf = element_sf self.array = ElementArray( win, xys=xys, nElements=len(xys), sizes=element_size, elementTex=element_tex, sfs=element_sf, ) self.array.pedestal_contrs = 1 self.update_elements() a = np.deg2rad(np.r_[0:363:3, 360:-3:-3, 0]) r = np.r_[np.full(121, 1.), np.full(121, 2.), [1.]] vertices = np.c_[np.cos(a) * r, np.sin(a) * r] self.edge = visual.ShapeStim( win, vertices=vertices, size=patch_size, fillColor=win.color, lineColor=win.color, )
def init_trial_stimuli(self): self.trial_stimuli = { # Fixation stimulus indicating start of the trial 'fixation': visual.ShapeStim(self.test_screen, units=None, lineWidth=4, pos=[0, 0], lineColor='white', closeShape=False, vertices=((0, -10), (0, 10), (0, 0), (-10, 0), (10, 0))), # Trial stimuli 'word': visual.TextStim(self.test_screen, text='', height=35, pos=[0, 0], color='white'), # Hints 'hint_animal': visual.TextStim(self.test_screen, text=u'D <- животное', height=30, pos=[-270, 0], color='white'), 'hint_plant': visual.TextStim(self.test_screen, text=u'растение -> L', height=30, pos=[270, 0], color='white') }
def __init__(self, win, mouse, imageFileName, thickness=3, lineColor='green', dotColor='blue'): '''Set up the gauge figure ellipse + normal''' # raw stuff self.win = win self.mouse = mouse self.thickness = thickness self.lineColor = lineColor self.dotColor = dotColor self.drawDots = True # image self.image = visual.SimpleImageStim(self.win, image=imageFileName) # line stim self.lines = visual.ShapeStim(self.win, lineColor=self.lineColor, lineWidth=self.thickness, fillColor=None, closeShape=False, opacity=0.75, autoLog=True) # self.points = []
def flanker_task(): orientation = [0, 180] position = [(-0.4, 0), (-0.2, 0), (0, 0), (0.2, 0), (0.4, 0)] shape_list = [] # generate 5 stimulus for i in range(5): # generate 5 arrows shape = visual.ShapeStim(win, fillColor='White', vertices=([-2, 0.5], [0.5, 0.5], [0.5, 1.5], [2, 0], [0.5, -1.5], [0.5, -0.5], [-2, -0.5])) shape_list.append(shape) random.shuffle(orientation) ori_side = orientation.pop() ori_middle = orientation.pop() for i in range(len(shape_list)): # draw all 5 stimulus on the screen shape_list[i].size = 0.03 shape_list[i].pos = position[i] if i == 2: shape_list[i].ori = ori_middle else: shape_list[i].ori = ori_side shape_list[i].draw() win.flip() return ori_middle, time.time()
def __init__(self, win, imageFolder): self.win = win # read filnames files = listdir_fullpath(imageFolder) # visuals self.ImageStims = [] for i in range(len(files)): self.ImageStims.append( visual.ImageStim(self.win, image=files[i], pos=(0, 0), size=(1.2, 1.2))) # randomize order random.shuffle(self.ImageStims) #self.Instructions = visual.TextStim(self.win,text="Please type in the letters in the correct order and press enter to confirm",pos=(.0,-.8),height=.07,alignVert='center',wrapWidth=1.5) #self.Stimulus = visual.TextStim(self.win,text="",pos=(.0,.0),height=.15,alignVert='center',wrapWidth=1.5) #self.Response = visual.TextStim(self.win,text="___",pos=(.0,.0),height=.15,alignVert='center',wrapWidth=1.5) self.fixation = visual.ShapeStim(win, units='pix', lineColor='white', lineWidth=3.0, vertices=((-25, 0), (25, 0), (0, 0), (0, 25), (0, -25)), closeShape=False, pos=[0, 0]) self.trialClock = core.Clock()
def shapestim(self, vertices, fix_coor=True, close=False): """ desc: Draws a stimulus definied by a list of vertices __Note:__ Specific to the PsychoPy backend, primarily intended for internal use. Using this function directly will break your experiment when switching backends. arguments: vertices: A list of lists, like [[0,0],[10,10]] containing the vertices of the shape keywords: fix_coor: A boolean indicating whether the vertices are in OpenSesame or PsychoPy format. close: Indicates whether the shape should be closed. """ if fix_coor: _vertices = [self.to_xy(tuple(xy)) for xy in vertices] else: _vertices = vertices if self.fill: fill_color = self.color.backend_color else: fill_color = None stim = visual.ShapeStim(self.experiment.window, units=u"pix", lineWidth=self.penwidth, vertices=_vertices, lineColor=self.color.backend_color, closeShape=close, fillColor=fill_color, interpolate=False) self.stim_list.append(stim)
def shapePres(shapeName,loc,shapeSize,shapeOrient): ''' display a short text message for a fixed duration ''' if shapeName == 'tr': shapeSize = shapeSize * 2 curShape = visual.ShapeStim(win, units='pix', lineWidth=1.5, # width of outline lineColor=black, lineColorSpace='rgb', # color of outline fillColor=black,fillColorSpace='rgb', # color of fill vertices=((-0.5,-0.5),(0.5,-0.5),(0,0.5)), # the four point of the shape size=shapeSize, # size of the shape, units=pixel pos= loc, # position of the shape ori=shapeOrient, # orientation of the shape in degree opacity=1, contrast=1.0, depth=1.0, interpolate=True, autoLog=None, autoDraw=False) else: curShape = visual.Circle(win, pos = loc, radius = shapeSize, units = 'pix', lineWidth=1.5, # width of outline lineColor=black, lineColorSpace='rgb', # color of outline fillColor=black,fillColorSpace='rgb') # color of fill) curShape.draw()
def _fixStim(self): """Returns a fixation cross '+' (as a visual) to be drawn later""" a = self.cueSize/2. vertices = [[0,0], [0,a], [0,-a], [0,0], [-a,0], [a,0], [0,0]] return visual.ShapeStim(self.win, fillColor=None, lineColor='black', lineWidth=self.allWidthPix, units='deg', vertices=vertices)
def test(self): self.ttl_timer = datetime.datetime.now() self.win = visual.Window(size=(self.w_scr, self.h_scr), fullscr=True, monitor='testMonitor') event.globalKeys.add('q', func=self.quit_q) self.win.mouseVisible = False self.fix_cros = visual.ShapeStim( win=self.win, vertices=((0, -self.cross_scl), (0, self.cross_scl), (0, 0), (-self.cross_scl * (6 / 8), 0), (self.cross_scl * (6 / 8), 0)), lineWidth=4, closeShape=False, lineColor="black") for i in range(10): timer_lst = [] in_txt = visual.ImageStim(win=self.win, image='images/instruct/exit.png', pos=(0, 0)) in_txt.draw() self.win.flip() trial_tmr = core.Clock() keys = event.waitKeys(maxWait=3.0, keyList=["z", "slash"], timeStamped=trial_tmr) self.fix_cros.draw() self.win.flip() core.wait(0.5) print(keys)
def test_shape(self): win = self.win shape = visual.ShapeStim(win, lineColor=[1, 1, 1], lineWidth=1.0, fillColor=[ 0.80000000000000004, 0.80000000000000004, 0.80000000000000004 ], vertices=[[-0.5 * self.scaleFactor, 0], [0, 0.5 * self.scaleFactor], [0.5 * self.scaleFactor, 0]], closeShape=True, pos=[0, 0], ori=0.0, opacity=1.0, depth=0, interpolate=True) shape.draw() #NB shape rendering can differ a little, depending on aliasing utils.compareScreenshot('shape1_%s.png' % (self.contextName), win, crit=12.0) win.flip() # Using .set() shape.setContrast(0.8) shape.setOpacity(0.8) shape.draw() utils.compareScreenshot('shape2_%s.png' % (self.contextName), win, crit=12.0)
def test_winScalePosOri(self): """test window.viewScale and .viewPos simultaneous negative-going scale should mirror-reverse, and position should account for that visually, the green square/rect should move clockwise around the text Non-zero viewOri would not currently pass with a nonzero viewPos """ with pytest.raises(NotImplementedError): w = visual.Window(size=(200,200), viewPos=(1,1), viewOri=1) for ori in [0, 45]: self.win.viewOri = ori for offset in [(0,0), (-.4,0)]: if ori and (offset[0] or offset[1]): continue # this combination is NotImplemented self.win.viewPos = offset for scale in [[1,1], # normal: green at lower left [1,-1], # mirror vert only: green appears to move up, text mirrored [-1,-1], # mirror horiz & vert: green appears to move right, text normal but upside down [-1,1], # mirror horiz only: green appears to move down, text mirrored [2,2],[2,-2],[-2,-2],[-2,2]]: # same, but both larger self.win.viewScale = scale self.win.flip() grn = visual.ShapeStim(self.win, vertices=v, pos=pgrn, size=n, fillColor='darkgreen') img = visual.ImageStim(self.win, image=img_name, size=2*n, pos=pimg) grn.draw() img.draw() oristr = str(ori) scalestr = str(scale[0]) + ',' + str(scale[1]) posstr = str(offset[0]) + ',' + str(offset[1]) filename = 'winScalePos_ori%s_scale%s_pos%s.png' % (oristr, scalestr, posstr) utils.compareScreenshot(filename, self.win, crit=15)