def _reset(self): self.duration = None self.status = NOT_STARTED self._numpy_frame = None if self._texID is not None: GL.glDeleteTextures(1, self._texID) self._texID = None # self._video_stream = None self._total_frame_count = None self._video_width = None self._video_height = None # TODO: Read depth from video source self._video_frame_depth = 3 self._video_frame_rate = None self._inter_frame_interval = None self._prev_frame_sec = None self._next_frame_sec = None self._next_frame_index = None self._prev_frame_index = None self._video_perc_done = None # self._last_video_flip_time = None self._next_frame_displayed = False self._video_track_clock = Clock() self._audio_stream_clock = Clock() self._vlc_instance = None self._audio_stream = None self._audio_stream_player = None self._audio_stream_started = False self._audio_stream_event_manager = None
def _reset(self): self.duration = None self.status = NOT_STARTED self._numpy_frame = None self._frame_texture = None self._frame_data_interface = None self._video_stream = None self._total_frame_count = None self._video_width = None self._video_height = None # TODO: Read depth from video source self._video_frame_depth = 3 self._video_frame_rate = None self._inter_frame_interval = None self._prev_frame_sec = None self._next_frame_sec = None self._next_frame_index = None self._prev_frame_index = None self._video_perc_done = None self._last_video_flip_time = None self._next_frame_displayed = False self._video_track_clock = Clock() self._vlc_instance = None self._audio_stream = None self._audio_stream_player = None self._audio_stream_started = False self._audio_stream_event_manager=None self._last_audio_callback_time = core.getTime() self._last_audio_stream_time = None self._first_audio_callback_time = None self._audio_computer_time_drift = None
def __init__(self, win, filename="", units='pix', size=None, pos=(0.0, 0.0), anchor="center", ori=0.0, flipVert=False, flipHoriz=False, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, volume=1.0, name='', loop=False, autoLog=True, depth=0.0, noAudio=False, vframe_callback=None, fps=None, interpolate=True): # what local vars are defined (these are the init params) for use # by __repr__ self._initParams = dir() self._initParams.remove('self') super(MovieStim3, self).__init__(win, units=units, name=name, autoLog=False) retraceRate = win._monitorFrameRate if retraceRate is None: retraceRate = win.getActualFrameRate() if retraceRate is None: logging.warning("FrameRate could not be supplied by psychopy; " "defaulting to 60.0") retraceRate = 60.0 self._retraceInterval = 1.0 / retraceRate self.filename = pathToString(filename) self.loop = loop self.flipVert = flipVert self.flipHoriz = flipHoriz self.pos = numpy.asarray(pos, float) self.anchor = anchor self.depth = depth self.opacity = opacity self.interpolate = interpolate self.noAudio = noAudio self._audioStream = None self.useTexSubImage2D = True if noAudio: # to avoid dependency problems in silent movies self.sound = None else: from psychopy import sound self.sound = sound # set autoLog (now that params have been initialised) self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self))) self._videoClock = Clock() self.loadMovie(self.filename) self.setVolume(volume) self.nDroppedFrames = 0 # size if size is None: self.size = numpy.array([self._mov.w, self._mov.h], float) else: self.size = val2array(size) self.ori = ori self._updateVertices()
def __init__(self, win, filename="", units='pix', size=None, pos=(0.0, 0.0), ori=0.0, flipVert=False, flipHoriz=False, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, volume=1.0, name='', loop=False, autoLog=True, depth=0.0, noAudio=False, vframe_callback=None, fps=None, interpolate=True): """ :Parameters: filename : a string giving the relative or absolute path to the movie. flipVert : True or *False* If True then the movie will be top-bottom flipped flipHoriz : True or *False* If True then the movie will be right-left flipped volume : The nominal level is 100, and 0 is silence. loop : bool, optional Whether to start the movie over from the beginning if draw is called and the movie is done. """ # what local vars are defined (these are the init params) for use # by __repr__ self._initParams = dir() self._initParams.remove('self') super(MovieStim3, self).__init__(win, units=units, name=name, autoLog=False) retraceRate = win._monitorFrameRate if retraceRate is None: retraceRate = win.getActualFrameRate() if retraceRate is None: logging.warning("FrameRate could not be supplied by psychopy; " "defaulting to 60.0") retraceRate = 60.0 self._retraceInterval = 1.0 / retraceRate self.filename = filename self.loop = loop self.flipVert = flipVert self.flipHoriz = flipHoriz self.pos = numpy.asarray(pos, float) self.depth = depth self.opacity = float(opacity) self.interpolate = interpolate self.noAudio = noAudio self._audioStream = None self.useTexSubImage2D = True if noAudio: # to avoid dependency problems in silent movies self.sound = None else: from psychopy import sound self.sound = sound self._videoClock = Clock() self.loadMovie(self.filename) self.setVolume(volume) self.nDroppedFrames = 0 # size if size is None: self.size = numpy.array([self._mov.w, self._mov.h], float) else: self.size = val2array(size) self.ori = ori self._updateVertices() # set autoLog (now that params have been initialised) self.autoLog = autoLog if autoLog: logging.exp("Created %s = %s" % (self.name, str(self)))
def __init__(self, win, filename="", units='pix', size=None, pos=(0.0, 0.0), ori=0.0, flipVert=False, flipHoriz=False, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, volume=1.0, name='', loop=False, autoLog=True, depth=0.0, noAudio=False, vframe_callback=None, fps=None, interpolate=True): """ :Parameters: filename : a string giving the relative or absolute path to the movie. flipVert : True or *False* If True then the movie will be top-bottom flipped flipHoriz : True or *False* If True then the movie will be right-left flipped volume : The nominal level is 100, and 0 is silence. loop : bool, optional Whether to start the movie over from the beginning if draw is called and the movie is done. """ # what local vars are defined (these are the init params) for use # by __repr__ self._initParams = dir() self._initParams.remove('self') super(VlcMovieStim, self).__init__(win, units=units, name=name, autoLog=False) # check for pyglet if win.winType != 'pyglet': logging.error( 'Movie stimuli can only be used with a pyglet window') core.quit() self._retracerate = win._monitorFrameRate if self._retracerate is None: self._retracerate = win.getActualFrameRate() if self._retracerate is None: logging.warning("FrameRate could not be supplied by psychopy; " "defaulting to 60.0") self._retracerate = 60.0 self.filename = pathToString(filename) self.loop = loop self.flipVert = flipVert self.flipHoriz = flipHoriz self.pos = numpy.asarray(pos, float) self.size = numpy.asarray(size, float) self.depth = depth self.opacity = float(opacity) self.volume = volume self.no_audio = noAudio self.interpolate = interpolate self._texture_id = GL.GLuint() GL.glGenTextures(1, ctypes.byref(self._texture_id)) self._pause_time = 0 self._vlc_clock = Clock() self._vlc_initialized = False self._reset() self.loadMovie(self.filename) self.setVolume(volume) self.nDroppedFrames = 0 self.ori = ori # set autoLog (now that params have been initialised) self.autoLog = autoLog if autoLog: logging.exp("Created {} = {}".format(self.name, self))
pos_x = randint(-700, 700) pos_y = randint(-400, 400) new_pos = (pos_x, pos_y) target.setPos(new_pos) # I call out the objects I will use and define my DISP and BGC: DISPSIZE = (1400,800) BGC = (-1,-1,-1) score = 0 win = Window(size=DISPSIZE, units='pix', fullscr=False, color=BGC) target = ImageStim(win, 'target.png', size = (420, 420)) # i created this target in photoshop mouse = Mouse(win) mouse_click_clock = Clock() # The game starts now by drawing the target at a random location: move_target_at_random_pos(target) while True: target.draw() win.flip() # since I am still to develop the game, I give myself the option to stop it # at any time by pressing 'q' (avoiding the otherwise infinite loop) keys_pressed = getKeys() if 'q' in keys_pressed: break
def main(): # I set up my siplay size and background colour DISPSIZE = (1400, 800) BGC = (-1, -1, -1) # for my game I need to create some variables: score = 0 lives = 3 level = 1 mouse_x = 0 mouse_y = 0 # I create some objects: win = Window(size=DISPSIZE, units='pix', fullscr=False, color=BGC) mouse = Mouse(win) target = ImageStim(win, 'target.png', size=(420, 420)) # I will display three text stimuli to the player while playing the game: lives_count = TextStim( win, text=f'Lives = {lives}', height=35, color=(1, 0.2, 0.6), pos=(100, 330), ) score_count = TextStim(win, text=f'Score = {score}', height=35, color=(0.2, 0.2, 0.8), pos=(450, 330)) level_count = TextStim(win, text=f'Level = {level}', height=35, color=(1, -0.5, 1), pos=(850, 330)) # I define the messages to show the player the outcome of the game: you_have_lost = TextStim( win, text='Boo! Not a great game, pal... Get it together!', height=35, color=(0.2, 0.2, 0.8), pos=(250, 230)) you_have_won = TextStim(win, text='Yey! Well done, champ! Time to celebrate!', height=35, color=(0.2, 0.2, 0.8), pos=(250, 230)) # These are the images I use for the winning and loosing scenarios: looser = ImageStim(win, 'failed.jpg', pos=(0, -100), size=(420, 420)) winner = ImageStim(win, 'tiny_trash.jpg', pos=(0, -100), size=(420, 420)) # I introduce this dialog to save the user's ID: user_id_dialog = gui.Dlg(title="Target Game") user_id_dialog.addText('Please write your subject ID: a 4-digit code') user_id_dialog.addField('Subject ID:') ok_data = user_id_dialog.show() # show dialog and wait for OK or Cancel if not user_id_dialog.OK: print('user cancelled') # NOW THE GAME WILL START: # If enabled, intro will play: enable_intro = True if enable_intro: show_intro(win) # We create this list to save our results into target_hits_per_level = [ [], [], [], [], ] move_target_at_random_pos( target) # first the target is shown on the screen lives_timer = CountdownTimer( 5) # Level 1 starts with 5 sec to hit the target mouse_click_clock = Clock() reaction_time_clock = Clock() change_target = False while level < 4 and lives > 0: target.draw() target_x, target_y = target.pos lives_count.draw() score_count.draw() level_count.draw() win.flip() keys_pressed = getKeys() if 'q' in keys_pressed: break mouse_is_pressed = mouse.getPressed()[0] == True mouse_x, mouse_y = mouse.getPos() level_count.setText(f'Level = {level}') #if the player does not click, the target moves and the player looses a life if lives_timer.getTime() <= 0: lives -= 1 lives_count.setText(f'Lives = {lives}') mouse_in_target = None mouse_in_target_x = None mouse_in_target_y = None change_target = True # Check for a mouse click every 0.2s, so that we don't accept more than 1 # press on mouse hold if mouse_is_pressed and mouse_click_clock.getTime() > 0.2: mouse_click_clock.reset() change_target = True if mouse_clicked_in_target(mouse, target): mouse_in_target = True mouse_in_target_x = mouse_x - target_x mouse_in_target_y = mouse_y - target_y score += 1 score_count.setText(f'Score = {score}') else: lives -= 1 lives_count.setText(f'Lives = {lives}') mouse_in_target = False mouse_in_target_x = None mouse_in_target_y = None if change_target: mouse_click = { 'mouse_x': mouse_in_target_x, 'mouse_y': mouse_in_target_y, 'reaction_time': reaction_time_clock.getTime(), 'mouse_in_target': mouse_in_target, } target_hits_per_level[level - 1].append( mouse_click) # inddexes start from 0 --> level - 1 if score == 5: lives_timer.reset(3) level = 2 elif score == 10: lives_timer.reset(1) level = 3 elif score == 15: level = 4 move_target_at_random_pos(target) lives_timer.reset() reaction_time_clock.reset() change_target = False # Here we display the outcome of the game: if level == 4: you_have_won.draw() winner.draw() else: you_have_lost.draw() looser.draw() win.flip() wait(3) # Finally, we draw the overwivew for thr player draw_overview_target( win=win, level=1, target_pos=(-450, 0), text_pos=(50, 300), mouse_clicks_all_levels=target_hits_per_level, ) draw_overview_target( win=win, level=2, target_pos=(0, 0), text_pos=(450, 300), mouse_clicks_all_levels=target_hits_per_level, ) draw_overview_target( win=win, level=3, target_pos=(450, 0), text_pos=(850, 300), mouse_clicks_all_levels=target_hits_per_level, ) win.flip() wait(4) # The user has not clicked Cancel on the subject ID window if ok_data is not None: write_results(target_hits_per_level, 'results-' + ok_data[0] + '.csv') win.close()