def __init__(self, context, shader): self.t = 0 self.blue_cir = Circle(context, shader, fill_color=(9 / 255, 44 / 255, 92 / 255, 180 / 255), is_outlined=False) self.blue_cir.scale.xy = 0.08 self.blue_cir.rotation = 180 self.blue_cir.position.y = 0.3 self.white_cir = Circle(context, shader, fill_color=(1, 1, 1, 180 / 255), is_outlined=False) self.white_cir.scale.xy = 0.08 self.white_cir.position.y = 0.3 self.alpha = 180 / 255
class LoadingCircs(object): def __init__(self, context, shader): self.t = 0 self.blue_cir = Circle(context, shader, fill_color=(9 / 255, 44 / 255, 92 / 255, 180 / 255), is_outlined=False) self.blue_cir.scale.xy = 0.08 self.blue_cir.rotation = 180 self.blue_cir.position.y = 0.3 self.white_cir = Circle(context, shader, fill_color=(1, 1, 1, 180 / 255), is_outlined=False) self.white_cir.scale.xy = 0.08 self.white_cir.position.y = 0.3 self.alpha = 180 / 255 def draw(self, camera): self.t += 1 / 60 self.blue_cir.scale.x = sin(self.t * .65) / 12 self.blue_cir.scale.y = cos(self.t * .4) / 12 self.white_cir.scale.x = cos(self.t * 1.1) / 11 self.white_cir.scale.y = sin(self.t * 0.55) / 13 self.blue_cir.rotation -= 0.8 self.white_cir.rotation += 0.5 self.white_cir.draw(camera) self.blue_cir.draw(camera) @property def alpha(self): return self.white_cir.fill_color.w @alpha.setter def alpha(self, val): self.white_cir.fill_color.w = val self.blue_cir.fill_color.w = val
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, num=4, position=(0, 0), scale=(1, 1)): flat_shader = FlatShader(win.context) self.counter = 0 self.num = num self.circs = [] # for i in range(num): self.circs.append( Circle(win.context, flat_shader, is_outlined=False)) self.position = Vector2f(position) self.scale = Vector2f(scale) self.reset_pos() self.reset()
if __name__ == '__main__': from pkg_resources import resource_filename import moderngl as mgl from gonogo.visuals.window import ExpWindow as Win from mglg.graphics.shaders import FlatShader from mglg.graphics.shape2d import Circle from mglg.graphics.camera import Camera from gonogo.visuals.projection import height_ortho win = Win() ortho = height_ortho(win.width, win.height) cam = Camera(projection=ortho) flt = FlatShader(win.context) cir = Circle(win.context, flt, scale=(0.5, 0.5), is_filled=False) xx = IntroDlg(win._win, recipe_dir='', font=resource_filename('gonogo', 'resources/fonts/UbuntuMono-R.ttf')) dr = False while not dr: cir.draw(cam) dr, txt = xx.update() #xx.alpha -= win.dt/10 xx.draw() win.flip() print(txt)
def __init__(self, win, block_handler, device, settings, number=1, total=10): white = {'en': 'white', 'es': 'blanco'} black = {'en': 'black', 'es': 'negro'} go_color = block_handler.text_dict['no_go_colors'][1] no_color = block_handler.text_dict['no_go_colors'][0] if go_color == 1: col1 = white col2 = black else: col1 = black col2 = white self.is2 = self.instruction_text.copy() self.instruction_text['en'] = self.instruction_text['en'] % ( col1['en'], col2['en']) self.instruction_text['es'] = self.instruction_text['es'] % ( col1['es'], col2['es']) super().__init__(win, device, settings, number, total) self.instruction_text['en'] = self.is2['en'] self.instruction_text['es'] = self.is2['es'] # 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, ...) self.ball = Circle(win.context, flat_shader, fill_color=(1, 1, 1, 1), scale=(0.1, 0.1), position=(0, 0)) self.hline = Circle(win.context, flat_shader, is_outlined=False, fill_color=(0.4, 0.4, 0.4, 1), scale=(2, 0.005), position=(0, -0.3)) # DrawableGroups clean up the main loop & can be used to # cluster drawables together that use the same shader (which # improves perf) self.dg = DrawableGroup([self.hline, self.ball]) # animations self.player = Player(repeats=inf) # ball trajectory (y) ball_traj_y = [(0, 0.4), (0.3, 0.4), (1, -0.3), (1.3, -0.3), (1.301, 0.4), (1.6, 0.4), (1.9, 0.4), (2.6, -0.3), (2.9, -0.6), (2.901, 0.4)] ball_traj_y = Track(ball_traj_y) self.player.add(ball_traj_y, 'y', self.ball.position) # ball color ball_traj_x = [(0, go_color), (0.65, go_color), (1.301, no_color), (2.25, no_color)] ball_traj_x = Track(ball_traj_x, interpolator=select) self.player.add(ball_traj_x, 'rgb', self.ball.fill_color) # 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), (1.6, orig_y), (1.75, orig_y / 3), (1.9, 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), (1.6, original_gray), (2.5, original_gray), (2.6, original_gray), (2.8, 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())
from mglg.graphics.shape2d import Circle from mglg.graphics.win import Win from toon_rawinput.mouse import Mouse from toon.input import MpDevice from timeit import default_timer if __name__ == '__main__': win = Win(vsync=1, screen=0) height = win.height cir = Circle(win, scale=0.1, fill_color=(0.2, 0.9, 0.7, 1)) cl = Circle(win, scale=0.025, fill_color=(1, 1, 1, 1)) cr = Circle(win, scale=0.025, fill_color=(0, 0, 0, 1)) dev = MpDevice(Mouse()) with dev: t0 = default_timer() t1 = t0 + 30 while t1 > default_timer(): res = dev.read() if res: time, data = res left = data[data['id'] == 0] right = data[data['id'] == 1] if left.shape[0] > 0: cir.position.x += float(sum(left['dy'])) / win.height cl.position.x += float(sum(left['dx'])) / win.height
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), is_outlined=False, scale=(0.12, 0.10),
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, 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))