def __init__(self, size, color=cardColor): self._size = size self._stimuli = (stimuli.Picture(templatePicture, position=None), stimuli.Rectangle(size, colour=color, line_width=None, position=None))
def setPicture(self, value, scale=True): self._stimuli = (stimuli.Picture(value, position=self.position), stimuli.Rectangle(self.size, colour=constants.C_WHITE, line_width=None, position=self.position)) if scale: self._stimuli[0].scale(self.size[0] / float(300))
def create_trial(Stimulus, Type, Filenumber): trial = design.Trial() trial.set_factor("Stimulus", Stimulus) trial.set_factor("Type", Type) trial.set_factor('Filenumber', int(Filenumber)) # must write "int" because Filenumber = numpy.float64 due to pandas when 'pandas.read_csv' (wouldn't happen with csv but then would have to generate headers) Image_Stimulus = 'Stimuli_Resize/{} {} {}.jpg'.format( Stimulus, Type, Filenumber ) # each {} is filed by a factor in the presented format () order trial.add_stimulus(stimuli.Picture(Image_Stimulus)) return trial
def logo_text_line(text): blank = stimuli.Canvas(size=(600, 400)) logo = stimuli.Picture(filename=os.path.join(os.path.dirname(__file__), "pytrak_logo.png"), position = (0, 150)) logo.scale(0.6) stimuli.TextLine(text="Version " + __version__, position=(0,80), text_size = 14, text_colour=misc.constants.C_EXPYRIMENT_ORANGE).plot(blank) logo.plot(blank) stimuli.TextLine(text=text).plot(blank) return blank
def trial_generator(task, N): if task[0] == "mixed_task": N = N // 2 b = design.Block() b.set_factor("task_type", task[0]) for specific_task in task[1]: for my_trial in specific_task: t = design.Trial() t.set_factor("shape", my_trial[0]) t.set_factor("filling", my_trial[1]) s = stimuli.Picture(my_trial[2]) t.add_stimulus(s) b.add_trial(t, copies=N) b.shuffle_trials() return b
def image(self, fname, center=True, x=None, y=None, scale=None): """See openexp._canvas.legacy""" if x == None: x = self.xcenter() if y == None: y = self.ycenter() if center == False: surf = pygame.image.load(fname) if scale == None: x += surf.get_width() / 2 y += surf.get_height() / 2 else: x += scale * surf.get_width() / 2 y += scale * surf.get_height() / 2 stim = stimuli.Picture(fname, position=c2p((x, y))) if scale != None: stim.scale((scale, scale)) self.add_stim(stim)
def __init__(self, experiment, buttonlist=None, timeout=None, \ visible=False): """See openexp._mouse.legacy""" self.experiment = experiment self.set_buttonlist(buttonlist) self.set_timeout(timeout) self.set_visible(visible) if self.experiment.get_check('custom_cursor', 'no') == 'yes': if self.experiment.expyriment.screen._fullscreen: raise exceptions.response_error( \ 'The xpyriment mouse back-end does not support custom cursors in fullscreen mode (you can change this in the back-end settings)') self.cursor = stimuli.Picture(self.experiment.resource( \ 'cursor.png')) else: self.cursor = None
def __init__(self, screen_size, pos_y, clef_name="g", design="bw", text=None): self.background_colour = constants.C_WHITE self.foreground_colour = constants.C_BLACK self.clef_name = clef_name # Position of field self.pos_x = 0 self.pos_y = pos_y[self.clef_name] self.field_position = [self.pos_x, self.pos_y] # Size of field is 1 / factor of whole screen factor = 3.5 field_x = screen_size[0] / 2 field_y = screen_size[1] / factor self.field_size = [field_x, field_y] self.Field = stimuli.Canvas(size=self.field_size, position=self.field_position, colour=self.background_colour) # Text field for debugging if text is not None: self.text = text text = stimuli.TextBox(self.text, [100,100]) text.plot(self.Field) # Add lines self.distance = screen_size[0] / 60 line_radius = screen_size[0]/10 for i in range(-2, 3, 1): item = { 'start_point': [-line_radius, self.pos_x - (i * self.distance)], 'end_point': [line_radius, self.pos_x - (i * self.distance)], 'line_width': 2, 'colour': self.foreground_colour } line = stimuli.Line(item['start_point'], item['end_point'], item['line_width'], colour=item['colour']) line.plot(self.Field) # Add clef clef_pos_x = line_radius * 1.2 clef = stimuli.Picture('Stimuli/clef_' + design + '_' + clef_name + '.jpg', position=[-clef_pos_x, 0]) clef.scale(3.9 * screen_size[0] / 100000) clef.plot(self.Field)
def image(self, fname, center=True, x=None, y=None, scale=None): x, y = self.to_xy(x, y) if not center: _fname = safe_decode(fname) try: surf = pygame.image.load(_fname) except pygame.error: raise osexception(u"'%s' is not a supported image format" % fname) if scale is None: x += surf.get_width() / 2 y -= surf.get_height() / 2 else: x += scale * surf.get_width() / 2 y -= scale * surf.get_height() / 2 stim = stimuli.Picture(fname, position=(x, y)) if scale is not None: stim.scale((scale, scale)) self.add_stim(stim)
def image(self, fname, center=True, x=None, y=None, scale=None): if x == None: x = self.xcenter() if y == None: y = self.ycenter() if center == False: if isinstance(fname, unicode): _fname = fname.encode(self.experiment.encoding) else: _fname = fname surf = pygame.image.load(_fname) if scale == None: x += surf.get_width()/2 y += surf.get_height()/2 else: x += scale*surf.get_width()/2 y += scale*surf.get_height()/2 stim = stimuli.Picture(fname, position=c2p((x,y))) if scale != None: stim.scale( (scale, scale) ) self.add_stim(stim)
return resp == expected_key ################################################################################ exp = design.Experiment(name="Cards", text_size=20) control.initialize(exp) ####################### Stimuli Preparation ################################## # load all card images in a dictionary mapping card name to Picture stimuli cards_directory = "cards_pics_small" stim = { op.splitext(f)[0]: stimuli.Picture(op.join(cards_directory, f)) for f in os.listdir(cards_directory) } # canvas mapped onto left, middle and right rectangles C = [ stimuli.Canvas((W, H), (-SHIFT, 0)), stimuli.Canvas((W, H), (0, 0)), stimuli.Canvas((W, H), (+SHIFT, 0)) ] # Create mapping 3 cards triplets -> surfaces three_cards_surfaces = dict() def create_3cards(card1, card2, card3):
def plot_instructions(self): instruction_picture = stimuli.Picture(self.instructions_path) instruction_picture.plot(self.canvas)
onset = row.onset stype = row.type f = row.stim try: cond = row.cond except: cond = "" if stype == 'sound': if not f in mapsounds: mapsounds[f] = stimuli.Audio(op.join(bp, f)) mapsounds[f].preload() events.put((onset, cond, 'sound', f, mapsounds[f])) elif stype == 'picture': if not f in mappictures: mappictures[f] = stimuli.Picture(op.join(bp, f)) mappictures[f].preload() events.put((onset, cond, 'picture', f, mappictures[f])) events.put((onset + PICTURE_DURATION, cond, 'blank', 'blank', bs)) elif stype == 'video': if not f in mapvideos: mapvideos[f] = stimuli.Video(op.join(bp, f)) mapvideos[f].preload() event.put((onset, cond, 'video', f, mapvideos[f])) elif stype == 'text': if not f in maptext: maptext[f] = stimuli.TextLine( f, text_font=TEXT_FONT, text_size=TEXT_SIZE, text_colour=TEXT_COLOR,
def create_picture_stimuli(number, position): return stimuli.Picture(os.path.join("pictures", str(number) + ".png"), position)
STIM_DIR = 'Stimuli/' #I decided not to implement a loop for these three blocks, since I would need to use a dictionary to create variable names from strings. The popular opinion is that it is not advisable pure_shape_block = design.Block() for shape in ['diamond', 'square']: for number in [2, 3]: trial = design.Trial() trial.set_factor('block', 'pure_shape') trial.set_factor('task', 'shape') trial.set_factor('shape', shape) trial.set_factor('number_of_circles', number) pngname = os.path.join(STIM_DIR, 'shape_{}_{}_circles.png'.format(shape, number)) trial.add_stimulus(stimuli.Picture(pngname)) pure_shape_block.add_trial(trial) pure_shape_block.shuffle_trials() pure_filling_block = design.Block() for shape in ['diamond', 'square']: for number in [2, 3]: trial = design.Trial() trial.set_factor('block', 'pure_filling') trial.set_factor('task', 'filling') trial.set_factor('shape', shape) trial.set_factor('number_of_circles', number) pngname = os.path.join( STIM_DIR, 'filling_{}_{}_circles.png'.format(shape, number)) trial.add_stimulus(stimuli.Picture(pngname)) pure_filling_block.add_trial(trial)
def run_test_suite(): """Run the Expyriment test suite.""" import expyriment.design.extras import expyriment.stimuli.extras import expyriment.io.extras import expyriment.misc.extras quit_experiment = False if not expyriment._active_exp.is_initialized: defaults.initialize_delay = 0 defaults.event_logging = 0 exp = expyriment.design.Experiment() exp.testsuite = True expyriment.control.initialize(exp) quit_experiment = True else: exp = expyriment._active_exp # make menu and code for test functions test_functions = ['', '', ''] menu = [ "1) Visual stimulus presentation", "2) Auditory stimulus presentation", "3) Font Viewer" ] for mod, cl in _find_self_tests(): test_functions.append("rtn = {0}.{1}._self_test(exp)".format(mod, cl)) menu.append("{0}) {1} test".format(len(test_functions), cl)) menu.append("{0}) Write protocol".format(len(test_functions) + 1)) menu.append("{0}) Quit".format(len(test_functions) + 2)) test_functions.extend( ['rtn = _write_protocol(exp, results)', 'go_on=False;rtn=[];']) background = stimuli.Canvas(size=[400, 600]) pict = stimuli.Picture(constants.EXPYRIMENT_LOGO_FILE, position=(0, 200)) pict.scale(0.5) pict.plot(background) results = expyriment.get_system_info() try: import android mouse = expyriment.io.Mouse(show_cursor=False) except ImportError: android = None mouse = None preselected_item = 0 go_on = True while go_on: select = expyriment.io.TextMenu("Test suite", menu, width=350, justification=0, background_stimulus=background, mouse=mouse).get(preselected_item) if select == 0: rtn = _stimulus_timing(exp) results["testsuite_visual_timing_todo"] = rtn[0] results["testsuite_visual_timing_actual"] = rtn[1] results["testsuite_visual_sync_refresh_rate"] = str(rtn[2]) + " Hz" results["testsuite_visual_timing_inaccuracy"] = str(rtn[3]) + " ms" results["testsuite_visual_timing_delayed"] = str(rtn[4]) + " %" results["testsuite_visual_flipping_user"] = rtn[5] delay = map( lambda x: x[1] - x[0], zip(results["testsuite_visual_timing_todo"], results["testsuite_visual_timing_actual"])) results["testsuite_visual_timing_delay_histogram"], _ = _histogram( delay) if ogl is not None and exp.screen.open_gl: results["testsuite_visual_opengl_vendor"] = ogl.glGetString( ogl.GL_VENDOR) results["testsuite_visual_opengl_renderer"] = ogl.glGetString( ogl.GL_RENDERER) results["testsuite_visual_opengl_version"] = ogl.glGetString( ogl.GL_VERSION) extensions = ogl.glGetString(ogl.GL_EXTENSIONS).split(" ") if extensions[-1] == "": extensions = extensions[:-1] results["testsuite_visual_opengl_extensions"] = extensions else: results["testsuite_visual_opengl_vendor"] = "" results["testsuite_visual_opengl_renderer"] = "" results["testsuite_visual_opengl_version"] = "" results["testsuite_visual_pygame_driver"] = "" results["testsuite_visual_opengl_extensions"] = "" results[ "testsuite_visual_pygame_driver"] = pygame.display.get_driver( ) results["testsuite_visual_pygame_screensize"] = exp.screen.size preselected_item = select + 1 elif select == 1: results["testsuite_audio_user"] = _audio_playback(exp) try: results["testsuite_audio_frequency"] = str( pygame.mixer.get_init()[0]) + " Hz" results["testsuite_audio_bitdepth"] = str( abs(pygame.mixer.get_init()[1])) + " bit" results["testsuite_audio_channels"] = pygame.mixer.get_init( )[2] except: results["testsuite_audio_frequency"] = "" results["testsuite_audio_bitdepth"] = "" results["testsuite_audio_channels"] = "" preselected_item = select + 1 elif select == 2: _font_viewer(exp) preselected_item = select + 1 else: exec(test_functions[select]) results.update(rtn) preselected_item = select + 1 if quit_experiment: expyriment.control.end(goodbye_delay=0, goodbye_text="Quitting test suite")
#fs.present() #exp.clock.wait(WORD_ISI*6) elif stype == 'sound': bp = op.dirname(splash_screen) if not (STIM_DIR == ''): bp = op.join(bp, STIM_DIR) instruction = stimuli.Audio(op.join(bp, instruction_line)) instruction.preload() instruction.present() fs.present() exp.clock.wait(int(instruction_duration)) elif stype == 'pict': bp = op.dirname(splash_screen) if not (STIM_DIR == ''): bp = op.join(bp, STIM_DIR) instruction = stimuli.Picture(op.join(bp, instruction_line)) instruction.preload() instruction.present() exp.clock.wait(int(instruction_duration)) else: splashs = stimuli.Picture(splash_screen) splashs.present() kb.wait_char(' ') #LAUNCH ONE SESSION else: wm = stimuli.TextLine('Waiting for scanner sync (or press \'t\')', text_font=TEXT_FONT, text_size=TEXT_SIZE, text_colour=TEXT_COLOR, background_colour=BACKGROUND_COLOR)
secondImageList = [ os.path.join(imageLocation, f) for f in [ myFilenames[blockNumber][i] for i in range(len(myFilenames[blockNumber])) if i % 2 == 1 ] ] for image1 in firstImageList: t = design.Trial() image2 = secondImageList[firstImageList.index(image1)] t.set_factor("Image 1 Name", image1) t.set_factor("Image 2 Name", image2) s1 = stimuli.Picture(image1, (0, 0)) s1.scale(scaleFactor) s2 = stimuli.Picture(image2, (0, 0)) s2.scale(scaleFactor) if conditionNames[blockNumber].endswith("Inverted"): s1.flip((False, True)) s2.flip((False, True)) t.add_stimulus(s1) t.add_stimulus(s2) b.add_trial(t, copies=1, random_position=True) exp.add_block(b)
validImages = 0 conditionName = subDirectories[stimuliPaths.index(condition)] b = design.Block(name=conditionName) b.set_factor("Condition", conditionName) imageNames = [os.path.join(condition, f) for f in os.listdir(condition)] imageRandomizer = design.randomize.rand_int_sequence(0, imagesPerBlock) for imageNumber in imageRandomizer: if validImages < imagesPerBlock: if imageNames[imageNumber].endswith('jpg'): t = design.Trial() soloName = os.path.split(imageNames[imageNumber])[1] t.set_factor("Image Name", soloName) s = stimuli.Picture(imageNames[imageNumber], (0,0)) s.scale(scaleFactor) t.add_stimulus(s) b.add_trial(t, copies=1, random_position=True) validImages += 1 else: imageNames.remove(imageNames[imageNumber]) else: break #b.shuffle_trials() exp.add_block(b) ###### RUN EXPERIMENT ###### # exp.save_design("StatLoc_Subject%02d_design.csv" % subjectNumber)
def run_experiment(self): # define headers for expyriment log file output table (we currently don't use it, # but if we want - we can improve it and use it if we want self.exp.data_variable_names = ["time", "location", "direction", "trialType", "response", "rt"\ ,"is success", "is practice", "blockType", "order"] currentTrailsNumber = self.test_trials_number; if self.is_practice: currentTrailsNumber = self.practice_trials_number; for trial_index in range(0, currentTrailsNumber): canvas = stimuli.BlankScreen() time_delay = 0 # plot cross on canvas cross = stimuli.FixCross((50, 50), (0, 0), 5) time_delay += cross.plot(canvas) # plot arrow on canvas picture_arrow = stimuli.Picture(self.direction_file_converter[self.directions[trial_index]] \ , position=self.locations_converter[self.locations[trial_index]]) time_delay += picture_arrow.preload() time_delay += picture_arrow.plot(canvas) # show canvas time_delay += canvas.present(); # send trigger to LSL with arrow details utils.push_sample_current_time(self.outlet, ["stimulus_task_stroop_type_arrow_location_" + ("u" if "up" in self.directions[trial_index] else "d") \ + "_direction_" + ("u" if "up" in self.locations[trial_index] else "d")]) # wait for subject's response. Wait only for "duration" time key, rt = self.game_controller.wait_press(self.possible_joystick_buttons, self.duration,\ process_control_events=False) # we get here is subjects responded or of duration of stimulus ended if key != None: # subject responded and stimulus duration hasn't ended utils.push_sample_current_time(self.outlet, ["keyPressed_task_stroop_key_" + str(key)]) self.exp.clock.wait(self.duration - rt) # wait the rest of the stimulus duration before going on # we get here when stimulus duration has ended (and subject responded) time_delay += self.paint_cross(); self.exp.clock.wait( self.isi - time_delay) # wait for the ISI before going on else: # we get here if subject hasn't responded but stimulus duration ended - so we clean the screen time_delay += self.paint_cross(); key = None; # we wait for subject to respond (but only for the ISI duration) key, rt = self.game_controller.wait_press(self.possible_joystick_buttons, self.isi - time_delay, process_control_events=False) if key != None: # we get here if subject has responded - so we need to wait for the rest of # the ISI self.exp.clock.wait( self.isi - rt - time_delay) # wait the rest of the ISI before going on utils.push_sample_current_time(self.outlet, ["keyPressed_task_stroop_key_" + str(key)]) self.save_trial_data(key, rt, trial_index) self.show_feedback_if_needed()
trials += [('incongruent', 'left'), ('incongruent', 'right')] * 10 random.shuffle(trials) exp = design.Experiment(name="Posner-task", text_size=30, background_colour=GREY, foreground_colour=BLACK) # control.set_develop_mode() control.initialize(exp) cross = stimuli.FixCross(size=(40, 40), colour=BLACK, line_width=6) cross.preload() blankscreen = stimuli.BlankScreen(colour=GREY) target_left = stimuli.Picture("star.png", position=(-150, 0)) target_left.preload() target_right = stimuli.Picture("star.png", position=(+150, 0)) target_right.preload() cue_left = stimuli.Picture('left_arrow.png') cue_left.preload() cue_right = stimuli.Picture('right_arrow.png') cue_right.preload() exp.add_data_variable_names(['congruency', 'side', 'respkey', 'RT']) control.start(skip_ready_screen=True) stimuli.TextScreen(
# fixation dot t.add_stimulus(c2) # rectangles t.add_stimulus(c3) # pictures c4 = stimuli.BlankScreen() fix.plot(c4) rect_b.plot(c4) # path_symbol = os.path.join(path_folder,'PICTURES','symbol'+str(StimList[trial][0])+'.bmp') path_symbol = StimList['Symbol'][trial] symbol = stimuli.Picture(path_symbol, position=pos[2]) symbol.plot(c4) c4.preload() t.add_stimulus(c4) # adding trial to block b.add_trial(t) exp.add_block(b) exp.data_variable_names = [ "subjID", "runID", "TrialID", "decisionTime", "EstSnackID", "EstSource" ] ### START ### control.start(experiment=None,
def initialize(experiment=None): """Initialize an experiment. This initializes an experiment defined by 'experiment' as well as the underlying expyriment system. If 'experiment' is None, a new Experiment object will be created and returned. Furthermore, a screen, a clock, a keyboard and a event file are created and added to the experiment. The initialization screen is shown for a short delay to ensure that Python is fully initialized and time accurate. Afterwards, "Preparing experiment..." is presented on the screen. After experiment initialize the following additional properties are available: - experiment.screen -- the current screen - experiment.clock -- the main clock - experiment.keyboard -- the main keyboard - experiment.mouse -- the main mouse - experiment.event -- the main event file Parameters ---------- experiment : design.Experiment, optional the experiment to initialize Returns ------- exp : design.Experiment initialized experiment """ if experiment is None: experiment = design.Experiment() if experiment.log_level is None: experiment.set_log_level(defaults.event_logging) if is_interactive_mode() and not expyriment.control.defaults.window_mode \ and not hasattr(experiment, "testsuite"): print """ Python is running in an interactive shell but Expyriment wants to initialize a fullscreen.""" quest = "Do you want to switch to windows mode?" ans = raw_input(quest + " (Y/n) ").strip().lower() if ans == "" or ans == "y" or ans == "yes": print "Switched to windows mode" expyriment.control.defaults.window_mode = True stdout_logging = defaults.stdout_logging expyriment._active_exp = experiment old_logging = experiment.log_level experiment.set_log_level(0) # switch off for the first screens _keyboard.quit_key = defaults.quit_key _keyboard.pause_key = defaults.pause_key _keyboard.refresh_key = defaults.refresh_key _keyboard.end_function = end _keyboard.pause_function = pause mixer.pre_init(defaults.audiosystem_sample_rate, defaults.audiosystem_bit_depth, defaults.audiosystem_channels, defaults.audiosystem_buffer_size) if defaults.audiosystem_autostart: mixer.init() mixer.init() # Needed on some systems experiment._clock = misc.Clock() experiment._screen = Screen(colour=(0, 0, 0), open_gl=defaults.open_gl, window_mode=defaults.window_mode, window_size=defaults.window_size) # Hack for IDLE: quit pygame and call atexit functions when crashing if is_idle_running() and sys.argv[0] != "": try: import idlelib.run def wrap(orig_func): def newfunc(*a, **kw): pygame.quit() import atexit atexit._run_exitfuncs() idlelib.run.flush_stdout = orig_func return orig_func(*a, **kw) return newfunc idlelib.run.flush_stdout = wrap(idlelib.run.flush_stdout) except ImportError: pass experiment._data = None experiment._subject = None experiment._is_initialized = True # required before EventFile if old_logging > 0: experiment._events = EventFile( additional_suffix=experiment.filename_suffix, time_stamp=True) if stdout_logging: _set_stdout_logging(experiment._events) else: experiment._events = None experiment._keyboard = Keyboard() experiment._mouse = Mouse(show_cursor=False) logo = stimuli.Picture(misc.constants.EXPYRIMENT_LOGO_FILE, position=(0, 100)) logo.scale((0.7, 0.7)) text = stimuli.TextLine("Version {0}".format(expyriment.get_version()), text_size=14, text_colour=misc.constants.C_EXPYRIMENT_ORANGE, background_colour=(0, 0, 0), position=(0, 40)) canvas = stimuli.Canvas((600, 300), colour=(0, 0, 0)) canvas2 = stimuli.Canvas((600, 300), colour=(0, 0, 0)) logo.plot(canvas) text.plot(canvas) hash_ = expyriment.get_experiment_secure_hash() if hash_ is not None: txt = "{0} ({1})".format(os.path.split(sys.argv[0])[1], hash_) if len(expyriment._secure_hash.module_hashes_as_string()) > 0: txt += ", {0}".format( expyriment._secure_hash.module_hashes_as_string()) text2 = stimuli.TextLine( txt, text_size=14, text_colour=misc.constants.C_EXPYRIMENT_ORANGE, background_colour=(0, 0, 0), position=(0, 10)) text2.plot(canvas) canvas.preload(True) canvas._set_surface(canvas._get_surface().convert()) start = experiment.clock.time r = [x for x in range(256) if x % 5 == 0] stopped = False if defaults.initialize_delay > 0: for x in r: canvas._get_surface().set_alpha(x) canvas2.clear_surface() canvas.plot(canvas2) canvas2.present() experiment.clock.wait(1) key = experiment.keyboard.check(pygame.K_ESCAPE, check_for_control_keys=False) if key is not None: stopped = True break duration = experiment.clock.time - start if duration < 2000 and not stopped: start = experiment.clock.time while experiment.clock.time - start < 2000: key = experiment.keyboard.check(pygame.K_ESCAPE, check_for_control_keys=False) if key is not None: stopped = True break r = [x for x in range(256)[::-1] if x % 5 == 0] if not stopped: for x in r: canvas._get_surface().set_alpha(x) canvas2.clear_surface() canvas.plot(canvas2) canvas2.present() experiment.clock.wait(1) key = experiment.keyboard.check(pygame.K_ESCAPE, check_for_control_keys=False) if key is not None: break stimuli.TextLine("Preparing experiment...", text_size=24, text_colour=misc.constants.C_EXPYRIMENT_PURPLE).present() experiment._screen.colour = experiment.background_colour experiment.set_log_level(old_logging) stimuli._stimulus.Stimulus._id_counter = 0 return experiment
mappictures = dict() mapvideos = dict() for listfile in sys.argv[1:]: stimlist = csv.reader(io.open(listfile, 'r', encoding='utf-8')) bp = op.dirname(listfile) for row in stimlist: onset, stype, f = int(row[0]), row[1], row[2] if stype == 'sound': if not f in mapsounds: mapsounds[f] = stimuli.Audio(op.join(bp, f)) mapsounds[f].preload() events.put((onset, 'sound', f, mapsounds[f])) elif stype == 'picture': if not f in mappictures: mappictures[f] = stimuli.Picture(op.join(bp, f)) mappictures[f].preload() events.put((onset, 'picture', f, mappictures[f])) events.put((onset + PICTURE_DURATION, 'blank', 'blank', bs)) elif stype == 'video': if not f in mapvideos: mapvideos[f] = stimuli.Video(op.join(bp, f)) mapvideos[f].preload() event.put((onset, 'video', f, mapvideos[f])) elif stype == 'text': if not f in maptext: maptext[f] = stimuli.TextLine(f) maptext[f].preload() events.put((onset, 'text', f, maptext[f])) events.put((onset + TEXT_DURATION, 'blank', 'blank', bs)) elif stype == 'rsvp':
""" from expyriment import control, stimuli, io import numpy as np import pygame from pygame.locals import * #control.set_develop_mode(True) exp = control.initialize() ###################### STIMULI ###################### # creating elements on screen # picture path_picture = '/Users/peterkraemer/Desktop/experiment/PICTURES/snack1.bmp' picture = stimuli.Picture(path_picture, position=(0, 200)) # bar barLength = 300 barThick = 10 posBar = (0, -100) bar = stimuli.Rectangle((barLength, barThick), corner_rounding=None, position=posBar) bar.preload() barEndLeft = stimuli.Rectangle((5, barThick * 3), position=((-(barLength + 2) / 2), posBar[1])) barEndLeft.preload() barEndRight = stimuli.Rectangle((5, barThick * 3), position=(((barLength + 2) / 2), posBar[1])) barEndRight.preload()