Experiment drawing methods#

expyfun provides multiple methods for drawing simple screen objects.

drawing methods
exp_name: test
date: 2024-07-22 22_14_44.513616
file: /home/circleci/project/examples/experiments/drawing_methods.py
participant: 2
session: 1
2024-07-22 22:14:44,513 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2024-07-22 22:14:44,514 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2024-07-22 22:14:44,690 - WARNING - Expyfun: Mismatch between reported stim sample rate (24414) and device sample rate (44100.0). Experiment Controller will resample for you, but this takes a non-trivial amount of processing time and may compromise your experimental timing and/or cause artifacts.
2024-07-22 22:14:44,690 - INFO    - Expyfun: Setting up screen
2024-07-22 22:14:44,719 - EXP     - Expyfun: Set screen visibility True
2024-07-22 22:14:44,727 - INFO    - Initialized [600 600] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f019f79fd90>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2024-07-22 22:14:44,728 - INFO    - Expyfun: Initializing dummy triggering mode
2024-07-22 22:14:44,729 - INFO    - Expyfun: Initialization complete
2024-07-22 22:14:44,729 - EXP     - Expyfun: Participant: 2
2024-07-22 22:14:44,729 - EXP     - Expyfun: Session: 1
2024-07-22 22:14:45,316 - INFO    - Expyfun: Exiting
2024-07-22 22:14:45,320 - EXP     - Expyfun: Audio stopped and reset.

# Author: Eric Larson <larsoner@uw.edu>
#
# License: BSD (3-clause)

import numpy as np

import expyfun.analyze as ea
from expyfun import ExperimentController, visual

print(__doc__)


with ExperimentController(
    "test",
    session="1",
    participant="2",
    full_screen=False,
    window_size=[600, 600],
    output_dir=None,
    version="dev",
) as ec:
    ec.screen_text("hello")

    # make an image with  alpha the x-dimension (columns), RGB upward
    img_buffer = np.zeros((120, 100, 4))
    img_buffer[:, :50, 3] = 1.0
    img_buffer[:, 50:, 3] = 0.5
    img_buffer[0] = 1
    for ii in range(3):
        img_buffer[ii * 40 : (ii + 1) * 40, :, ii] = 1.0
    img = visual.RawImage(ec, img_buffer, scale=2.0)

    # make a line, rectangle, diamond, and circle
    line = visual.Line(
        ec,
        [[-2, 2, 2, -2], [-2, 2, -2, -2]],
        units="deg",
        line_color="w",
        line_width=2.0,
    )
    rect = visual.Rectangle(ec, [0, 0, 2, 2], units="deg", fill_color="y")
    diamond = visual.Diamond(
        ec,
        [0, 0, 4, 4],
        units="deg",
        fill_color=None,
        line_color="gray",
        line_width=2.0,
    )
    circle = visual.Circle(
        ec, 1, units="deg", line_color="w", fill_color="k", line_width=2.0
    )

    # do the drawing, then flip
    for obj in [img, line, rect, diamond, circle]:
        obj.draw()

    screenshot = ec.screenshot()  # must be called *before* the flip
    ec.flip()
    ec.wait_for_presses(0.5)

ea.plot_screen(screenshot)

Total running time of the script: (0 minutes 0.853 seconds)

Gallery generated by Sphinx-Gallery