示例#1
0
    def __init__(self, mywin):
        self.mywin = mywin

        # Alien stimuli
        self.enemy_line = visual.Line(
            win=self.mywin,
            start=(-self.mywin.size[0] / 2, self.mywin.size[1] / 2 + pos_corr),
            end=(self.mywin.size[0] / 2, self.mywin.size[1] / 2 + pos_corr),
            lineColor='red')
        self.enemy_line.setAutoDraw(True)
        self.enemy = visual.Circle(
            win=self.mywin,
            pos=[
                np.random.randint(self.mywin.size[0] * 0.75) -
                self.mywin.size[0] * 0.375, self.mywin.size[1] / 2 + pos_corr
            ],
            radius=self.mywin.size[0] / 20,
            edges=32,
            fillColor=[-1, 1, -1],
            units='pix')
        self.enemy.setAutoDraw(True)
示例#2
0
def slideshow(endpoint,map="None"): 
    if (map=="None"): 
        map=np.repeat("",10)
    box = visual.Rect(window, width=wBox, height=hBox)
    blank=visual.TextStim(window,"")
    ans=visual.TextStim(window,text=map[0],
                        pos=(0,100),
                        height=40,bold=True,
                        anchorVert="bottom")
    for i in range(nLen):
        im=visual.Line(window, start=[-endpoint[i],0],
                       end=[endpoint[i],0])  
        ans.text=map[i]        
        im.draw()
        ans.draw()
        box.draw()
        window.flip()
        box.draw()
        event.waitKeys()
        blank.draw()
        window.flip()
def psychopy_line(width=800, height=600, x=0, y=0, x1=None, y1=None, x2=None, y2=None, length=1,
                  rotate=0, size=1, color="black", background="white", window=None,
                  blur=0, full_screen=False, adjust_width=False, adjust_height=False):
    """
    Examples
    --------
    >>> import pyllusion as ill
    >>>
    >>> window = ill.psychopy_line(x=0, y=0, length=1)
    """

    # Draw window
    win = visual.Window(size=[width, height], fullscr=full_screen,
                        screen=0, winType='pyglet', allowGUI=False,
                        allowStencil=False,
                        monitor='testMonitor', color=background, colorSpace='rgb',
                        blendMode='avg', useFBO=True, units='norm')

    # Get coordinates
    coord, leng, angle = _coord_line(image=window, x=x, y=y, x1=x1, y1=y1, x2=x2, y2=y2,
                                     length=length, angle=rotate,
                                     adjust_width=adjust_width, adjust_height=adjust_height)

    # Line parameters
    line = visual.Line(win=win, units='norm', lineColor=color, lineWidth=size)
    line.start = [coord[0], coord[1]]
    line.end = [coord[2], coord[3]]
    
    # blur
    if blur > 0:
        line.opacity = blur
    
    # Display
    while True:
        line.draw()
        win.flip()
    
        if 'escape' in event.getKeys():
            win.close()
            core.quit()
示例#4
0
    def test_write(self):
        win = visual.Window([600, 400], units='height')
        svg = exp.SVG(win, filename='stims')

        circle = visual.Circle(win,
                               pos=(-.5, 0),
                               fillColor='yellow',
                               lineColor=None)
        circle.draw()
        svg.write(circle)

        line = visual.Line(win, pos=(0, 0), lineColor='black', lineWidth=5)
        line.draw()
        svg.write(line)

        rect = visual.Rect(win, height=.8, pos=(.5, 0))
        rect.draw()
        svg.write(rect)

        shape = visual.ShapeStim(win, fillColor='blue', opacity=.5)
        shape.draw()
        svg.write(shape)

        text = visual.TextStim(win, pos=(.5, 0.25))
        text.draw()
        svg.write(text)

        thick = exp.ThickShapeStim(win,
                                   vertices=[(-.5, .5), (.5, -.5)],
                                   lineWidth=.01)
        thick.draw()
        svg.write(thick)

        win.flip()
        #win.getMovieFrame()
        #win.saveMovieFrames('stims.png')
        #svg.save()

        core.wait(5)
示例#5
0
        def __init__(self, cfg, nticks=40):

            # save this stuff in the ruler object:
            self.nticks = nticks
            self.cfg = cfg

            # create ruler tick stuff:
            self.x = np.linspace(-(cfg['height'] / 2), (cfg['height'] / 2),
                                 nticks)
            self.y1 = (cfg['height'] / 4) - (cfg['height'] / 50)
            self.y2 = (cfg['height'] / 4) + (cfg['height'] / 50)

            # create all the lines:
            self.ticklines = []
            for tickn in range(nticks):
                self.ticklines.append(
                    visual.Line(cfg['win'],
                                start=(self.x[tickn], self.y1),
                                end=(self.x[tickn], self.y2),
                                lineWidth=4,
                                lineColor=(0, 0, 0),
                                lineColorSpace='rgb255'))
示例#6
0
def trialAbsId(endpoint, map):
    box = visual.Rect(window, width=wBox, height=hBox)
    im = visual.Line(window, start=[-endpoint, 0], end=[endpoint, 0])
    feedback = visual.TextStim(window,
                               text=map,
                               pos=(0, 100),
                               height=20,
                               bold=True,
                               anchorVert="bottom")
    blank = visual.TextStim(window, "")
    timer.reset()
    im.draw()
    box.draw()
    window.flip()
    box.draw()
    keys = event.waitKeys(keyList=('1', '2', '3', '4', '5', '6', '7',
                                   abortKey),
                          timeStamped=timer)
    resp = keys[0][0]
    rt = keys[0][1]
    if resp == abortKey:
        window.close()
        core.quit()
    if (resp == map):
        correct1.play()
        correct2.play()
        core.wait(.5)
    else:
        feedback.text = "Error. Your Answer: " + resp + ".  Correct Answer: " + map
        im.draw()
        feedback.draw()
        window.flip()
        box.draw()
        event.waitKeys()
    blank.draw()
    window.flip()
    core.wait(.5)
    return (resp, rt)
示例#7
0
    def make_dashed(win, G, b, e, N, d):
        lines = []
        b = (float(b[0]), float(b[1]))
        e = (float(e[0]), float(e[1]))
        # diff=(e[0]-b[0], e[1]-b[1])
        # print(diff/float(N)*d)
        # scaling:
        if b[0] == e[0]:
            scalingx = 0
        else:
            scalingx = (e[0] - b[0]) / (e[0] - (e[0] - b[0]) / float(N) *
                                        (1 - d) - b[0])
        if b[1] == e[1]:
            scalingy = 0
        else:
            scalingy = (e[1] - b[1]) / (e[1] - (e[1] - b[1]) / float(N) *
                                        (1 - d) - b[1])

        for i in range(N):
            #print('i='+str(i))
            #print(N)
            #print(float(1+i))
            xposb = b[0] + (e[0] - b[0]) / float(N) * float(i) * scalingx
            yposb = b[1] + (e[1] - b[1]) / float(N) * float(i) * scalingy
            xpose = xposb + (e[0] - b[0]) / float(N) * d * scalingx
            ypose = yposb + (e[1] - b[1]) / float(N) * d * scalingy

            #xpose = xposb+0.1
            # ypose = yposb+0.1
            # print([xposb, yposb, xpose, ypose])

            lines.append(
                visual.Line(win,
                            start=(xposb, yposb),
                            end=(xpose, ypose),
                            lineWidth=G['EX_THRLINEWIDTH']))

        return lines
示例#8
0
 def __init__(self,win,pos,width,height,incr,decr_butts,incr_butts,
              conf_butts,richtung=0,midline_length=1,midline_pos=0,
              overcolor=(0,0,1),undercolor=(1,0,0),visobjs_extras={}):
     rval = midline_pos
     r2a = Rel2Abs(pos,width,height,midline_pos,richtung)
     visobjs={}
     visobjs["frame"]=VisObj(visual.Rect(win,units="norm",pos=pos,
            width=width,height=height,lineColor=(-1,-1,-1)))
     visobjs["valrect"]=VisObj(visual.Rect(win,units="norm",pos=(0,0),
            width=0,height=0,lineColor=(-1,-1,-1),fillColor=(0,0,0)))
     visobjs["midline"]=VisObj(visual.Line(win,r2a((midline_pos,midline_length)),
       r2a((midline_pos,-midline_length)),lineColor=(-1,-1,-1)))
     
     self.visobjs = {**visobjs, **visobjs_extras}
     self.r2a = r2a
     self.rval = rval
     self.midline_pos = midline_pos
     self.incr = incr
     self.incr_butts = incr_butts
     self.decr_butts = decr_butts
     self.conf_butts = conf_butts
     self.overcolor = overcolor
     self.undercolor = undercolor
