stimuli.visuals.MovingBar

class stimuli.visuals.MovingBar(window_name='Visual', window_size=None)

Class to display a centered moving bar along an axis.

Parameters:
window_namestr

Name of the window in which the visual is displayed.

window_sizetuple | None

Either None to automatically select a window size based on the available monitors, or a 2-length of positive integer sequence as (width, height) in pixels.

Attributes

axis

Axis on which the bar is moving.

background

Background color in BGR color space.

color

Color of the bar in BGR color space.

img

Image array.

length

Length of the bar in pixel.

position

Position between -1 and 1 of the bar on the given axis.

width

Width of the bar in pixel.

window_center

Window's center position.

window_name

Window's name.

window_size

Window's size (width x height).

Methods

close()

Close the visual.

draw_background(color)

Draw a uniform single color background.

putBar(length, width, color[, position, axis])

Draw the bar on top of the current visual.

show([wait])

Show the visual with cv2.imshow() and cv2.waitKey().

close()

Close the visual.

draw_background(color)

Draw a uniform single color background.

Replace all the pixels with this color, thus this method erases any prior work.

Parameters:
colorstr | tuple

Color used to draw the background.

Notes

A color is provided as matplotlib string or as (B, G, R) tuple of int8 set between 0 and 255.

putBar(length, width, color, position=0, axis=0)

Draw the bar on top of the current visual.

Parameters:
lengthint

Number of pixels used to draw the length of the bar.

widthint

Number of pixels used to draw the width of the bar.

colorstr | tuple

Color used to draw the bar.

positionfloat

Relative position of the bar along the given axis. Along the vertical axis:

  • -1: corresponds to the top of the window.

  • 1: corresponds to the bottom of the window.

Along the horizontal axis:

  • -1: corresponds to the left of the window.

  • 1: corresponds to the right of the window.

0 corresponds to the center of the window.

axisint | str

Axis along which the bar is moving:

  • 0 | 'vertical' | 'v' - horizontal bar along vertical axis.

  • 1 | 'horizontal' | 'h' - vertical bar along horizontal axis.

Notes

A color is provided as matplotlib string or as (B, G, R) tuple of int8 set between 0 and 255.

show(wait=1)

Show the visual with cv2.imshow() and cv2.waitKey().

Parameters:
waitint

Wait timer passed to cv2.waitKey() [ms].

property axis

Axis on which the bar is moving.

This property is a binary integer:
  • 0: Horizontal bar along vertical axis.

  • 1: Vertical bar along horizontal axis.

property background

Background color in BGR color space.

property color

Color of the bar in BGR color space.

property img

Image array.

property length

Length of the bar in pixel.

property position

Position between -1 and 1 of the bar on the given axis.

property width

Width of the bar in pixel.

property window_center

Window’s center position.

property window_name

Window’s name.

property window_size

Window’s size (width x height).