def __init__(self, win, recipe_dir=None, can_rush=False): self._imrender = ProgrammablePygletRenderer(win._win) ubuntu_font = resource_filename('gonogo', 'resources/fonts/UbuntuMono-R.ttf') self.intro_dlg = IntroDlg(self._imrender, (win.width, win.height), recipe_dir=recipe_dir, font=ubuntu_font) flat = FlatShader(win.context) self.loading = LoadingCircs(win.context, flat) self.win = win self.can_rush = can_rush text_shader = TextShader(win.context) font = FontManager.get(ubuntu_font, size=64) self.no_rush = Text2D(win.context, text_shader, win.width, win.height, 'Run as administrator for better performance.', font, scale=0.03, position=(0, -0.45), color=(0.9, 0.2, 0.2, 1)) self.no_device = Text2D( win.context, text_shader, win.width, win.height, 'Device not plugged in. Please plug in and restart.', font, scale=0.03, position=(0, -0.35), color=(0.9, 0.2, 0.2, 1)) # exit anim dlg_fade = Track([(0, 1.0), (1, 0.0)]) load_fade = Track([(0, 180 / 255), (1, 0.0)]) light_screen = Track([(0, 0.3), (1, 0.5)]) self.photo = Square(win.context, flat, is_outlined=False, fill_color=(1, 1, 1, 1), scale=(0.05, 0.05), position=(0.85, 0)) self.player = Player() self.player.add(dlg_fade, 'alpha', self.intro_dlg) self.player.add(load_fade, 'alpha', self.loading) self.player.add(light_screen, 'xyz', self.win.background_color) self.player_photo = Player(repeats=100000) phot_trk = Track([(0, 0), (0.5, 1), (0.5 + win.frame_period * 2, 0)], interpolator=select) self.player_photo.add(phot_trk, 'xyz', self.photo.fill_color) self.online = OnlinePlot()
def __init__(self, win, device, settings, number=1, total=10): self.win = win self.device = device default_lang = settings['spanish'] self.default_lang = default_lang self.it2 = self.instruction_text[default_lang] flat = FlatShader(self.win.context) self.fade_sqr = Square(win.context, flat, is_outlined=False, fill_color=win._background_color, scale=(2, 2)) self.fade_sqr.fill_color.a = 1 image_shader = ImageShader(win.context) self.preview_surface = RenderSurface2D(win.context, image_shader, scale=(1, 3/5), position=(1/4, 1/6-0.03), clear_color=(0.3, 0.3, 0.3, 1)) text_shader = TextShader(win.context) title_path = resource_filename('gonogo', 'resources/fonts/Baloo-Regular.ttf') title_font = FontManager.get(title_path, size=64) instr_path = resource_filename('gonogo', 'resources/fonts/UbuntuMono-R.ttf') instr_font = FontManager.get(instr_path, size=64) self.render_title = Text2D(win.context, text_shader, win.width, win.height, self.title, title_font, scale=(0.05, 0.05), position=(-0.45, 1/6-0.03)) if type(device.device).__name__ == 'Keyboard': keys = [x.upper() for x in device.device.keys] elif type(device.device).__name__ == 'Custom': keys = ['\u2190', '\u2192'] self.mock_keys = MockButtons(win, keys=keys) start_txt = {'en': 'Press either key to start.', 'es': 'Pulse cualquiera las dos teclas para comenzar.'} self.render_start = Text2D(win.context, text_shader, win.width, win.height, start_txt[default_lang], instr_font, color=(0.1, 0.9, 0.2, 0.8), scale=(0.05, 0.05), position=(0, 0.1)) self.start_text_bg = Square(win.context, flat, is_outlined=False, fill_color=(0.1, 0.1, 0.1, 0.8), scale=(2, 0.06), position=(0, 0.1)) # imgui stuff self.imgui_renderer = ProgrammablePygletRenderer(win._win) fnt = self.imgui_renderer.io.fonts self.imgui_font = fnt.add_font_from_file_ttf(instr_path, 26, fnt.get_glyph_ranges_latin()) self.imgui_renderer.refresh_font_texture() self.flags = WINDOW_NO_RESIZE | WINDOW_NO_MOVE | WINDOW_NO_COLLAPSE self.imgui_dims = int(4/3*win.height), int(1/4 * win.height) self.imgui_pos = win.width//7, int((win.height/2) + self.imgui_dims[1] * 4/5) self.t0 = default_timer() self.can_finish = False self.fade_in = True self.fade_out = False self.num = number self.tot = total
class Test(BaseInstruction): title = 'FooBar' instruction_text = {'en': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.', 'es': 'Lorem ipsum dolor sit amet, elit adipiscing del consectetur, tempor sed y vitalidad, por lo que el trabajo y dolor, algunas cosas importantes que hacer eiusmod. Con los años, entraré, que nostrud aliquip fuera de ella la ventaja de ejercicio, por lo que los esfuerzos de estímulo si el distrito escolar y la longevidad.'} def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) flat = FlatShader(self.win.context) self.sqr = Square(self.win.context, flat, scale=(0.1, 0.1), rotation=30) def preview_draw(self, cam): self.sqr.rotation += 4 self.sqr.draw(cam)
def __init__(self, win, keys=['K', 'L']): flat_shader = FlatShader(win.context) text_shader = TextShader(win.context) # base self.subbase = Square(win.context, flat_shader, fill_color=(1, 1, 1, 1), is_outlined=False, position=(0.54, -0.26), scale=(0.42, 0.22)) self.base = Square(win.context, flat_shader, fill_color=(0.1, 0.1, 0.3, 1), outline_color=(1, 1, 1, 1), position=(0.54, -0.26), scale=(0.4, 0.2)) # keys self.left_key = Square(win.context, flat_shader, fill_color=(0.4, 0.4, 0.4, 1), outline_color=(1, 1, 1, 1), position=(0.44, -0.26), scale=(0.15, 0.15), is_outlined=False) self.right_key = Square(win.context, flat_shader, fill_color=(0.4, 0.4, 0.4, 1), outline_color=(1, 1, 1, 1), position=(0.64, -0.26), scale=(0.15, 0.15), is_outlined=False) text_path = resource_filename('gonogo', 'resources/fonts/FreeSans.ttf') font = FontManager.get(text_path, size=128) self.left_txt = Text2D(win.context, text_shader, win.width, win.height, keys[0], font, scale=(0.06, 0.06), position=(0.44, -0.26)) self.right_txt = Text2D(win.context, text_shader, win.width, win.height, keys[1], font, scale=(0.06, 0.06), position=(0.64, -0.26))
def __init__(self, win, block_handler, device, user_settings): super().__init__(win, block_handler, device, user_settings) flat_shader = FlatShader(win.context) # self.ball.fill_color = gray # hline position is determined by user_settings self.hline = Square(win.context, flat_shader, is_outlined=False, fill_color=(0.9, 0.9, 0.9, 1), scale=(2, 0.004)) self.flats.insert(0, self.hline)
def __init__(self, win, block_handler, device, settings, number=1, total=10): super().__init__(win, device, settings, number, total) # visuals flat_shader = FlatShader(win.context) # scales & things are approximate, the exact ones are calculated # trial-by-trial and depend on various settings (timing tolerance, # initial position, ...) ball_color = block_handler.text_dict['ball_color'] self.ball = Circle(win.context, flat_shader, fill_color=(ball_color, ball_color, ball_color, 1), scale=(0.1, 0.1), position=(0, 0)) self.hline = Square(win.context, flat_shader, is_outlined=False, fill_color=(0.4, 0.4, 0.4, 1), scale=(2, 0.005), position=(0, -0.3)) self.dg = DrawableGroup([self.hline, self.ball]) self.player = Player(repeats=inf) ball_traj = Track([(0, 0.4), (0.3, 0.4), (1, -0.3), (1.3, -0.3)]) self.player.add(ball_traj, 'y', self.ball.position) # ball squish # TODO: why doesn't y behave well for scaling? orig_y = float(self.ball.scale.y) ball_windup = [(0, orig_y), (0.15, orig_y / 3), (0.3, orig_y)] ball_windup = Track(ball_windup) self.player.add(ball_windup, 'y', self.ball.scale) # key animation original_gray = self.mock_keys.left_key.fill_color.g key_green = [(0, original_gray), (0.9, original_gray), (1, 0.9), (1.2, original_gray)] left_green = Track(key_green, easing=smootherstep) self.player.add(left_green, 'g', self.mock_keys.left_key.fill_color) self.player.start(default_timer())
def __init__(self, win, block_handler, device, user_settings): super().__init__(win, block_handler, device, user_settings) flat_shader = FlatShader(win.context) # hline position is determined by user_settings self.hline = Square(win.context, flat_shader, is_outlined=False, fill_color=(0.9, 0.9, 0.9, 1), scale=(2, 0.004)) self.traffic = Traffic(win, num=self.block_handler. trial_by_trial_settings['t_max'].consecutive) self.flats.insert(0, self.hline) self.flats.insert(0, self.traffic)
# import gamemode as gm # figure out if we're a script or exe if getattr(sys, 'frozen', False): application_path = os.path.dirname(sys.executable) elif __file__: application_path = os.path.dirname(__file__) else: raise ValueError( 'No idea if this is running as a script or under pyinstaller!') if __name__ == '__main__': win = Win(vsync=1, screen=0) win.ctx.line_width = 3.0 sqr = Square(win, scale=(0.15, 0.1), fill_color=(0.7, 0.9, 0.2, 1), rotation=45) circle = Circle(win, scale=(0.15, 0.1), fill_color=(0.2, 0.9, 0.7, 1)) mouse_cir = Circle(win, scale=0.05, fill_color=1) arrow = Arrow(win, scale=(0.15, 0.1), fill_color=(0.9, 0.7, 0.2, 1)) circle.position.x += 0.2 arrow.position.x -= 0.2 sqr2 = Square(win, scale=(0.05, 0.05), fill_color=(0.1, 0.1, 0.1, 0.6)) poly = Polygon(win, segments=7, scale=(0.08, 0.08), position=(-0.2, -0.2), fill_color=(0.9, 0.2, 0.2, 0.5), outline_color=(0.1, 0.1, 0.1, 1)) crs = Cross(win, fill_color=(0.2, 0.1, 0.9, 0.7),
@property def color(self): return self._color @color.setter def color(self, color): if isinstance(color, Vector4f): self._color = color else: self._color[:] = color if __name__ == '__main__': from mglg.graphics.shaders import FlatShader, VertexColorShader from mglg.graphics.shape2d import Square from gonogo.visuals.window import ExpWindow as Win win = Win() flat = FlatShader(win.context) vcs = VertexColorShader(win.context) # don't touch scale arc4 = ThickDivArc(win.context, vcs, radius=0.9, angle=90) sqr = Square(win.context, flat, scale=(0.0005, 2)) sqr2 = Square(win.context, flat, scale=(2, 0.0005)) for i in range(180): #arc4.angle += 1 sqr.draw(win.cam) sqr2.draw(win.cam) arc4.draw(win.cam) win.flip()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) flat = FlatShader(self.win.context) self.sqr = Square(self.win.context, flat, scale=(0.1, 0.1), rotation=30)
class BaseInstruction(metaclass=ABCMeta): @property @abstractmethod def title(self): # just some brief string, e.g. "Left/Right" pass @property @abstractmethod def instruction_text(self): # for supported langs: # {'en': 'Hello', 'es': 'Hola'} pass def __init__(self, win, device, settings, number=1, total=10): self.win = win self.device = device default_lang = settings['spanish'] self.default_lang = default_lang self.it2 = self.instruction_text[default_lang] flat = FlatShader(self.win.context) self.fade_sqr = Square(win.context, flat, is_outlined=False, fill_color=win._background_color, scale=(2, 2)) self.fade_sqr.fill_color.a = 1 image_shader = ImageShader(win.context) self.preview_surface = RenderSurface2D(win.context, image_shader, scale=(1, 3/5), position=(1/4, 1/6-0.03), clear_color=(0.3, 0.3, 0.3, 1)) text_shader = TextShader(win.context) title_path = resource_filename('gonogo', 'resources/fonts/Baloo-Regular.ttf') title_font = FontManager.get(title_path, size=64) instr_path = resource_filename('gonogo', 'resources/fonts/UbuntuMono-R.ttf') instr_font = FontManager.get(instr_path, size=64) self.render_title = Text2D(win.context, text_shader, win.width, win.height, self.title, title_font, scale=(0.05, 0.05), position=(-0.45, 1/6-0.03)) if type(device.device).__name__ == 'Keyboard': keys = [x.upper() for x in device.device.keys] elif type(device.device).__name__ == 'Custom': keys = ['\u2190', '\u2192'] self.mock_keys = MockButtons(win, keys=keys) start_txt = {'en': 'Press either key to start.', 'es': 'Pulse cualquiera las dos teclas para comenzar.'} self.render_start = Text2D(win.context, text_shader, win.width, win.height, start_txt[default_lang], instr_font, color=(0.1, 0.9, 0.2, 0.8), scale=(0.05, 0.05), position=(0, 0.1)) self.start_text_bg = Square(win.context, flat, is_outlined=False, fill_color=(0.1, 0.1, 0.1, 0.8), scale=(2, 0.06), position=(0, 0.1)) # imgui stuff self.imgui_renderer = ProgrammablePygletRenderer(win._win) fnt = self.imgui_renderer.io.fonts self.imgui_font = fnt.add_font_from_file_ttf(instr_path, 26, fnt.get_glyph_ranges_latin()) self.imgui_renderer.refresh_font_texture() self.flags = WINDOW_NO_RESIZE | WINDOW_NO_MOVE | WINDOW_NO_COLLAPSE self.imgui_dims = int(4/3*win.height), int(1/4 * win.height) self.imgui_pos = win.width//7, int((win.height/2) + self.imgui_dims[1] * 4/5) self.t0 = default_timer() self.can_finish = False self.fade_in = True self.fade_out = False self.num = number self.tot = total def draw(self, data): # render to texture time = default_timer() - self.t0 with self.preview_surface: self.preview_draw(self.preview_surface.cam) # start flashing message & allow input if time > 3.14: self.can_finish = True self.render_start.color.a = sin(time*3)/2 + 0.85 self.start_text_bg.draw(self.preview_surface.cam) self.render_start.draw(self.preview_surface.cam) self.mock_keys.draw(self.preview_surface.cam) self.preview_surface.draw(self.win.cam) self.render_title.draw(self.win.cam) # imgui window imgui.new_frame() imgui.push_font(self.imgui_font) imgui.set_next_window_size(*self.imgui_dims) imgui.set_next_window_position(*self.imgui_pos) title = {'en': 'Instructions', 'es': 'Instrucciones'} imgui.begin(title[self.default_lang], False, flags=self.flags) imgui.push_text_wrap_pos(1000) imgui.text(self.it2) imgui.pop_text_wrap_pos() imgui.end() imgui.set_next_window_position(100, 100) imgui.set_next_window_size(180, 50) imgui.begin('##blockcount', flags=self.flags | WINDOW_NO_TITLE_BAR) rnd = {'en': 'Round', 'es': 'La ronda'} imgui.text('%s %s/%s' % (rnd[self.default_lang], self.num, self.tot)) imgui.end() imgui.pop_font() imgui.render() self.imgui_renderer.render(imgui.get_draw_data()) # fade in effect if self.fade_in: self.fade_sqr.fill_color.a -= 0.05 if self.fade_sqr.fill_color.a <= 0: self.fade_in = False self.fade_sqr.draw(self.win.cam) if self.fade_out: self.fade_sqr.fill_color.a += 0.05 self.fade_sqr.draw(self.win.cam) if self.fade_sqr.fill_color.a >= 1: return True if data and self.can_finish: self.fade_out = True return False def preview_draw(self, cam): pass def run(self): self.t0 = default_timer() done = False kbd = self.device win = self.win any_pressed = False with kbd as dev: while not done: data = dev.read() if data.any(): if type(dev.device).__name__ == 'Custom': any_pressed = (data.buttons > 0).any() else: any_pressed = any(data.press) else: data = None done = self.draw(any_pressed) win.flip()
from mglg.graphics.stipple2d import StippleArrow from mglg.graphics.text2d import FontManager, Text2D win = Win() ortho = height_ortho(win.width, win.height) context = mgl.create_context(330) context.line_width = 3.0 prog = FlatShader(context) img_prog = ImageShader(context) part_prog = ParticleShader(context) stip_prog = StippleShader(context) text_prog = TextShader(context) sqr = Square(context, prog, scale=(0.15, 0.1), fill_color=(0.7, 0.9, 0.2, 1), rotation=45) circle = Circle(context, prog, scale=(0.15, 0.1), fill_color=(0.2, 0.9, 0.7, 1)) arrow = Arrow(context, prog, scale=(0.15, 0.1), fill_color=(0.9, 0.7, 0.2, 1)) circle.position.x += 0.2 arrow.position.x -= 0.2 sqr2 = Square(context, prog, scale=(0.05, 0.05), fill_color=(0.1, 0.1, 0.1, 0.6)) poly = Polygon(context, prog,
class Loading(object): def __init__(self, win, recipe_dir=None, can_rush=False): self._imrender = ProgrammablePygletRenderer(win._win) ubuntu_font = resource_filename('gonogo', 'resources/fonts/UbuntuMono-R.ttf') self.intro_dlg = IntroDlg(self._imrender, (win.width, win.height), recipe_dir=recipe_dir, font=ubuntu_font) flat = FlatShader(win.context) self.loading = LoadingCircs(win.context, flat) self.win = win self.can_rush = can_rush text_shader = TextShader(win.context) font = FontManager.get(ubuntu_font, size=64) self.no_rush = Text2D(win.context, text_shader, win.width, win.height, 'Run as administrator for better performance.', font, scale=0.03, position=(0, -0.45), color=(0.9, 0.2, 0.2, 1)) self.no_device = Text2D( win.context, text_shader, win.width, win.height, 'Device not plugged in. Please plug in and restart.', font, scale=0.03, position=(0, -0.35), color=(0.9, 0.2, 0.2, 1)) # exit anim dlg_fade = Track([(0, 1.0), (1, 0.0)]) load_fade = Track([(0, 180 / 255), (1, 0.0)]) light_screen = Track([(0, 0.3), (1, 0.5)]) self.photo = Square(win.context, flat, is_outlined=False, fill_color=(1, 1, 1, 1), scale=(0.05, 0.05), position=(0.85, 0)) self.player = Player() self.player.add(dlg_fade, 'alpha', self.intro_dlg) self.player.add(load_fade, 'alpha', self.loading) self.player.add(light_screen, 'xyz', self.win.background_color) self.player_photo = Player(repeats=100000) phot_trk = Track([(0, 0), (0.5, 1), (0.5 + win.frame_period * 2, 0)], interpolator=select) self.player_photo.add(phot_trk, 'xyz', self.photo.fill_color) self.online = OnlinePlot() def run(self, device, device_type): # loop until response done = False with device: self.player_photo.start(self.win.current_time) while not done: imgui.new_frame() if not self.can_rush: self.no_rush.draw(self.win.cam) if device_type != 'custom': self.no_device.draw(self.win.cam) else: # draw online thing data = device.read() self.online.update(data) self.loading.draw(self.win.cam) done, sets = self.intro_dlg.update() self.player_photo.advance(self.win.current_time) self.photo.draw(self.win.cam) imgui.render() self._imrender.render(imgui.get_draw_data()) self.win.flip() # self.player.start(self.win.current_time) while self.player.is_playing: imgui.new_frame() self.player.advance(self.win.current_time) self.player_photo.advance(self.win.current_time) self.loading.draw(self.win.cam) d, s = self.intro_dlg.update() imgui.render() self._imrender.render(imgui.get_draw_data()) self.win.flip() return sets