示例#9
0
                               sf=5.0 / 7)
maskLeft = visual.GratingStim(win=win,
                              units="deg",
                              size=7,
                              pos=(-4, 0),
                              sf=5.0 / 7)
#mask.sf = 5.0 / 7

#Feedback
corSnd = sound.Sound(2200, octave=14, secs=0.01)  # auditory feedback
incorSnd = sound.Sound(800, octave=7, secs=0.01)  # auditory feedback

#Underline as Cue
lineLeft = visual.Line(win,
                       start=(-1, -1.5),
                       end=(-8, -1.5),
                       lineColor=[-1, -1, -1],
                       lineWidth=8.5)
lineRight = visual.Line(win,
                        start=(1, -1.5),
                        end=(8, -1.5),
                        lineColor=[-1, -1, -1],
                        lineWidth=8.5)

stimSize = 2.5  #size of the text
textFont = 'Courier'
wordlistE = ['shareef', '7aneen', 'kaman', 'sa2el', 'kamal', '3aneed']
wordlist1 = [u'شريف', u'حنين', u'كمان', u'سائل', u'كمال', u'عنيد']  #word list1
wordlist1Form = [u'عريف', u'حزين', u'زمان', u'سائم', u'رمال',
                 u'عميد']  #similar form condition
wordlist1Root = [u'أشرف', u'حنان', u'كمين', u'سؤال', u'كامل',
hello_grid = visual.Rect(win,
                         units="deg",
                         fillColor="black",
                         pos=(8, 6),
                         size=6,
                         fillColorSpace='rgb')
hello_text = visual.TextStim(win,
                             text="Hello",
                             pos=(8, 6),
                             color=(1, 1, 1),
                             colorSpace='rgb')

# line to connect 2 rightmost moving circles
line_connect = visual.Line(win,
                           start=(-4, 0),
                           end=(4, 0),
                           lineColor="white",
                           lineColorSpace='rgb')

angle = 0
angle2 = 0

running = True

while running == True:

    dots = []
    dots2 = []
    dots3 = []
    light_dots = []
示例#11
0
if expInfo['frameRate'] != None:
    frameDur = 1.0 / round(expInfo['frameRate'])
else:
    frameDur = 1.0 / 60.0  # couldn't get a reliable measure so guess

# Initialize components for Routine "trial"
trialClock = core.Clock()
ISI = core.StaticPeriod(win=win, screenHz=expInfo['frameRate'], name='ISI')
TopUpperLine = visual.Line(win=win,
                           name='TopUpperLine',
                           units='norm',
                           start=(- [2, 0.95][0] / 2.0, 0),
                           end=(+ [2, 0.95][0] / 2.0, 0),
                           ori=0,
                           pos=[0, 0.65],
                           lineWidth=2,
                           lineColor=[1, 1, -1],
                           lineColorSpace='rgb',
                           fillColor='[1,1,-1]',
                           fillColorSpace='rgb',
                           opacity=1,
                           depth=-1.0,
                           interpolate=True)
UpperText = visual.TextStim(win=win,
                            ori=0,
                            name='UpperText',
                            text='default text',
                            font='Courier',
                            units='norm',
                            pos=[0, 0.4],
                            height=0.2,
示例#12
0
            ]:  # congruent incongruent
                #                for cond in ['identity','control','form','morphological']:
                stimList.append({
                    'cue': cue,
                    'resp': resp,
                    'cong': cong,
                    'word': word
                })
trials = data.TrialHandler(stimList, 2)
trials.data.addDataType('accuracy')
trials.data.addDataType('RT')
clockRT = core.Clock()

for thisTrial in trials:
    linew1 = visual.Line(
        win, start=(0, 2), end=(0, -3), pos=(0, 0),
        lineColor=[-1, -1,
                   -1])  #to draw a vertical line separating the word-halves
    linew2 = visual.Line(
        win, start=(0, 2), end=(0, -3), pos=(0, 0),
        lineColor=[-1, -1,
                   -1])  #to draw a vertical line separating the word-halves

    if trials.thisTrial.cue == 'right':  #if right is target
        cue = cueRight
        if trials.thisTrial.resp == 'same':  # if same trial, Target half same
            corresp = 1  # correct response = 1
            if trials.thisTrial.cong == 'congruent':  # if congruent trial
                word1 = visual.TextStim(win,
                                        font=textFont,
                                        text=wordlist1[trials.thisTrial.word],
                                        color=(-1, -1, -1),
示例#13
0
    def start(self):

        #######
        iViewXAPI.iV_StartRecording()

        t = 0
        baselineClock = core.Clock()
        baselineClock.reset()
        frameN = -1
        continueRoutine = True
        endExpNow = False
        while continueRoutine and self.routine_timer.getTime() > 0:
            # Current time and frame
            t = baselineClock.getTime()
            frameN = frameN + 1

            # API Call
            # Collect pupil eye diameter
            res = iViewXAPI.iV_GetSample(byref(sampleData))
            self.current_baseline_val = (
                sampleData.leftEye.diam
            )  # /32 fur highspeed eyetracker, ohne /32 fur RED

            # The following if statements remove blinks, etc. Use as is

            #--------------------
            # state 0: starting
            #--------------------
            if self.state_no == 0:
                if self.lmarker < 1:
                    self.lmarker = self.lmarker + 1
                    self.baseline_vals[
                        self.lmarker] = self.current_baseline_val
                    self.state_next = 0

                else:
                    if self.current_baseline_val > self.lower_th and self.baseline_vals[
                            self.
                            lmarker] > self.lower_th and self.baseline_vals[
                                self.lmarker - 1] > self.lower_th and (
                                    abs(self.current_baseline_val -
                                        self.baseline_vals[self.lmarker]) <=
                                    self.step_limit) and (abs(
                                        self.baseline_vals[self.lmarker] -
                                        self.baseline_vals[self.lmarker - 1])
                                                          <= self.step_limit):
                        self.lmarker = self.lmarker + 1
                        self.baseline_vals[
                            self.lmarker] = self.current_baseline_val
                        self.state_next = 1
                    else:
                        self.baseline_vals[self.lmarker -
                                           1] = self.baseline_vals[
                                               self.lmarker]
                        self.baseline_vals[
                            self.lmarker] = self.current_baseline_val

                        self.state_next = 0

            #----------------------
            # state 1: observation
            #----------------------
            if self.state_no == 1:

                # Filter Activation
                #- - - - - - - - - - -
                if self.current_baseline_val <= self.lower_th:
                    on = 1
                    self.jump_marker = self.lmarker + 1  # marks values to be replaced

                    # Identification of last self.valid_value before the blink
                    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                    while on == 1:
                        if self.baseline_vals[
                                self.
                                lmarker] >= self.lower_th and self.baseline_vals[
                                    self.lmarker -
                                    1] >= self.lower_th and self.baseline_vals[
                                        self.lmarker -
                                        2] >= self.lower_th and abs(
                                            self.baseline_vals[self.lmarker] -
                                            self.baseline_vals[self.lmarker -
                                                               1]
                                        ) <= self.step_limit and abs(
                                            self.baseline_vals[self.lmarker -
                                                               1] -
                                            self.baseline_vals[self.lmarker -
                                                               2]
                                        ) <= self.step_limit:
                            self.valid_value = self.baseline_vals[self.lmarker]
                            self.lmarker = self.lmarker + 1
                            for i in range(self.lmarker, self.jump_marker, 1):
                                self.baseline_vals[i] = self.valid_value

                            self.baseline_vals[
                                self.jump_marker] = self.valid_value

                            self.lmarker = self.jump_marker
                            self.puffer_size = self.jump_marker + self.delay_size

                            on = 0
                            self.state_next = 2

                        else:
                            self.lmarker = self.lmarker - 1

                else:
                    self.lmarker = self.lmarker + 1
                    self.baseline_vals[
                        self.lmarker] = self.current_baseline_val

                    self.state_next = 1

            #-------------------------------------------------------------
            # state 2: identification of next self.valid_value after the blink
            #-------------------------------------------------------------

            if self.state_no == 2:
                # collecting values following the blink
                #- - - - - - - - - - - - - - - - - - - - - -
                if self.lmarker < self.puffer_size:
                    self.lmarker = self.lmarker + 1
                    self.baseline_vals[
                        self.lmarker] = self.current_baseline_val

                    self.state_next = 2

                else:
                    # identification of next self.valid_value after the blink
                    #- - - - - - - - - - - - - - - - - - - - - - - - - - - -
                    if self.current_baseline_val > self.lower_th and abs(
                            self.current_baseline_val - self.baseline_vals[
                                self.lmarker]) <= self.step_limit and abs(
                                    self.baseline_vals[self.lmarker] -
                                    self.baseline_vals[self.lmarker -
                                                       1]) <= self.step_limit:
                        self.lmarker = self.lmarker + 1
                        self.baseline_vals[
                            self.lmarker] = self.current_baseline_val

                        self.state_next = 1

                    else:
                        self.lmarker = self.lmarker + 1
                        self.baseline_vals[
                            self.lmarker] = self.current_baseline_val
                        self.baseline_vals[self.lmarker - 2] = self.valid_value

                        self.state_next = 2

            self.state_no = self.state_next

            # Draw the crosses
            baseline_cross_1 = visual.Line(self.win,
                                           start=(0, -20),
                                           end=(0, 20),
                                           lineColor=(-1, -1, -1))
            baseline_cross_2 = visual.Line(self.win,
                                           start=(-20, 0),
                                           end=(20, 0),
                                           lineColor=(-1, -1, -1))
            baseline_cross_1.draw()
            baseline_cross_2.draw()

            # check if all components have finished
            if not continueRoutine: break

            # check for quit (the Esc key)
            if endExpNow or event.getKeys(keyList=["escape"]): core.quit()

            # refresh the screen
            if continueRoutine: self.win.flip()
                             image='Correct.png',
                             mask=None,
                             ori=0,
                             pos=[0, 0],
                             size=[0.18, 0.18 * 1.778],
                             color=[1, 1, 1],
                             colorSpace=u'rgb',
                             opacity=1,
                             texRes=128,
                             interpolate=False,
                             depth=-2.0)

line = visual.Line(win,
                   start=(-1.0, line_break),
                   end=(1.0, line_break),
                   ori=0,
                   name='line',
                   opacity=1,
                   depth=0.0)

d_label = visual.TextStim(win=win,
                          ori=0,
                          name='D',
                          text="Left",
                          font='Arial',
                          pos=[-0.2, -0.65],
                          height=(0.12),
                          wrapWidth=None,
                          color='white',
                          opacity=1,
                          depth=0.0)
    def __init__(self, win, nposs=4):
        start, end = -.5, .5
        ypad = .05
        self.nposs = nposs
        line = visual.Line(win,
                           start=(start, 0),
                           end=(end, 0),
                           units='norm',
                           lineColor=stimcolor,
                           lineWidth=5)
        ticks = start + np.arange(0, nposs) * (end - start) / float(nposs - 1)
        poss = [
            visual.Line(win,
                        start=(tick, -ypad),
                        end=(tick, ypad),
                        units='norm',
                        lineColor=stimcolor,
                        lineWidth=3) for tick in ticks
        ]
        lab = [
            visual.TextStim(win,
                            pos=(ticks[0], -.1),
                            units='norm',
                            text='1',
                            height=.1,
                            color=stimcolor),
            visual.TextStim(win,
                            pos=(ticks[1], -.1),
                            units='norm',
                            text='2',
                            height=.1,
                            color=stimcolor),
            visual.TextStim(win,
                            pos=(ticks[2], -.1),
                            units='norm',
                            text='3',
                            height=.1,
                            color=stimcolor),
            visual.TextStim(win,
                            pos=(ticks[-1], -.1),
                            units='norm',
                            text='4',
                            height=.1,
                            color=stimcolor),
            visual.TextStim(win,
                            pos=(ticks[0] + .1, -.28),
                            units='norm',
                            text='Minimal task-unrelated thought',
                            wrapWidth=0.2,
                            height=.05,
                            color=stimcolor),
            visual.TextStim(win,
                            pos=(ticks[-1] + .1, -.28),
                            units='norm',
                            text='Maximal task-unrelated thought',
                            wrapWidth=0.2,
                            height=.05,
                            color=stimcolor),
            visual.TextStim(
                win,
                pos=(0, .5),
                units='norm',
                text=
                ' To what extent have you experienced \n task-unrelated thoughts \n prior to the thought probe?',
                alignHoriz='center',
                wrapWidth=1.5,
                height=.1,
                color=stimcolor)
        ]

        self.arrow_v = 0.4 * np.array([[0, 0], [.2, .2], [.1, .2], [.1, .5],
                                       [-.1, .5], [-.1, .2], [-.2, .2], [0, 0]
                                       ])
        self.arrow_v[:, 1] += ypad + .01
        self.ticks = ticks
        self.arrow = visual.ShapeStim(win,
                                      vertices=self.arrow_v,
                                      fillColor=stimcolor,
                                      units='norm')

        self.init_random()
        self.elements = [line] + poss + lab
示例#16
0
    def __init__(self,
                 win,
                 scaleColor,
                 activeColor,
                 startLevel,
                 width,
                 height,
                 pos,
                 opacity=1):
        self.win = win
        self.scaleColor = scaleColor
        self.activeColor = activeColor
        self.activeLevel = startLevel  # default active level is the starting level
        self.width = width
        self.height = height
        self.posX = pos[0]
        self.posY = pos[1]
        self.opacity = opacity

        # Create scale bar
        barWidth = self.width * 0.8
        barLeftEdge = self.posX - barWidth / 2.0
        barRightEdge = self.posX + barWidth / 2.0
        self.bar = visual.Line(self.win,
                               lineColor=self.scaleColor,
                               start=(barLeftEdge, self.posY),
                               end=(barRightEdge, self.posY),
                               opacity=self.opacity)

        # Create scale arrows
        arrowWidth = self.width * 0.1
        leftArrowPosX = barLeftEdge - arrowWidth / 2.0
        rightArrowPosX = barRightEdge + arrowWidth / 2.0
        # Note: Polygon is supposed to create regular polygons, but there is a bug in Psychopy... They didn't account for norm units. So the actual shape will turn out unexpected.
        self.leftArrow = visual.Polygon(win,
                                        lineColor=self.scaleColor,
                                        fillColor=self.scaleColor,
                                        edges=3,
                                        radius=arrowWidth / 2.0,
                                        pos=(leftArrowPosX, self.posY),
                                        ori=-90,
                                        opacity=self.opacity)
        self.rightArrow = visual.Polygon(win,
                                         lineColor=self.scaleColor,
                                         fillColor=self.scaleColor,
                                         edges=3,
                                         radius=arrowWidth / 2.0,
                                         pos=(rightArrowPosX, self.posY),
                                         ori=90,
                                         opacity=self.opacity)

        # Make the scale arrows function as buttons
        mouse = event.Mouse()
        self.leftArrowButton = Button(self.leftArrow, mouse)
        self.rightArrowButton = Button(self.rightArrow, mouse)

        # Calculate the space between each tick
        tickIntervalWidth = barWidth / 6.0  # 7 ticks => 6 intervals

        # Calculate the end points of the tick bars
        tickYStart = self.posY - self.height / 2.0
        tickYEnd = self.posY + self.height / 2.0
        tick1PosX = barLeftEdge
        tick2PosX = self.posX - (2 * tickIntervalWidth)
        tick3PosX = self.posX - (1 * tickIntervalWidth)
        tick4PosX = self.posX
        tick5PosX = self.posX + (1 * tickIntervalWidth)
        tick6PosX = self.posX + (2 * tickIntervalWidth)
        tick7PosX = barRightEdge

        # Create tick bars
        self.tick1 = visual.Line(self.win,
                                 lineColor=self.scaleColor,
                                 start=(tick1PosX, tickYStart),
                                 end=(tick1PosX, tickYEnd),
                                 opacity=self.opacity)
        self.tick2 = visual.Line(self.win,
                                 lineColor=self.scaleColor,
                                 start=(tick2PosX, tickYStart),
                                 end=(tick2PosX, tickYEnd),
                                 opacity=self.opacity)
        self.tick3 = visual.Line(self.win,
                                 lineColor=self.scaleColor,
                                 start=(tick3PosX, tickYStart),
                                 end=(tick3PosX, tickYEnd),
                                 opacity=self.opacity)
        self.tick4 = visual.Line(self.win,
                                 lineColor=self.scaleColor,
                                 start=(tick4PosX, tickYStart),
                                 end=(tick4PosX, tickYEnd),
                                 opacity=self.opacity)
        self.tick5 = visual.Line(self.win,
                                 lineColor=self.scaleColor,
                                 start=(tick5PosX, tickYStart),
                                 end=(tick5PosX, tickYEnd),
                                 opacity=self.opacity)
        self.tick6 = visual.Line(self.win,
                                 lineColor=self.scaleColor,
                                 start=(tick6PosX, tickYStart),
                                 end=(tick6PosX, tickYEnd),
                                 opacity=self.opacity)
        self.tick7 = visual.Line(self.win,
                                 lineColor=self.scaleColor,
                                 start=(tick7PosX, tickYStart),
                                 end=(tick7PosX, tickYEnd),
                                 opacity=self.opacity)

        tickLabelPosY = self.posY - self.height  # Prevents scale labels from overlapping the scale

        # Create tick labels
        self.tick1Label = visual.TextStim(self.win,
                                          text='1',
                                          height=self.height,
                                          color=self.scaleColor,
                                          pos=(tick1PosX, tickLabelPosY),
                                          opacity=self.opacity)
        self.tick2Label = visual.TextStim(self.win,
                                          text='2',
                                          height=self.height,
                                          color=self.scaleColor,
                                          pos=(tick2PosX, tickLabelPosY),
                                          opacity=self.opacity)
        self.tick3Label = visual.TextStim(self.win,
                                          text='3',
                                          height=self.height,
                                          color=self.scaleColor,
                                          pos=(tick3PosX, tickLabelPosY),
                                          opacity=self.opacity)
        self.tick4Label = visual.TextStim(self.win,
                                          text='4',
                                          height=self.height,
                                          color=self.scaleColor,
                                          pos=(tick4PosX, tickLabelPosY),
                                          opacity=self.opacity)
        self.tick5Label = visual.TextStim(self.win,
                                          text='5',
                                          height=self.height,
                                          color=self.scaleColor,
                                          pos=(tick5PosX, tickLabelPosY),
                                          opacity=self.opacity)
        self.tick6Label = visual.TextStim(self.win,
                                          text='6',
                                          height=self.height,
                                          color=self.scaleColor,
                                          pos=(tick6PosX, tickLabelPosY),
                                          opacity=self.opacity)
        self.tick7Label = visual.TextStim(self.win,
                                          text='7',
                                          height=self.height,
                                          color=self.scaleColor,
                                          pos=(tick7PosX, tickLabelPosY),
                                          opacity=self.opacity)

        # Create tick dictionary
        self.tickDict = {
            1: {
                'tick': self.tick1,
                'label': self.tick1Label
            },
            2: {
                'tick': self.tick2,
                'label': self.tick2Label
            },
            3: {
                'tick': self.tick3,
                'label': self.tick3Label
            },
            4: {
                'tick': self.tick4,
                'label': self.tick4Label
            },
            5: {
                'tick': self.tick5,
                'label': self.tick5Label
            },
            6: {
                'tick': self.tick6,
                'label': self.tick6Label
            },
            7: {
                'tick': self.tick7,
                'label': self.tick7Label
            }
        }

        # Set active colors
        self.tickDict[self.activeLevel]['tick'].lineColor = self.activeColor
        self.tickDict[self.activeLevel]['label'].color = self.activeColor

        # Create clickable (invisible) boxes around the ticks & tick labels so you can skip using the arrow buttons and click directly on the ticks or labels on the scale
        tickBoxPosY = self.posY - self.height / 2.0
        tickBoxWidth = tickIntervalWidth * 0.9
        tickBoxHeight = self.height * 2.5
        self.tick1box = visual.Rect(self.win,
                                    lineColor=self.scaleColor,
                                    width=tickBoxWidth / 2.0,
                                    height=tickBoxHeight,
                                    pos=(tick1PosX + tickBoxWidth / 4.0,
                                         tickBoxPosY),
                                    opacity=self.opacity)
        self.tick2box = visual.Rect(self.win,
                                    lineColor=self.scaleColor,
                                    width=tickBoxWidth,
                                    height=tickBoxHeight,
                                    pos=(tick2PosX, tickBoxPosY),
                                    opacity=self.opacity)
        self.tick3box = visual.Rect(self.win,
                                    lineColor=self.scaleColor,
                                    width=tickBoxWidth,
                                    height=tickBoxHeight,
                                    pos=(tick3PosX, tickBoxPosY),
                                    opacity=self.opacity)
        self.tick4box = visual.Rect(self.win,
                                    lineColor=self.scaleColor,
                                    width=tickBoxWidth,
                                    height=tickBoxHeight,
                                    pos=(tick4PosX, tickBoxPosY),
                                    opacity=self.opacity)
        self.tick5box = visual.Rect(self.win,
                                    lineColor=self.scaleColor,
                                    width=tickBoxWidth,
                                    height=tickBoxHeight,
                                    pos=(tick5PosX, tickBoxPosY),
                                    opacity=self.opacity)
        self.tick6box = visual.Rect(self.win,
                                    lineColor=self.scaleColor,
                                    width=tickBoxWidth,
                                    height=tickBoxHeight,
                                    pos=(tick6PosX, tickBoxPosY),
                                    opacity=self.opacity)
        self.tick7box = visual.Rect(self.win,
                                    lineColor=self.scaleColor,
                                    width=tickBoxWidth / 2.0,
                                    height=tickBoxHeight,
                                    pos=(tick7PosX - tickBoxWidth / 4.0,
                                         tickBoxPosY),
                                    opacity=self.opacity)
        self.tick1button = Button(self.tick1box, mouse)
        self.tick2button = Button(self.tick2box, mouse)
        self.tick3button = Button(self.tick3box, mouse)
        self.tick4button = Button(self.tick4box, mouse)
        self.tick5button = Button(self.tick5box, mouse)
        self.tick6button = Button(self.tick6box, mouse)
        self.tick7button = Button(self.tick7box, mouse)
示例#17
0
def inflectionSnakes(win,
                     circle,
                     color=True,
                     size=0.1,
                     length=15,
                     curr_radius=4):
    ori = 90
    min_ecc, max_ecc = get_eccentricity_bounds(curr_radius=curr_radius,
                                               gilb_radius=43.8 / 2,
                                               gilb_min_ecc=2.4,
                                               gilb_max_ecc=8.4)
    print min_ecc, max_ecc
    posX = sample(np.arange(-max_ecc, max_ecc, 0.25), 1)[0]
    length /= 2
    positionsX = np.arange(posX - 0.3 * length, posX + 0.3 * length, 0.3)
    posY = 0
    #posY = sample(np.arange(-curr_radius, curr_radius,0.25),1)[0]
    infl = [positionsX[int(i)] for i in np.linspace(0, len(positionsX) - 1, 5)]
    infl = infl[1:-1]
    print infl
    prevOri = ori
    prevPos = (positionsX[0], posY)
    allLines = []
    sign = -1
    for posX in positionsX:
        if posX in infl:
            sign *= -1
            ori += sign * 45
        m, c = getIntercept(prevPos[0], prevPos[1], ori)
        posY = m * posX + c
        if circle.contains((posX, posY)):
            line = draw_line(win,
                             pos=(posX, posY),
                             contour=False,
                             color=True,
                             size=0.1,
                             ori=ori - 45,
                             center=False)
            print posX, posY
            prevPos = (posX, posY)
            allLines.append(line)

    ori_orth = np.random.uniform(-180, 180)
    for posX in np.arange(-curr_radius, curr_radius, 0.4):
        for posY in np.arange(-curr_radius, curr_radius, 0.4):
            if circle.contains(posX, posY):
                alpha, beta = np.abs(ori_orth + 45), np.abs(
                    ori_orth + 90
                )  #Driving neighbouring 'distractor' lines to be non-collinear
                minTheta, maxTheta = min(alpha, beta), max(
                    alpha, beta
                )  #Range of orientation of new 'distractor' line segment
                ori_orth = np.random.uniform(minTheta, maxTheta)
                ln = visual.Line(win=win,
                                 pos=(posX, posY),
                                 size=size,
                                 ori=np.random.uniform(ori_orth),
                                 contrast=1.,
                                 lineColor=(1, 1, 1),
                                 interpolate=True)
                overlaps = [
                    np.sum(np.abs(ln.pos - ln2.pos)) < 0.3 for ln2 in allLines
                ]
                if not True in overlaps:
                    ln.draw()
示例#18
0
                     modifiers=['ctrl'],
                     func=core.quit,
                     name='shutdown')

