def logo_text_line(text): blank = stimuli.Canvas(size=(600, 400)) stimuli.TextLine(text="Version " + forceDAQVersion, position=(0, 80), text_size=14, text_colour=constants.C_EXPYRIMENT_ORANGE).plot(blank) stimuli.TextLine(text=text).plot(blank) return blank
def ask_for_order(self): canvas = stimuli.BlankScreen() order1_ = stimuli.Rectangle(size=(100, 80), position=(-200, 0)) Order1 = stimuli.TextLine(text="Order1", position=order1_.position, text_colour=misc.constants.C_WHITE) order2_ = stimuli.Rectangle(size=(100, 80), position=(-70, 0)) Order2 = stimuli.TextLine(text="Order2", position=order2_.position, text_colour=misc.constants.C_WHITE) order3_ = stimuli.Rectangle(size=(100, 80), position=(60, 0)) Order3 = stimuli.TextLine(text="Order3", position=order3_.position, text_colour=misc.constants.C_WHITE) order4_ = stimuli.Rectangle(size=(100, 80), position=(200, 0)) Order4 = stimuli.TextLine(text="Order4", position=order4_.position, text_colour=misc.constants.C_WHITE) order1_.plot(canvas) Order1.plot(canvas) order2_.plot(canvas) Order2.plot(canvas) order3_.plot(canvas) Order3.plot(canvas) order4_.plot(canvas) Order4.plot(canvas) self.experiment.exp.mouse.show_cursor() canvas.present() while True: id, pos, _rt = self.experiment.exp.mouse.wait_press() if order1_.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() self.current_block_order_number = '1' return elif order2_.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() self.current_block_order_number = '2' return elif order3_.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() self.current_block_order_number = '3' return elif order4_.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() self.current_block_order_number = '4' return
def _clickable_numeric_input(title, start_at): # copied from the 0.7.0 release of expyriment # https://github.com/expyriment/expyriment/blob/81acb8be1a2abcecdbbfe501e9c4f662c9ba6620/expyriment/control/_experiment_control.py#L96 background_stimulus = stimuli.BlankScreen(colour=(0, 0, 0)) fields = [ stimuli.Circle(diameter=200, colour=(70, 70, 70), position=(0, 70)), stimuli.Circle(diameter=200, colour=(70, 70, 70), position=(0, -70)), stimuli.Rectangle(size=(50, 50), colour=(70, 70, 70), position=(120, 0)) ] fields[0].scale((0.25, 0.25)) fields[1].scale((0.25, 0.25)) # stimuli.TextLine(text="-", text_size=36, position=(0, -70), # text_font="FreeMono", # text_colour=(0, 0, 0)), plusminus = [ stimuli.TextLine(title, text_size=24, text_colour=misc.constants.C_EXPYRIMENT_PURPLE, position=(-182, 0)), stimuli.FixCross(size=(15, 15), position=(0, 70), colour=(0, 0, 0), line_width=2), stimuli.FixCross(size=(15, 2), position=(0, -70), colour=(0, 0, 0), line_width=2), stimuli.TextLine(text="Go", text_size=18, position=(120, 0), text_colour=(0, 0, 0)) ] number = int(start_at) while True: text = stimuli.TextLine(text="{0}".format(number), text_size=28, text_colour=misc.constants.C_EXPYRIMENT_ORANGE) btn = io.TouchScreenButtonBox(button_fields=fields, stimuli=plusminus + [text], background_stimulus=background_stimulus) btn.show() key, rt = btn.wait() if key == fields[0]: number += 1 elif key == fields[1]: number -= 1 if number <= 0: number = 0 elif key == fields[2]: break return (number)
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 get_input(exp, i): global measurement_rate, max_range, report_rate, power_line, metric if i == 1: measurement_rate = int(io.TextInput("Measurement rate (20 Hz < rate < 255 Hz):", length=3, ascii_filter=range(ord("0"), ord("9") + 1)).get()) if measurement_rate < 20 or measurement_rate > 255: measurement_rate = 80 invalid_value() else: stimuli.TextLine(text="Measurement rate set to {0} Hz.".format(measurement_rate)).present() exp.clock.wait(t_wait) return elif i == 2: max_range = int(io.TextInput("Maximum range of transmitter (36, 72, 144 inches):", length=3, ascii_filter=range(ord("1"), ord("5")) + [ord("6"), ord("7")]).get()) if max_range not in [36, 72, 144]: max_range = 36 invalid_value() else: stimuli.TextLine(text="Maximum range of transmitter set to {0} inches.".format(max_range)).present() exp.clock.wait(t_wait) return elif i == 3: report_rate = int(io.TextInput("Report rate of the data (1 <= rate <= 127):", length=3, ascii_filter=range(ord("0"), ord("9") + 1)).get()) if report_rate < 1 or report_rate > 127: report_rate = 1 invalid_value() else: stimuli.TextLine(text="Report rate of incoming data set to {0}.".format(report_rate)).present() exp.clock.wait(t_wait) return elif i == 4: power_line = int(io.TextInput("Power line frequency of the AC power source (50 or 60 Hz):", length=2, ascii_filter=[ord("0"), ord("5"), ord("6")]).get()) if power_line not in [50, 60]: power_line = 60 invalid_value() else: stimuli.TextLine( text="Power line frequency of the AC power source set to {0} Hz.".format(power_line)).present() exp.clock.wait(t_wait) return elif i == 5: metric = int(io.TextInput("Switch metric data reporting on/off (1/0):", length=1, ascii_filter=[ord("0"), ord("1")]).get()) if metric not in [0, 1]: metric = True invalid_value() else: stimuli.TextLine(text="Metric data reporting set to {0}.".format(metric)).present() exp.clock.wait(t_wait) return
def blocks(nb_el_block, nb_probes, exp, block_name): """Run a block of trials with the inputed parameters Saves in the expyriment data file : subject_id, stimulus (digit), button pressed (always space), RT , error, block name Saves in the manually created data file : block name, trial number, reponse and rt to both Probes Is used once for the practice block and another number of time (chosen in the parameters) for the real blocks """ #random size out of 5 font_sizes_list = [48, 72, 94, 100, 120] #list far easier this way #numbers = list(range(0,10)) repetitions = round(nb_el_block / 10) block = [] for i in range(repetitions): for j in range(0, 10): block.append(j) probe_trials = probe_random(nb_el_block, nb_probes) trial_number = 0 for digit in block: trial_number += 1 f_size = randint(0, 4) target = stimuli.TextLine(text=str(digit), text_size=font_sizes_list[f_size]) mask = stimuli.TextLine(text='X\u0336', text_size=font_sizes_list[f_size]) target.present() exp.clock.wait(250) mask.present() button, rt = exp.keyboard.wait(misc.constants.K_SPACE, 900) #to make sure the ITI stays at 1150ms if rt != None: time_left = 900 - rt exp.clock.wait(time_left - stimuli.BlankScreen().present()) error = (button == misc.constants.K_SPACE and digit == 3) or (button == [] and digit != 3) exp.data.add([digit, button, rt, int(error), block_name]) #probe trials if trial_number in probe_trials: button_r, rt_r, button_c, rt_c = probes() globals()[''.join(data_probe_name)] = open(''.join(data_file_name), "a") globals()[''.join(data_probe_name)].write(str(block_name)+','+str(trial_number)\ +','+str(button_r)+','+str(rt_r)+','+str(button_c)+','+str(rt_c)+ '\n') globals()[''.join(data_probe_name)].close
def write_text(self, text_above, text_edges, y_position, canvas): line_start = 0 - (self.line_length / 2) line_end = 0 + (self.line_length / 2) text_above = stimuli.TextLine(text_above, [0-10, y_position + self.title_distance_from_scale],\ text_font='Monospace', text_size=self.text_size) text_start = stimuli.TextLine(text_edges[0], [line_start + self.start_text_distance_from_scale,\ y_position + self.edges_distance_above_scale],\ text_font='Monospace', text_size=self.text_size) text_end = stimuli.TextLine(text_edges[1], [line_end + self.end_text_distance_from_Scale,\ y_position + self.edges_distance_above_scale ],\ text_font='Monospace', text_size=self.text_size) text_above.plot(canvas) text_start.plot(canvas) text_end.plot(canvas)
def show_feedback_if_needed(self): currentTrialsNumber = self.test_trials_number; if self.is_practice: currentTrialsNumber = self.practice_trials_number; if self.is_practice == True: canvas = stimuli.BlankScreen() text_title = stimuli.TextLine("Success Rate", (0,0), text_size=(50)) success_rate = str(float(self.correct_trials) / currentTrialsNumber * 100) text_number = stimuli.TextLine(success_rate + "%", position=(0, -100),\ text_size=(50)) text_title.plot(canvas) text_number.plot(canvas) canvas.present();
def line_bisection_task(line_length, position): # make button button = stimuli.Rectangle(size=(40, 20), position=(exp.screen.size[0] / 2 - 25, 15 - exp.screen.size[1] / 2)) button_text = stimuli.TextLine(text="ok", position=button.position, text_colour=misc.constants.C_WHITE) mark_position = None while True: canvas = stimuli.BlankScreen() line = stimuli.Rectangle(size=(line_length, 3), position=position, colour=misc.constants.C_BLACK) line.plot(canvas) if mark_position is not None: # plot button and mark line on canvas button.plot(canvas) button_text.plot(canvas) markline = stimuli.Rectangle(size=(1, 25), position=(mark_position, line.position[1]), colour=misc.constants.C_RED) markline.plot(canvas) # present stimulus canvas.present() # wait for mouse or touch screen response _id, pos, _rt = exp.mouse.wait_press() # process clicked position position if abs(pos[1]-line.position[1])<=50 and\ abs(pos[0]-line.position[0])<=line_length/2: mark_position = pos[0] else: if button.overlapping_with_position(pos): # is button pressed return mark_position - line.position[0]
def run_trial(cnt, trial): # present Fixation cross and prepare trial in the meantime fixcross.present() exp.clock.reset_stopwatch() ISI = design.randomize.rand_int(min_max_ISI[0], min_max_ISI[1]) digit = trial.get_factor("digit") target = stimuli.TextLine(text=str(digit), text_size=60) target.preload() exp.clock.wait(t_fixcross - exp.clock.stopwatch_time) #presesnt blankscreen for a random interval blankscreen.present() exp.clock.wait(ISI) # Present target & record button response target.present() btn, rt = exp.keyboard.wait([constants.K_LEFT, constants.K_RIGHT]) #Error feedback if required if block.get_factor("mapping") == "left_odd": error = (digit % 2 == 0 and btn == constants.K_LEFT) or \ (digit % 2 == 1 and btn == constants.K_RIGHT) else: error = (digit % 2 == 1 and btn == constants.K_LEFT) or \ (digit % 2 == 0 and btn == constants.K_RIGHT) if error: error_beep.present() #write data and clean up while inter-trial-interval blankscreen.present() exp.clock.reset_stopwatch() exp.data.add([block.id, block.get_factor("mapping"), cnt, target.text, ISI, btn, rt, int(error)]) exp.data.save() target.unload() exp.clock.wait(ITI - exp.clock.stopwatch_time)
def mount_design(self): """ Creates a list of expyriment.design.Block objects, creates trials and loads the experimental stim according to the class parameters Returns ------- exp_design: list of expyriment.design.Block objects list containing the blocks, trials and stimuli ready to run """ block_list = [design.Block(name='run%d' % block + 1 for block in range(self.n_block))] run_list = [open(filename) for filename in sorted(os.listdir(self.stim_list))] for block in range(self.n_block): for line in run_list[block].readlines(): trial = design.Trial() stim = stimuli.TextLine("+") trial.add_stimulus(stim) block_list[block].add_trial(trial) self.exp.add_block(block_list[block])
def prepare_button_boxes(self, labels): buttons = [] for i, lb in enumerate(labels): width, height = self.screen.window_size size = (width / len(labels), self._unit(self.config.get('APPEARANCE', 'button_height'))) pos = (int(size[0] * (i - len(labels) / 2.0 + 0.5)), -(height - size[1]) / 2) btn = stimuli.Rectangle(size=size, position=pos, colour=self._colours( self.config.get( 'APPEARANCE', 'button_background_colour'))) stimuli.Rectangle( size=size, line_width=5, colour=self._colours( self.config.get('APPEARANCE', 'button_border_colour'))).plot(btn) text = stimuli.TextLine(text=lb, text_colour=self._colours( self.config.get( 'APPEARANCE', 'button_text_colour'))) text.plot(btn) btn.label = lb btn.preload() buttons.append(btn) return (buttons)
def pause(): """Pause a running experiment. This will show a pause screen and waits for ENTER to be pressed to continue. """ if not expyriment._active_exp.is_initialized: raise Exception("Experiment is not initialized!") experiment = expyriment._active_exp experiment._event_file_log("Experiment,paused") screen_colour = experiment.screen.colour experiment._screen.colour = [0, 0, 0] old_logging = experiment.log_level experiment.set_log_level(0) if android is not None: position = (0, 200) else: position = (0, 0) stimuli.TextLine("Paused", position=position, text_colour=misc.constants.C_EXPYRIMENT_ORANGE, text_size=24).present() experiment.set_log_level(old_logging) experiment._screen.colour = screen_colour stimuli._stimulus.Stimulus._id_counter -= 1 misc.Clock().wait(200) if android is None: experiment.keyboard.wait() else: experiment.mouse.wait_press() experiment._event_file_log("Experiment,resumed")
def _clickable_numeric_input(title, start_at, scale=1.0): positions = [(100*scale, 0), (-100*scale, 0), (300*scale, -200*scale)] btn_colour = misc.constants.C_DARKGREY btn_size = (int(70*scale), int(70*scale)) btn_text_colour = (0, 0, 0) pos_title = (0, 100*scale) title_text_colour = misc.constants.C_GREY number_text_colour = misc.constants.C_GREY buttons = [stimuli.Rectangle(size=btn_size, colour=btn_colour, position=pos) for pos in positions] plus_width = 2*scale if expyriment_version[0] == 7 else 3*scale minus_width = 3*scale labels = [ stimuli.TextLine(text='OK', text_size=int(30*scale), position=positions[2], text_colour=btn_text_colour), stimuli.FixCross(size=(40*scale, 40*scale), position=positions[0], colour=btn_text_colour, line_width=plus_width), stimuli.FixCross(size=(40*scale, 3*scale), position=positions[1], colour=btn_text_colour, line_width=minus_width), stimuli.TextLine(title, text_size=int(30*scale), text_colour=title_text_colour, position=pos_title) ] number = int(start_at) while True: current_num = stimuli.TextLine(text=str(number), text_size=int(40*scale), text_colour=number_text_colour) button_box = io.TouchScreenButtonBox(buttons, labels+[current_num]) button_box.show() key = button_box.wait()[0] if key == buttons[0]: number = number + 1 elif key == buttons[1]: number = max(number - 1, 1) elif key == buttons[2]: return(number) return(number)
def ask_for_task(): canvas = stimuli.BlankScreen() develop_mode = use_develop_mode design.defaults.experiment_background_colour = misc.constants.C_GREY design.defaults.experiment_foreground_colour = misc.constants.C_BLACK N_back = stimuli.Rectangle(size=(100, 80), position=(200, 0)) text_N_back = stimuli.TextLine(text="N back", position=N_back.position, text_colour=misc.constants.C_WHITE) Stroop = stimuli.Rectangle(size=(100, 80), position=(-200, 0)) text_Stroop = stimuli.TextLine(text="Stroop", position=Stroop.position, text_colour=misc.constants.C_WHITE) exit = stimuli.Rectangle(size=(100, 80), position=(0, -200)) text_exit = stimuli.TextLine(text="Exit", position=exit.position, text_colour=misc.constants.C_WHITE) N_back.plot(canvas) text_N_back.plot(canvas) Stroop.plot(canvas) text_Stroop.plot(canvas) exit.plot(canvas) text_exit.plot(canvas) exp.mouse.show_cursor() canvas.present() while True: id, pos, _rt = exp.mouse.wait_press() if N_back.overlapping_with_position(pos): exp.mouse.hide_cursor() return 'n_back', exp elif Stroop.overlapping_with_position(pos): exp.mouse.hide_cursor() return 'stroop', exp elif exit.overlapping_with_position(pos): exp.mouse.hide_cursor() return 'exit', exp
def startTrial(NUMBER, OPERATOR): #fixcross.preload() exp = design.Experiment("MATH") control.initialize(exp) control.start() fixcross = stimuli.FixCross() txt_input = io.TextInput("= ") stimuli.TextScreen("MATH GAME", "STARTING in 10 secs", heading_size=40, text_size=60).present() exp.clock.wait(2000) #stim -1 fixcross.preload() fixcross.present() exp.clock.wait(10000) b = design.Block() for i in range(0, 10): #FOR 10 TRIALS b.clear_trials() b = design.Block() print(i) tr = atl.arithmetictriall1(NUMBER, OPERATOR) print(tr) for trel in tr[0]: t = design.Trial() s = stimuli.TextLine(text=str(trel), text_size=120, text_colour=misc.constants.C_GREEN) t.add_stimulus(s) b.add_trial(t) #print(b.trials) exp.add_block(b) #START TEST: ONSCREEN for b in exp.blocks: fixcross.present() exp.clock.wait(100) for t in b.trials: t.stimuli[0].present() exp.clock.wait(1000) print(b) exp.clock.reset_stopwatch() answer = txt_input.get() try: answer = int(answer) if answer == tr[1]: print("Correct") else: print("incorrect") except: print("incorrect")
def show_feedback_if_needed(self): if self.is_practice == True: canvas = stimuli.BlankScreen() text_title = stimuli.TextLine("Success Rate", (0, 0), text_size=(50)) success_rate = int(float(self.hit_trials) / self.targets_amount * 100) - \ int(float(self.FA_trials) / (self.trials_number - self.targets_amount) * 100) if success_rate < 0: success_rate = "0" if success_rate > 100: success_rate = "100" else: success_rate = str(success_rate) text_number = stimuli.TextLine(success_rate + "%", position=(0, -100),\ text_size=(50)) text_title.plot(canvas) text_number.plot(canvas) canvas.present()
def _text_size(self, text): try: _font = self.experiment.resource(u"%s.ttf" % self.font_family) except: _font = self.font_family stim = stimuli.TextLine(text, text_font=_font, text_size=self.font_size, text_bold=self.font_bold, text_italic=self.font_italic) surf = stim._create_surface() return surf.get_width(), surf.get_height()
def prepare_trial(self, key): trial = design.Trial() for key_pos in key: trial.add_stimulus( stimuli.TextLine( key_pos, position=self.stimulus_offset, text_colour=self.stimulus_colour, text_size=self.stimulus_text_size)) trial.set_factor('sequence', key) trial.set_factor('sequence_length', len(key)) return(trial)
def text_size(self, text): """See openexp._canvas.legacy""" try: _font = self.experiment.resource(u"%s.ttf" % self.font_style) except: _font = self.font_style stim = stimuli.TextLine(text, text_font=_font, \ text_size=self.font_size, text_bold=self.font_bold, \ text_italic=self.font_italic) surf = stim._create_surface() return surf.get_width(), surf.get_height()
def ask_for_level(self): canvas = stimuli.BlankScreen() level1 = stimuli.Rectangle(size=(100, 80), position=(200, 0)) text_level1 = stimuli.TextLine(text="1 back", position=level1.position, text_colour=misc.constants.C_WHITE) level2 = stimuli.Rectangle(size=(100, 80), position=(0, 0)) text_level2 = stimuli.TextLine(text="2 back", position=level2.position, text_colour=misc.constants.C_WHITE) level3 = stimuli.Rectangle(size=(100, 80), position=(-200, 0)) text_level3 = stimuli.TextLine(text="3 back", position=level3.position, text_colour=misc.constants.C_WHITE) level1.plot(canvas) text_level1.plot(canvas) level2.plot(canvas) text_level2.plot(canvas) level3.plot(canvas) text_level3.plot(canvas) self.experiment.exp.mouse.show_cursor() canvas.present() while True: id, pos, _rt = self.experiment.exp.mouse.wait_press() if level1.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return "1" elif level2.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return "2" elif level3.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return "3"
def ask_for_practice_type(self): canvas = stimuli.BlankScreen() auditory = stimuli.Rectangle(size=(100, 80), position=(200, 0)) text_auditory = stimuli.TextLine(text="auditory", position=auditory.position, text_colour=misc.constants.C_WHITE) spatial = stimuli.Rectangle(size=(100, 80), position=(-200, 0)) text_spatial = stimuli.TextLine(text="spatial", position=spatial.position, text_colour=misc.constants.C_WHITE) both = stimuli.Rectangle(size=(100, 80), position=(0, 0)) text_both = stimuli.TextLine(text="both", position=both.position, text_colour=misc.constants.C_WHITE) auditory.plot(canvas) text_auditory.plot(canvas) spatial.plot(canvas) text_spatial.plot(canvas) both.plot(canvas) text_both.plot(canvas) self.experiment.exp.mouse.show_cursor() canvas.present() while True: id, pos, _rt = self.experiment.exp.mouse.wait_press() if auditory.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return "a" elif spatial.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return "v" elif both.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return "both"
def ask_for_condition(self): canvas = stimuli.BlankScreen() Practice = stimuli.Rectangle(size=(100, 80), position=(200, 0)) text_Practice = stimuli.TextLine(text="Practice", position=Practice.position, text_colour=misc.constants.C_WHITE) Basic = stimuli.Rectangle(size=(100, 80), position=(-200, 0)) text_Basic = stimuli.TextLine(text="Test", position=Basic.position, text_colour=misc.constants.C_WHITE) exit = stimuli.Rectangle(size=(100, 80), position=(0, -200)) text_exit = stimuli.TextLine(text="Exit", position=exit.position, text_colour=misc.constants.C_WHITE) Practice.plot(canvas) text_Practice.plot(canvas) Basic.plot(canvas) text_Basic.plot(canvas) exit.plot(canvas) text_exit.plot(canvas) self.experiment.exp.mouse.show_cursor() canvas.present() while True: id, pos, _rt = self.experiment.exp.mouse.wait_press() if Practice.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return 'practice' elif Basic.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return 'test' elif exit.overlapping_with_position(pos): self.experiment.exp.mouse.hide_cursor() return 'exit'
def client(server_ip): # t : test connect # q : quit client # space : enter control.set_develop_mode(True) control.defaults.audiosystem_autostart = False exp = control.initialize() udp_connection = UDPConnection() print(udp_connection) if not udp_connection.connect_peer(server_ip): print("error connecting to peer") exit() stimuli.TextScreen( "connected to " + udp_connection.peer_ip, "\nSPACE: send text\nT: trigger test\nQ: quit").present() c = Clock() while True: key = exp.keyboard.check() if key == ord("q"): break elif key == misc.constants.K_SPACE: text = io.TextInput().get() stimuli.BlankScreen().present() print("send: {} {}".format(c.time, text)) udp_connection.send(text) elif key == ord("t"): times = [] for cnt in range(20): stimuli.TextLine("ping test " + str(cnt)).present() c.reset_stopwatch() ok, time = udp_connection.ping(timeout=1) print("answer received in {} ms".format(c.stopwatch_time)) times.append(time) c.wait(100) stimuli.BlankScreen().present() print(times) feedback = udp_connection.poll() if feedback is not None: print("received: {} {}".format(c.time, feedback)) udp_connection.unconnect_peer()
def _text(self, text, x, y): try: _font = self.experiment.resource(u"%s.ttf" % self.font_family) except: _font = self.font_style w, h = self.text_size(text) x += w/2 y += h/2 stim = stimuli.TextLine(text, position=self.to_xy((x,y)), text_colour=self.color.backend_color, text_font=_font, text_size=self.font_size, text_bold=self.font_bold, text_italic=self.font_italic, text_underline=self.font_underline) self.add_stim(stim)
def _text(self, text, x, y): """See openexp._canvas.legacy""" try: _font = self.experiment.resource(u"%s.ttf" % self.font_style) except: _font = self.font_style w, h = self.text_size(text) x += w / 2 y += h / 2 stim = stimuli.TextLine(text, position=c2p((x,y)), \ text_colour=self.fgcolor, text_font=_font, \ text_size=self.font_size, text_bold=self.font_bold, \ text_italic=self.font_italic, text_underline=self.font_underline) self.add_stim(stim)
def main(exp): """Displays the instructions and successively lauches each block """ #practice block instructions = stimuli.TextScreen( heading="Practise", text="Thank you for participating in this experiment. \ \nThe task is very simple : you will see numbers appear briefly on the screen, followed by a crossed capital X.\ \nYou must press spacebar everytime you see a number EXCEPT when it's the number 3. \ \n\n You also need to know that at random moments, 'thought probes' are going to appear. \ \nThose probes inquire about what you were thinking about, just before they appeared.\ \n(WARNING: to answer the probes, you should use the numbers on top of your keyboard, with Caps Lock on !!!)\ \n\nIf you understood well and are ready to do a practice trial, press space bar" ) instructions.present() exp.keyboard.wait(misc.constants.K_SPACE) block_name = "practice" blocks(nb_el_block_p, nb_probes_p, exp, block_name) #real blocks instructions = stimuli.TextScreen( heading="Experiment", text= "Instructions:\nYou must press spacebar everytime you see a number EXCEPT when it's the number 3. \ \nAnswer on the scaleS about your thoughts when they appear. \ \n\nIf you are ready for the real experiment, press space bar") instructions.present() exp.keyboard.wait(misc.constants.K_SPACE) for i in range(nb_block_r): block_name = "real" + str(i + 1) blocks(nb_el_block_r, nb_probes_r, exp, block_name) instructions = stimuli.TextLine( text="Ready for the next trial? Press spacebar") instructions.present() exp.keyboard.wait(misc.constants.K_SPACE) control.end(goodbye_text="Thank you very much...", goodbye_delay=2000)
bs = stimuli.BlankScreen(bgColor) # Create blank screen m.plotDefault(bs, True) # Draw default grid exp.clock.wait(shortRest) exp.add_experiment_info(['Block {} - Presentation'.format(0) ]) # Add listPictures exp.add_experiment_info(presentationOrder) # Add listPictures instructions = stimuli.TextLine( ' PRESENTATION ', position=(0, -windowSize[1] / float(2) + (2 * m.gap + cardSize[1]) / float(2)), text_font=None, text_size=textSize, text_bold=None, text_italic=None, text_underline=None, text_colour=textColor, background_colour=bgColor, max_width=None) instructionRectangle.plot(bs) instructions.plot(bs) bs.present(False, True) exp.clock.wait(shortRest) # Short Rest between presentation and cue-recall instructionRectangle.plot(bs) bs.present(False, True) exp.clock.wait(shortRest)
PICTURE_DURATION = 1000 TEXT_DURATION = 3000 #TOTAL_EXPE_DURATION = 20000 # 10 sec exp = expyriment.design.Experiment(name="HiRes Experiment") #expyriment.control.defaults.open_gl=1 expyriment.control.defaults.window_size = (1280, 1028) expyriment.control.set_develop_mode(True) #% expyriment.control.initialize(exp) kb = expyriment.io.Keyboard() bs = stimuli.BlankScreen() wm = stimuli.TextLine('Waiting for scanner sync (or press \'t\')') fs = stimuli.FixCross() events = PriorityQueue() # all stimuli will be queued here # load stimuli mapsounds = dict() mapspeech = dict() maptext = dict() mappictures = dict() mapvideos = dict() for listfile in sys.argv[1:]: stimlist = csv.reader(io.open(listfile, 'r', encoding='utf-8')) bp = op.dirname(listfile)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ A very short example experiment in 16 lines of pure code. Participants have to indicate the parity of digits by pressing the left arrow key for odd and the right arrow key for even numbers. """ from expyriment import control, stimuli, design, misc digit_list = [1, 2, 3, 4, 6, 7, 8, 9] * 12 design.randomize.shuffle_list(digit_list) exp = control.initialize() exp.data_variable_names = ["digit", "btn", "rt", "error"] control.start(exp) for digit in digit_list: target = stimuli.TextLine(text=str(digit), text_size=80) exp.clock.wait(500 - stimuli.FixCross().present() - target.preload()) target.present() button, rt = exp.keyboard.wait( [misc.constants.K_LEFT, misc.constants.K_RIGHT]) error = (button == misc.constants.K_LEFT) == digit % 2 if error: stimuli.Tone(duration=200, frequency=2000).play() exp.data.add([digit, button, rt, int(error)]) exp.clock.wait(1000 - stimuli.BlankScreen().present() - target.unload()) control.end(goodbye_text="Thank you very much...", goodbye_delay=2000)