def test_extras(): pp.init((800, 600)) el = pp.EventListener() arr = np.arange(1, 101).reshape(10, 10) pp.display( pp.compose(pp.empty_surface(0))(pp.Surface(scale=1)( pp.mat_to_surface(arr)))) el.wait_for_seconds(1) pp.display( pp.compose(pp.empty_surface(0))(pp.Surface(scale=1)(pp.mat_to_surface( arr, pp.apply_color_map("autumn"))))) el.wait_for_seconds(1) _test_transparency_mask() el.wait_for_seconds(1) _test_transparency_colorkey() el.wait_for_seconds(1)
def _test_transparency_mask(): mask = np.ones((100, 100), dtype=bool) mask[:, :50] = 0 img = pp.mat_to_surface(np.random.randint(0, 255, (100, 100))) pp.display( pp.compose(pp.empty_surface(0))(pp.make_transparent_by_mask(img, mask)))
def render_trial_screen(word, font_color, target): return compose(_bg(), LinLayout("v"))( # Create the Text text("Which color is named by the letters?" if target == "text" else "What's the color of the word?"), # Create the stimulus, and scale it down a little. Padding.from_scale(0.3)(text(word, font_color)), LLItem(1))
def display_intro(el: EventListener): # the first argument for slide_show must be an iterable of pygame.Surface # to create it we render the text onto an empty surface with the map() # function. slide_show displays one slide, and then calls the function that # is passed to it as second argument. When this function returns, the next # slide is displayed and the function is called again. The function that is # passed simply waits for the return key slides = map(lambda s: compose(_bg())(text(s)), intro_text) slide_show(slides, lambda: el.wait_for_keys(pygame.K_RETURN))
def render_train_screen(show_mapping, stim_type, target_color): # the contents are aranged in a vertical layout, topmost is the # title "target color", followed by the stim for training (either a # square containing the color, or the word naming the color) # in the Bottom there is the information which key is mapped to which # color. But its only displayed optionally return compose(_bg(), LinLayout("v"))( # Create the Text text("target color:"), # Create the stimulus, and scale it down a little. Padding.from_scale(0.3)(make_train_stim(stim_type, target_color)), # Up till here the content is static, but displaying the mapping is optionally # and depends on the parameter, therefore we either add the mapping, or # an LLItem(1) as placeholder make_color_mapping() if show_mapping else LLItem(1))
def display_text(text, bg_color): pp.display( pp.compose(pp.empty_surface(bg_color))(pp.Text(text, pp.Font(size=60), color=pp.rgba(white))))
def display_text(s: str): display(compose(_bg())(text(s)))
def _test_transparency_colorkey(): tra_img = pp.compose(pp.empty_surface(0))(pp.empty_surface(20, (200, 200))) tra_img = pp.make_transparent_by_colorkey(tra_img, 20) pp.display(pp.compose(pp.empty_surface(0xFF0000))(tra_img))