# Add a Display and get its framerate (specifically, how many ms 1 frame takes)
win = visual.Window(size=[1920, 1080],
                    units='norm',
                    color=[1, 1, 1],
                    fullscr=True)
framerate = win.getMsPerFrame()[2]

# Some visuals
line_hori = visual.Line(win,
                        units='norm',
                        start=(-0.42, 0),
                        end=(0.42, 0),
                        lineColor='black',
                        lineWidth=2.5,
                        name='line_hori')
line_vert = visual.Line(win,
                        units='norm',
                        start=(0, -0.75),
                        end=(0, 0.75),
                        lineColor='black',
                        lineWidth=2.5,
                        name='line_vert')
border_up = visual.Line(win,
                        units='norm',
                        start=(-0.42, 0.75),
                        end=(0.42, 0.75),
                        lineColor='black',
示例#19
0
                       color=[-1, -1, -1],
                       fullscr=False)
window.mouseVisible = False

# import stimuli
turtle_black = visual.ImageStim(window, 'turtle_black.png', autoLog=False)
turtle_green = visual.ImageStim(window, 'turtle_green.png', autoLog=False)
tortoise_black = visual.ImageStim(window, 'tortoise_black.png', autoLog=False)
#tortoise_green = visual.ImageStim(window, 'tortoise_green.png', autoLog=False)

