Note
Go to the end to download the full example code.
Experiment drawing methods#
expyfun provides multiple methods for drawing simple screen objects.

exp_name: test
date: 2025-02-10 22_39_19.754449
file: /home/circleci/project/examples/experiments/drawing_methods.py
participant: 2
session: 1
2025-02-10 22:39:19,754 - INFO - Expyfun: Using version 2.0.0.dev0 (requested dev)
2025-02-10 22:39:19,755 - INFO - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2025-02-10 22:39:19,952 - 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.
2025-02-10 22:39:19,952 - INFO - Expyfun: Setting up screen
2025-02-10 22:39:19,982 - EXP - Expyfun: Set screen visibility True
2025-02-10 22:39:19,991 - INFO - Initialized [600 600] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f4cbe5af430>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2025-02-10 22:39:19,991 - INFO - Expyfun: Initializing dummy triggering mode
2025-02-10 22:39:19,992 - INFO - Expyfun: Initialization complete
2025-02-10 22:39:19,993 - EXP - Expyfun: Participant: 2
2025-02-10 22:39:19,993 - EXP - Expyfun: Session: 1
2025-02-10 22:39:20,597 - INFO - Expyfun: Exiting
2025-02-10 22:39:20,602 - 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.894 seconds)