def __init__(self, win, size=1, pos=(0, 0), ori=0, nVert=120, shape='circle', units=None, name='', autoLog=True): #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() self._initParams.remove('self') super(Aperture, self).__init__(name=name, autoLog=False) #set self params self.autoLog = False #set this False first and change after attribs are set self.win = win self.size = size self.pos = pos self.name = name self.ori = ori #unit conversions if units != None and len(units): self.units = units else: self.units = win.units # set vertices using shape, or default to a circle with nVerts edges if hasattr(shape, 'lower'): shape = shape.lower() if shape is None or shape == 'circle': vertices = [(0.5 * sin(theta * pi / 180), 0.5 * cos(theta * pi / 180)) for theta in numpy.linspace(0, 360, nVert, False)] elif shape == 'square': vertices = [[0.5, -0.5], [-0.5, -0.5], [-0.5, 0.5], [0.5, 0.5]] elif shape == 'triangle': vertices = [[0.5, -0.5], [0, 0.5], [-0.5, -0.5]] elif type(shape) in [tuple, list, numpy.ndarray] and len(shape) > 2: vertices = shape else: logging.error( "Unrecognized shape for aperture. Expected 'circle', 'square', 'triangle', vertices, or None; got %s" % (repr(shape))) self._shape = ShapeStim(win=self.win, vertices=vertices, fillColor=1, lineColor=None, interpolate=False, pos=pos, size=size, autoLog=False) self.vertices = self._shape.vertices self._needVertexUpdate = True self._reset() #implicitly runs an self.enable() self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self)))
def __init__(self, win, size=1, pos=(0,0), ori=0, nVert=120, shape='circle', units=None, name=None, autoLog=None): #what local vars are defined (these are the init params) for use by __repr__ self._initParams = dir() self._initParams.remove('self') super(Aperture, self).__init__(name=name, autoLog=False) #set self params self.autoLog=False #set this False first and change after attribs are set self.win=win if not win.allowStencil: logging.error('Aperture has no effect in a window created without allowStencil=True') core.quit() self.__dict__['size'] = size self.__dict__['pos'] = pos self.__dict__['ori'] = ori #unit conversions if units!=None and len(units): self.units = units else: self.units = win.units # set vertices using shape, or default to a circle with nVerts edges if hasattr(shape, 'lower'): shape = shape.lower() if shape is None or shape == 'circle': # NB: pentagon etc point upwards by setting x,y to be y,x (sin,cos): vertices = [(0.5*sin(radians(theta)), 0.5*cos(radians(theta))) for theta in numpy.linspace(0, 360, nVert, False)] elif shape == 'square': vertices = [[0.5,-0.5],[-0.5,-0.5],[-0.5,0.5],[0.5,0.5]] elif shape == 'triangle': vertices = [[0.5,-0.5],[0,0.5],[-0.5,-0.5]] elif type(shape) in [tuple, list, numpy.ndarray] and len(shape) > 2: vertices = shape else: logging.error("Unrecognized shape for aperture. Expected 'circle', 'square', 'triangle', vertices, or None; got %s" %(repr(shape))) self._shape = ShapeStim(win=self.win, vertices=vertices, fillColor=1, lineColor=None, interpolate=False, pos=pos, size=size, autoLog=False) self.vertices = self._shape.vertices self._needVertexUpdate = True self._needReset = True # Default when setting attributes self._reset() #implicitly runs a self.enabled = True. Also sets self._needReset = True on every call # set autoLog now that params have been initialised self.__dict__['autoLog'] = autoLog or autoLog is None and self.win.autoLog if self.autoLog: logging.exp("Created %s = %s" %(self.name, str(self)))
def test_elements(self): s = Slider(self.win, size=(1, 0.1)) assert type(s.line) == type(Rect(self.win)) assert type(s.tickLines) == type(ElementArrayStim(self.win)) assert type(s.marker) == type(ShapeStim(self.win)) assert type(s.validArea) == type(Rect(self.win))
def _initialize_elements(self, win, stimulus_a, stimulus_b): stimulus_a.pos = (0, -stimulus_a.size[0] / 2 - 90) stimulus_b.pos = (0, +stimulus_b.size[0] / 2 + 90) self.stimulus_a = stimulus_a self.stimulus_b = stimulus_b self._elements.append(stimulus_a) self._elements.append(stimulus_b) # create arrows for confidence rating # create vertices for the arrow arrow_shape_vertices = [ (0, 0), (230, 0), (220, 8), (230, 0), (220, -8), ] self.arrow_a_shape = ShapeStim( win, vertices=arrow_shape_vertices, size=1, lineColor="black", lineWidth=3, closeShape=False, pos=(-112, 25), ) self.arrow_b_shape = ShapeStim( win, vertices=arrow_shape_vertices, size=1, lineColor="black", lineWidth=3, closeShape=False, pos=(-112, -25), ) self._elements.append(self.arrow_a_shape) # hide the rectangles until they are needed (opacity=0) self.choice_text_rectangle = Rect(win, 40, 40, lineWidth=5, lineColor="black", opacity=0.0) self.choice_stimulus_rectangle = Rect( win, stimulus_a.size[1], stimulus_a.size[0], lineWidth=5, lineColor="black", opacity=0.0, ) self.correct_rectangle = Rect( win, stimulus_a.size[1] + 7.5, stimulus_a.size[0] + 7.5, lineWidth=5, lineColor="green", opacity=0.0, ) self._elements.append(self.choice_text_rectangle) self._elements.append(self.choice_stimulus_rectangle) self._elements.append(self.correct_rectangle) self.arrow_a_text = TextStim( win, text="More confident", color="black", height=25, anchorHoriz="center", alignText="center", pos=(0, +0), ) self.arrow_b_text = self.arrow_a_text self._elements.append(self.arrow_a_text) self.arrow_levels_text: List[TextStim] = [] arrow_levels_values = [1, 2, 3, -1, -2, -3] arrow_levels_texts = [ str(x) if x > 0 else str(-x) for x in arrow_levels_values ] arrow_levels_positions = [(-100, 60), (0, 60), (+100, 60), (-100, -60), (0, -60), (+100, -60)] for (position_x, position_y), text, value in zip(arrow_levels_positions, arrow_levels_texts, arrow_levels_values): item = TextStim(win, text=text, color="black", height=25, pos=(position_x, position_y)) rect = Rect(win, width=25, height=25, lineWidth=0.0, pos=(position_x, position_y)) item.value = value item.clickable_area = rect self.arrow_levels_text.append(item) self._elements.append(item) self._elements.append(rect)