# import backgrounds
water_top = visual.ImageStim(window, 'water_top_sand_bot.png', autoLog=False)
sand_top = visual.ImageStim(window, 'sand_top_water_bot.png', autoLog=False)

# fixation crosses
fix_hori = visual.Line(window, (-15, 0), (15, 0), lineColor='white')
fix_vert = visual.Line(window, (0, -15), (0, 15), lineColor='white')

## Timing definitions

# this is for speed run (comment out the block below for this)
frame_rate = window.getActualFrameRate()
resp_time = 0.001
break_time = 1
fix_min = 0.001
fix_max = 0.002
iti_min = 0.001
iti_max = 0.002
timer = core.Clock()
check_timer = core.Clock()
check_interval = 0.6 * (1 / frame_rate)
示例#20
0
    def __init__(self,
                 win=None,
                 params=None,
                 exp_info=None,
                 txt_ins=None,
                 stimulus_list=None):
        self.win = win
        self.params = params
        self.exp_info = exp_info
        self.txt_ins = txt_ins
        self.stimulus_list = stimulus_list

        if self.params["EEG"]:
            self.pport = PortParallel()
        else:
            self.pport = False

        # Get a list of stimuli for the practice trial
        # The list contain all the stimuli in the practice folder as win.image
        self.practice_stim_list = get_practice_stim(params["Practice_path"],
                                                    self.win)

        self.pic_time = float(params[u"Cat_stim_time"])
        self.primer_time = float(params[u"Primer_time"])
        self.maxanswer_time = float(params[u"Maxanswer_time"])
        self.feedback_time = float(params["Feedback_time"])
        self.stim_end = self.primer_time + self.pic_time
        self.trial_end = self.primer_time + self.maxanswer_time

        # Create the mouse, primer and categorisation choices txt
        self.mouse = event.Mouse(visible=False, newPos=None, win=None)
        self.primer = visual.Circle(win=win,
                                    radius=45,
                                    units="pix",
                                    fillColor=[-1, -1, -1],
                                    lineColor=[-1, -1, -1])
        self.horizontal_line = visual.Line(win=win,
                                           units="pix",
                                           lineColor=[+1, +1, +1],
                                           lineWidth=10,
                                           start=(-50, 0),
                                           end=(+50, 0))
        self.vertical_line = visual.Line(win=win,
                                         units="pix",
                                         lineColor=[+1, +1, +1],
                                         lineWidth=10,
                                         start=(0, -50),
                                         end=(0, +50))
        self.center = visual.Circle(win=win,
                                    radius=5,
                                    units="pix",
                                    fillColor=[-1, -1, -1],
                                    lineColor=[-1, -1, -1])
        self.txt_categorisation_choices = visual.TextStim(
            win=win,
            text=self.txt_ins["Cat_answer_option"],
            pos=(0.0, 0.0),
            color="Black")

        # Create a trial_list
        # Method must be adapted to the way stimuli are stored in the computer and rules wanted
        if exp_info["Exp"] == "Fish":
            if self.params["Orientation"] == "True":
                self.cat_trials_list = get_list_cat_trial_fish_with_orientation(
                    stimulus_list, self.win, params)
        elif exp_info["Exp"] == "Textures":
            self.cat_trials_list = get_list_cat_trial_texture(
                stimulus_list, self.win, params)

        # Create data handler
        file_name = exp_info['Exp'] + "_Version" + exp_info[
            'Version'] + "_" + exp_info["Name"] + "_Cat"
        self.cat_data = data.ExperimentHandler(
            name='Cat',
            version=exp_info['Version'],
            extraInfo=exp_info,
            runtimeInfo=None,
            savePickle=False,
            saveWideText=True,
            dataFileName=params["Cat_saving_path"] + file_name,
            autoLog=True)
j=(-8)
for i in range(zdots):
    
    angle=0
    
    line_cart = pol_to_cart(j, angle)
    dotx = line_cart[0]
    doty = line_cart[1]
    zdot_list.append([dotx, doty])
    
    j += .2
    
multi_line_color1 = "red"
multi_line_color2 = "red"
  
linea = visual.Line(win, start=(zdot_list[0]), end=(4,0), lineColor=multi_line_color1)
lineb = visual.Line(win, start=(zdot_list[1]), end=(4,0), lineColor=multi_line_color2)
linec = visual.Line(win, start=(zdot_list[2]), end=(4,0), lineColor=multi_line_color1)
lined = visual.Line(win, start=(zdot_list[3]), end=(4,0), lineColor=multi_line_color2)
linee = visual.Line(win, start=(zdot_list[4]), end=(4,0), lineColor=multi_line_color1)
linef = visual.Line(win, start=(zdot_list[5]), end=(4,0), lineColor=multi_line_color2)
lineg = visual.Line(win, start=(zdot_list[6]), end=(4,0), lineColor=multi_line_color1)
lineh = visual.Line(win, start=(zdot_list[7]), end=(4,0), lineColor=multi_line_color2)
linei = visual.Line(win, start=(zdot_list[8]), end=(4,0), lineColor=multi_line_color1)
linej = visual.Line(win, start=(zdot_list[9]), end=(4,0), lineColor=multi_line_color2)
linek = visual.Line(win, start=(zdot_list[10]), end=(4,0), lineColor=multi_line_color1)
linel = visual.Line(win, start=(zdot_list[11]), end=(4,0), lineColor=multi_line_color2)
linem = visual.Line(win, start=(zdot_list[12]), end=(4,0), lineColor=multi_line_color1)
linen = visual.Line(win, start=(zdot_list[13]), end=(4,0), lineColor=multi_line_color2)
lineo = visual.Line(win, start=(zdot_list[14]), end=(4,0), lineColor=multi_line_color1)
linep = visual.Line(win, start=(zdot_list[15]), end=(4,0), lineColor=multi_line_color2)
示例#22
0
                lmarker = lmarker + 1
                bsize_liste[lmarker] = bsize
                
                state_next = 1
     
             else:
                 lmarker = lmarker + 1
                 bsize_liste[lmarker] = bsize
                 bsize_liste[lmarker-2] = valid_value
        
                 state_next = 2
     
     state_no = state_next
     
     #baseline_liste.append(sampleData.leftEye.diam/32)
     line1 = visual.Line(win, start=(0, -20), end=(0, 20), lineColor=(1, 1, 1))
     line2 = visual.Line(win, start=(-20, 0), end=(20, 0), lineColor=(1, 1, 1))
     line1.draw()
     line2.draw()
     
     # generic
     if not routine_helper.check_comps_status(): break
     if event.getKeys(keyList=conf_escape_keys): core.quit()
     if routine_helper.get_status(): win.flip()
 routine_helper.end_components()
 
 ######################################################################################################
 
 #####################  Computing baseline stats
 
 bsize_liste = filter(None, bsize_liste)
示例#23
0
frame_size = 15
line_length = 6

# create a rod-and-frame stimulus
frame = visual.Rect(win,
                    width=frame_size,
                    height=frame_size,
                    lineColor=frameColor,
                    lineColorSpace='rgb',
                    lineWidth=1,
                    units='cm')
rod = visual.Line(win,
                  start=(0, -line_length),
                  end=(0, line_length),
                  lineColor=rodColor,
                  lineColorSpace='rgb',
                  lineWidth=1,
                  units='cm')

vert_center = -2
horz_center = +15.0

frame.pos = (horz_center, vert_center)
rod.pos = (horz_center, vert_center)

# stimulus orientations
# frameOri = range(-45,45,5)
frameOri = numpy.linspace(-45, 45, 11)
rodOri = numpy.linspace(-10, 10, 30)
示例#24
0
    text="YXIXM",
    pos=(0, -2),  # and can have line breaks
    color=[-1.0, -1, 1],
    units='deg',
    height=3.0,
    alignHoriz='center',
    alignVert='center',
    font=sans)

fixationPoint = visual.PatchStim(win,
                                 colorSpace='rgb',
                                 color=(1, 1, 1),
                                 size=5,
                                 units='pix')
horizontalMeridian = visual.Line(win,
                                 start=(-5, 0),
                                 end=(5, 0),
                                 fillColor=(0, 1, 1))
vertLine = visual.Line(win, start=(0, -2), end=(0, 2), fillColor=(1, 0, -.3))
trialClock = core.Clock()
t = lastFPSupdate = 0

# Continues the loop until any key is pressed
stop = False
while not stop:
    upper.draw()
    lower.draw()
    fixationPoint.draw()
    horizontalMeridian.draw()
    vertLine.draw()
    win.flip()
    keysPressed = event.getKeys()  #print 'keysPressed = ', keysPressed
                           height=0.05,
                           wrapWidth=None,
                           ori=0,
                           color='white',
                           colorSpace='rgb',
                           opacity=1,
                           languageStyle='LTR',
                           depth=-2.0)
gridColor = [1, 1, 1]
gridLine1 = visual.Line(win=win,
                        name='gridLine1',
                        start=(-(0.6, 0.6)[0] / 2.0, 0),
                        end=(+(0.6, 0.6)[0] / 2.0, 0),
                        ori=0,
                        pos=(0, 0.3),
                        lineWidth=1.5,
                        lineColor=1.0,
                        lineColorSpace='rgb',
                        fillColor=1.0,
                        fillColorSpace='rgb',
                        opacity=1,
                        depth=-4.0,
                        interpolate=True)
gridLine2 = visual.Line(win=win,
                        name='gridLine2',
                        start=(-(0.6, 0.6)[0] / 2.0, 0),
                        end=(+(0.6, 0.6)[0] / 2.0, 0),
                        ori=0,
                        pos=(0, 0.096),
                        lineWidth=1.5,
                        lineColor=1.0,
                        lineColorSpace='rgb',
示例#26
0
    def __init__ (self):
        positionX = np.linspace(-23.5, 23.5, num=10, endpoint=True, retstep=False)
        positionY = np.linspace(-14.1, 14.1, num=6, endpoint=True, retstep=False)
        xys = np.transpose([np.tile(positionX, len(positionY)), np.repeat(positionY, len(positionX))])
        self.positions = xys
        self.counter = 0
        self.waitForKeys = True
        mon = monitors.Monitor('myMonitor1')
        self.window = visual.Window(size=mon.getSizePix(), color=(1,1,1), colorSpace='rgb', fullscr=True, monitor=mon, units='cm')
        self.window.mouseVisible = False
        self.resultData = np.zeros(shape = (360,7),dtype=np.float64)

        
        fixationX = visual.Line(win=self.window, lineColor=(-1,-1,-1), lineColorSpace='rgb', start=(-0.5,0), end=(0.5,0),lineWidth = 2.5, interpolate=False)
        fixationY = visual.Line(win=self.window, lineColor=(-1,-1,-1), lineColorSpace='rgb', start=(0,-0.5), end=(0,0.5),lineWidth = 2.5, interpolate=False)
        self.fixation = [fixationX, fixationY]
        
        
        self.text1 = visual.TextStim(win=self.window, text='Ist', color=(-1,-1,-1), colorSpace='rgb', height=2, bold=True, wrapWidth=50, pos=(0.0, 2))
        self.text3 = visual.TextStim(win=self.window, text='im folgenden Bild enthalten?', color=(-1,-1,-1), colorSpace='rgb', height=2, bold=True, wrapWidth=50, pos=(0.0, -2.0))
        
        
        imgStart1 = visual.SimpleImageStim(win=self.window, image="..\\img\\auftrag1.png")
        imgStart2 = visual.SimpleImageStim(win=self.window, image="..\\img\\aufgabe2.png")
        imgPractice1 = visual.SimpleImageStim(win=self.window, image="..\\img\\training1.png")
        imgExperiment = visual.SimpleImageStim(win=self.window, image="..\\img\\Versuch.jpg")
        thankyou = visual.SimpleImageStim(win=self.window, image="..\\img\\danke.jpg")
        
        # block slides
        block1 = visual.SimpleImageStim(win=self.window, image="..\\img\\Block_1.jpg")
        block2 = visual.SimpleImageStim(win=self.window, image="..\\img\\Block_2.jpg")
        block3 = visual.SimpleImageStim(win=self.window, image="..\\img\\Block_3.jpg")
        block4 = visual.SimpleImageStim(win=self.window, image="..\\img\\Block_4.jpg")
        block5 = visual.SimpleImageStim(win=self.window, image="..\\img\\Block_5.jpg")
        block6 = visual.SimpleImageStim(win=self.window, image="..\\img\\Block_6.jpg")
        
        'creating the stimulus'
        self.redCircle = visual.ImageStim(win=self.window, image="..\\img\\shapes_13.jpg", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
        self.greenCircle = visual.ImageStim(win=self.window, image="..\\img\\shapes_11.jpg", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
        self.redTriangle = visual.ImageStim(win=self.window, image="..\\img\\shapes_15.jpg", units = "cm", pos=(0,0), size = 3.4, ori = -90, contrast=1.0)
        self.greenTriangle = visual.ImageStim(win=self.window, image="..\\img\\shapes_17.png", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
        self.redSquare = visual.ImageStim(win=self.window, image="..\\img\\shapes_03.jpg", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
        self.greenSquare = visual.ImageStim(win=self.window, image="..\\img\\shapes_05.jpg", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
        self.greenRhombus = visual.ImageStim(win=self.window, image="..\\img\\shapes_07.jpg", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
        self.greenSquareOpen = visual.ImageStim(win=self.window, image="..\\img\\shapes_09.jpg", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
        self.star4 = visual.ImageStim(win=self.window, image="..\\img\\shapes_25.jpg", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
        self.star5 = visual.ImageStim(win=self.window, image="..\\img\\shapes_20.jpg", units = "cm", pos=(0,0), size = 3.4, contrast=1.0)
                
        self.instructions = {'start1': imgStart1,
                             'start2': imgStart2,
                             'practice1': imgPractice1,
                             'experiment': imgExperiment,
                             'danke': thankyou,
                             'block1': block1,
                             'block2': block2,
                             'block3': block3,
                             'block4': block4,
                             'block5': block5,
                             'block6': block6
                             }
        '''generating a dict with keys 1 to 60 of all the necessary images'''
        self.images = {} 
        for x in range(1,17):
            self.images[x] = self.redCircle
    
        x += 1
        self.images[x] = self.greenCircle
    
        for x in range (18,29):
            self.images[x] = self.redSquare
    
        for x in range (29,40):
            self.images[x] = self.greenSquare 
    
        x += 1
        self.images[x] = self.greenSquareOpen
    
        x += 1
        self.images[x] = self.greenRhombus 
    
        x += 1
        self.images[x] = self.redTriangle
    
        for x in range (43,59):
            self.images[x] = self.star4
    
        x += 1
        self.images[x] = self.star5
    
        x += 1
        self.images[x] = self.greenTriangle
        
        '''creating the constellation using the code for six time: constellation = random.sample(xrange(1, 61), 60)'''
        constellation1 = [7, 43, 46, 16, 27, 5, 31, 36, 44, 52, 22, 25, 59, 24, 17, 48, 8, 32, 40, 20, 29, 21, 57, 15, 26, 13, 10, 35, 53, 2, 51, 30, 33, 38, 47, 34, 3, 55, 4, 6, 50, 23, 28, 12, 54, 1, 9, 60, 18, 37, 42, 39, 11, 19, 14, 41, 45, 58, 56, 49]
        constellation2 = [29, 9, 1, 4, 45, 3, 35, 16, 13, 22, 57, 25, 24, 37, 19, 26, 60, 32, 59, 36, 2, 18, 46, 58, 14, 48, 49, 44, 12, 39, 38, 40, 56, 8, 51, 28, 47, 43, 50, 34, 41, 21, 55, 31, 33, 17, 53, 42, 30, 15, 23, 11, 7, 52, 20, 54, 10, 6, 27, 5]
        constellation3 = [57, 19, 53, 47, 13, 55, 14, 52, 29, 39, 9, 1, 25, 38, 18, 56, 49, 31, 28, 15, 3, 5, 4, 54, 58, 41, 27, 2, 44, 59, 35, 60, 24, 16, 40, 23, 43, 34, 32, 20, 17, 37, 6, 26, 33, 45, 51, 11, 50, 46, 30, 8, 36, 22, 48, 12, 21, 7, 42, 10]
        constellation4 = [13, 27, 32, 49, 2, 57, 35, 60, 11, 25, 19, 5, 59, 24, 34, 6, 54, 21, 3, 51, 52, 23, 18, 31, 42, 45, 9, 10, 15, 38, 16, 53, 47, 8, 22, 37, 4, 40, 44, 17, 58, 7, 29, 46, 12, 20, 39, 26, 50, 56, 14, 1, 43, 33, 36, 30, 41, 55, 48, 28]
        constellation5 = [51, 27, 15, 48, 59, 20, 9, 19, 53, 13, 43, 39, 37, 58, 38, 45, 47, 40, 31, 17, 18, 26, 30, 8, 32, 4, 55, 54, 56, 25, 14, 50, 1, 12, 28, 16, 10, 44, 52, 24, 3, 34, 6, 5, 42, 35, 46, 36, 57, 7, 23, 11, 21, 22, 60, 2, 41, 49, 29, 33]
        constellation6 = [20, 60, 35, 54, 26, 7, 4, 29, 30, 59, 34, 37, 42, 1, 46, 48, 9, 31, 21, 36, 32, 45, 5, 33, 53, 14, 22, 11, 55, 23, 18, 28, 52, 2, 25, 41, 51, 47, 43, 27, 10, 57, 6, 40, 50, 49, 19, 39, 56, 13, 8, 12, 16, 3, 17, 38, 15, 24, 44, 58]
        constellationPrac = [19, 43, 39, 13, 12, 46, 25, 41, 16, 60, 20, 49, 8, 33, 36, 35, 9, 37, 21, 42, 31, 55, 23, 24, 34, 57, 53, 5, 18, 14, 32, 1, 26, 11, 3, 50, 15, 4, 30, 58, 22, 54, 56, 45, 28, 47, 38, 40, 29, 44, 10, 59, 7, 6, 52, 27, 51, 17, 48, 2]
        
        '''a dict to access the constellation block wise'''
        self.constellation = {
                         1 : constellation1,
                         2 : constellation2,
                         3 : constellation3,
                         4 : constellation4,
                         5 : constellation5,
                         6 : constellation6,
                         7 : constellationPrac
                         }        
    width=(1.6, 1.6)[0], height=(1.6, 1.6)[1],
    ori=0, pos=(4.6, 0),
    lineWidth=4, lineColor='black', lineColorSpace='rgb',
    fillColor=[1,1,1], fillColorSpace='rgb',
    opacity=1, depth=-4.0, interpolate=True)
cue = visual.ImageStim(
    win=win, name='cue',units='cm', 
    image='images/arrow-left.png', mask=None,
    ori=1.0, pos=(0, 0), size=(1.5, 1.5),
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-5.0)
TargetX = visual.Line(
    win=win, name='TargetX',units='cm', 
    start=(-(1.2, 3.2)[0]/2.0, 0), end=(+(1.2, 3.2)[0]/2.0, 0),
    ori=1.0, pos=[0,0],
    lineWidth=4, lineColor='black', lineColorSpace='rgb',
    fillColor=[1,1,1], fillColorSpace='rgb',
    opacity=1, depth=-6.0, interpolate=True)
TargetY = visual.Line(
    win=win, name='TargetY',units='cm', 
    start=(-(1.2, 3.2)[0]/2.0, 0), end=(+(1.2, 3.2)[0]/2.0, 0),
    ori=1.0, pos=[0,0],
    lineWidth=4, lineColor='black', lineColorSpace='rgb',
    fillColor=[1,1,1], fillColorSpace='rgb',
    opacity=1, depth=-7.0, interpolate=True)


# Initialize components for Routine "pause"
pauseClock = core.Clock()
示例#28
0
def main(win, globalClock):
    
    all_changes = []
    
    ################################ Stimuli prepation ################################

    # Bar preparation    
    grating_texture = np.tile([[1,-1],[-1,1]], (1,12))#(4,64))
    grating_texture = np.dstack((grating_texture,grating_texture,grating_texture))
    bar_size = (Bar_length[0]*resX,Bar_length[1]*resY)
    grating_1 = visual.GratingStim(win,tex=grating_texture,color=[1.0, 1.0, 1.0],colorSpace='rgb', units="pix",
        size=bar_size,ori=0,autoLog=False,interpolate=False)
    grating_2 = visual.GratingStim(win,tex=~grating_texture+1,color=[1.0, 1.0, 1.0],colorSpace='rgb', units="pix",
        size=bar_size,ori=0,autoLog=False,interpolate=False)
    
    # Vertical shifting
    bar_positions = []
    for i_ori in range(len(Bar_orientations)):
        i_x = np.linspace(Bar_paths[i_ori,0,0],Bar_paths[i_ori,1,0],Bar_positions_number).reshape((-1,1))
        i_y = np.linspace(Bar_paths[i_ori,0,1],Bar_paths[i_ori,1,1],Bar_positions_number).reshape((-1,1))
        position_i = np.concatenate((i_x,i_y), axis=1)
        position_i = position_i * resY/2
        bar_positions.append(position_i)
    
    # Fixation cross preparation
    fixation = visual.ShapeStim(win,vertices=((0,-1),(0,1),(0,0),(-1,0),(1,0)),lineWidth=4, units="pix",
        size=(20,20),closeShape=False,lineColor='red',autoDraw=True)
    
    # Spyder network
    web_circle = visual.Circle(win=win,radius=1,edges=200,units='norm',pos=[0, 0],lineWidth=1,opacity=1,interpolate=True,
                            lineColor=[1.0, 1.0, 1.0],lineColorSpace='rgb',fillColor=None,fillColorSpace='rgb')
    web_dimension = (screenCorrection(win,Web_size[0]),Web_size[1])
    web_line = visual.Line(win,name='Line',start=(-1.4, 0),end=(1.4, 0),pos=[0, 0],lineWidth=1,
                           lineColor=[1.0, 1.0, 1.0],lineColorSpace='rgb',opacity=1,interpolate=True)

    # DEBUG stimuli
    if DEBUG_MODE:
        fps_text = visual.TextStim(win, units='norm', height=0.05,pos=(-0.98, +0.93), text='starting...',
                                  font=sans, alignHoriz='left', alignVert='bottom', color='yellow')    
        fps_text.autoDraw = True
        
        orientation_details_string = visual.TextStim(win, text = u"Orientation..", units='norm', height=0.05,
                                             pos=(0.95, +0.93), alignHoriz='right', alignVert='bottom', 
                                             font=sans, color='yellow')
        orientation_details_string.autoDraw = True        

    # External Aperture (black ring)
    external_aperture_size = tuple([screenCorrection(win,External_ring_size),External_ring_size])
    external_aperture = visual.Aperture(win, size=external_aperture_size, shape='circle')
    external_aperture.enabled = False

    ################################ Definitions/Functions ################################    
    
    ## handle Rkey presses each frame
    def escapeCondition():              
        for key in event.getKeys():
            if key in ['escape', 'q']:
                return False
        return True
    

    ################################ Animation starts ################################        
    # Display instructions and wait
    message1 = visual.TextStim(win, pos=[0,0.5],text='Hit a key when ready.')
    message1.draw()
    win.flip()
    event.waitKeys()    #pause until there's a keypress

    # Scanner trigger wait
    message3 = visual.TextStim(win,pos=[0,0.25],text=scanner_message,font=serif,alignVert='center',
                               wrapWidth=1.5)
    message3.size = .5
    message3.draw()
    win.flip()

    if BUTTON_BOX:
        button_state = button_thread.button_state
        while 1:
            if(button_state['state'][-1]==0):
                break
    else:
        event.waitKeys()    #pause until there's a keypress
  
    
    # Wait Pre_post_stimuli_fixation_time before stimuli
    # Spyder network
    if Spyder_grid:
        for i_dim in range(Spyder_rings):
            web_circle.setSize(tuple([x*(i_dim+1) * 1./Spyder_rings for x in web_dimension]))
            web_circle.draw()
        for i_dim in range(2):
            web_line.setOri(i_dim * 90)
            web_line.draw()
    win.flip()
    core.wait(Pre_post_stimuli_fixation_time)
    
    
    i_bar_ori = n_frame = last_fps_update = 0

    globalClock.reset()
    inizio = globalClock.getTime()
    timer_global = core.CountdownTimer(Total_time)    
    break_flag = True
    logging.data('First orientation. Number %d/%d at %f (sec.)' % (i_bar_ori+1,len(Bar_orientations),inizio))
    
    
    while (timer_global.getTime() > 0 and break_flag==True):                      #globalClock.getTime() < Total_time:
        n_frame += 1
        t = globalClock.getTime()

        # Spyder network
        if Spyder_grid:
            for i_dim in range(Spyder_rings):
                web_circle.setSize(tuple([x*(i_dim+1) * 1./Spyder_rings for x in web_dimension]))
                web_circle.draw()
            for i_dim in range(2):
                web_line.setOri(i_dim * 90)
                web_line.draw()

        # External ring
        external_aperture.enabled = True
                
        # Bar
        if (t >= ((i_bar_ori+1)*Cycle_duration*Passagges_per_orientation)) & (i_bar_ori < (len(Bar_orientations)-1)):
            i_bar_ori += 1
            logging.data('Change orientation. Number %d/%d at %f (sec.)' % (i_bar_ori+1,len(Bar_orientations),t))
            new_record = globalClock.getTime() - sum(all_changes)
            all_changes.append(new_record)        
        
        if t % Flash_period < Flash_period / 2.0:  # more accurate to count frames
            stim = grating_1
        else:
            stim = grating_2
        bar_pos_indx = int((Bar_positions_number / Cycle_duration) * (t % Cycle_duration) )
        i_orientation_ordered = Bar_orientation_order[i_bar_ori]
        stim.pos = tuple(bar_positions[i_orientation_ordered][bar_pos_indx])
        stim.ori = Bar_orientations[i_orientation_ordered]
        stim.draw()
        
                
        # Fixation
        if Rotating_cross:
            fixation.ori = t * Rotation_cross_rate * 360.0  # set new rotation
        if Color_change_cross:
            if t % Color_change_rate < Color_change_rate / 2.0:  # more accurate to count frames
                fixation.lineColor = 'red'
            else:
                fixation.lineColor = 'green'        

        external_aperture.enabled = False
        if DEBUG_MODE:
            if t - last_fps_update > Fps_update_rate:         # update the fps text every second
                fps_text.text = "%.2f fps" % win.fps()
                last_fps_update += 1
            orientation_details_string.text = 'Ori: %d/%d at %.3f (sec.)' % (i_bar_ori+1,len(Bar_orientations),np.sum(all_changes))

        # Update screen                
        win.flip()
        break_flag = escapeCondition()
        if break_flag == False: break
    

    logging.data('Total time spent: %.6f' % (globalClock.getTime() - inizio))
    logging.data('Every frame duration saved in %s' % (path_out+Frames_durations_name))
    logging.data('All durations: ' + str(all_changes))
    logging.data('Mean: ' + str(sum(all_changes)/(len(all_changes)+EPSILON)))

    if DEBUG_MODE:
        orientation_details_string.text = 'Ended at %.3f (sec.)' % (globalClock.getTime())

    win.flip()
    # Wait Pre_post_stimuli_fixation_time after stimuli
    core.wait(Pre_post_stimuli_fixation_time)
    return
示例#29
0
def zollner_psychopy(window, parameters=None, outline=5, **kwargs):
    """
    Examples
    ---------
    >>> import pyllusion as ill
    >>> from psychopy import visual, event

    >>> parameters = ill.zollner_parameters(illusion_strength=75)

    >>> # Initiate Window
    >>> window = visual.Window(size=[800, 600], fullscr=False,
                               screen=0, winType='pyglet', monitor='testMonitor',
                               allowGUI=False, color="white",
                               blendMode='avg', units='pix')
    
    >>> # Display illusion
    >>> ill.zollner_psychopy(window=window, parameters=parameters)
    
    >>> # Refresh and close window    
    >>> window.flip()
    >>> event.waitKeys()  # Press any key to close
    >>> window.close()

    """
    # Create white canvas and get drawing context
    if parameters is None:
        parameters = zollner_parameters(**kwargs)

    # Loop lines
    for i in range(parameters["Distractors_n"]):
        # Draw distractor lines
        for pos in ["_Top_", "_Bottom_"]:
            coord, _, _ = _coord_line(
                image=window,
                x1=parameters["Distractors" + pos + "x1"][i],
                y1=parameters["Distractors" + pos + "y1"][i],
                x2=parameters["Distractors" + pos + "x2"][i],
                y2=parameters["Distractors" + pos + "y2"][i],
                adjust_height=True,
                method="psychopy")

            # line parameters
            line_distractor = visual.Line(win=window,
                                          units='pix',
                                          lineColor="black",
                                          lineWidth=outline)
            line_distractor.start = [
                coord[0] - window.size[0] / 2, coord[1] - window.size[1] / 2
            ]
            line_distractor.end = [
                coord[2] - window.size[0] / 2, coord[3] - window.size[1] / 2
            ]
            line_distractor.draw()

    for pos in ["Bottom", "Top"]:
        # Draw target lines
        coord, _, _ = _coord_line(image=window,
                                  x1=parameters[pos + "_x1"],
                                  y1=parameters[pos + "_y1"],
                                  x2=parameters[pos + "_x2"],
                                  y2=parameters[pos + "_y2"],
                                  adjust_height=True,
                                  method="psychopy")
        # Line parameters
        line_target = visual.Line(win=window,
                                  units='pix',
                                  lineColor="red",
                                  lineWidth=outline)
        line_target.start = [
            coord[0] - window.size[0] / 2, coord[1] - window.size[1] / 2
        ]
        line_target.end = [
            coord[2] - window.size[0] / 2, coord[3] - window.size[1] / 2
        ]
        line_target.draw()
示例#30
0
    def __init__(self, tracker, win):
        
        '''Initialize a Custom EyeLinkCoreGraphics  
        
        tracker: an eye-tracker instance
        win: the Psychopy display we plan to use for stimulus presentation  '''
        
        pylink.EyeLinkCustomDisplay.__init__(self)
                
        self.pylinkMinorVer = pylink.__version__.split('.')[1] # minor version 1-Mac, 11-Win/Linux
        self.display = win
        self.w, self.h = win.size
        
        # on Macs with HiDPI screens, force the drawing routine to use the size defined
        # in the monitor instance, as win.size will give the wrong size of the screen
        if os.name == 'posix':
            self.w,self.h = win.monitor.getSizePix()
            
        #self.display.autoLog = False
        # check the screen units of Psychopy, forcing the screen to use 'pix'
        self.units = win.units
        if self.units != 'pix': self.display.setUnits('pix')
        
        # Simple warning beeps
        self.__target_beep__ = sound.Sound('A', octave=4, secs=0.1)
        self.__target_beep__done__ = sound.Sound('E', octave=4, secs=0.1)
        self.__target_beep__error__ = sound.Sound('E', octave=6, secs=0.1)
        
        self.imgBuffInitType = 'I'
        self.imagebuffer = array.array(self.imgBuffInitType)
        self.resizeImagebuffer = array.array(self.imgBuffInitType)
        self.pal = None
        self.bg_color = win.color
        self.img_scaling_factor = 3
        self.size = (192*self.img_scaling_factor, 160*self.img_scaling_factor)
        
        # initial setup for the mouse
        self.display.mouseVisible = False
        self.mouse = event.Mouse(visible=False)
        self.last_mouse_state = -1

        # image title & calibration instructions
        self.msgHeight = self.size[1]/20.0
        self.title = visual.TextStim(self.display,'', height=self.msgHeight, color=[1,1,1],
                                     pos = (0,-self.size[1]/2-self.msgHeight), wrapWidth=self.w, units='pix')
        self.calibInst = visual.TextStim(self.display, alignHoriz='left',alignVert ='top', height=self.msgHeight, color=[1,1,1],
                                        pos = (-self.w/2.0, self.h/2.0), units='pix',
                                        text = '''
        Enter: Show/Hide camera image
        Left/Right: Switch camera view
        C: Calibration
        V: Validation
        O: Start Recording
        +=/-: CR threshold
        Up/Down: Pupil threshold
        Alt+arrows: Search limit''')
        
        # lines for drawing cross hair etc.
        self.line = visual.Line(self.display, start=(0, 0), end=(0,0),
                                lineWidth=2.0, lineColor=[0,0,0], units='pix')
        
        # set a few tracker parameters
        self.tracker=tracker
        self.tracker.setOfflineMode()
        self.tracker_version = tracker.getTrackerVersion()
        if self.tracker_version >=3:
            self.tracker.sendCommand("enable_search_limits=YES")
            self.tracker.sendCommand("track_search_limits=YES")
            self.tracker.sendCommand("autothreshold_click=YES")
            self.tracker.sendCommand("autothreshold_repeat=YES")
            self.tracker.sendCommand("enable_camera_position_detect=YES")
        # let the tracker know the correct screen resolution being used
        self.tracker.sendCommand("screen_pixel_coords = 0 0 %d %d" % (self.w-1, self.h-1))