stimuli.visuals.FillingBar

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

Class to display a centered bar that can fill/unfill along a given axis.

The filling process starts from the center of the bar and fills both sides simultaneously.

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 used for the bar background in BGR color space.

fill_color

Color used to fill the bar in BGR color space.

fill_perc

Length filled in percent between 0 and 1.

img

Image array.

length

Length of the bar in pixel.

margin

Margin in pixel between the bar and its filled content.

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, margin, color, fill_color)

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, margin, color, fill_color, fill_perc=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.

marginint

Margin in pixel between the filling bar and the containing bar. The containing bar (length x width) is set as (length+margin, width+margin).

colorstr | tuple

Color used to draw the bar background.

fill_colorstr | tuple

Color used to fill the bar.

fill_percfloat

Percentage between 0 and 1 of bar filling.

  • 0: not filled

  • 1: fully filled

As the bar fills on both side simultaneously, the percentage filled is length//2 * fill_perc.

axisint | str

Axis along which the bar is moving:

  • 0 | 'vertical' | 'v' - vertical bar

  • 1 | 'horizontal' | 'h' - horizontal bar

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: Vertical bar filling along the vertical axis.

  • 1: Horizontal bar filling along the horizontal axis.

property background

Background color in BGR color space.

property color

Color used for the bar background in BGR color space.

property fill_color

Color used to fill the bar in BGR color space.

property fill_perc

Length filled in percent between 0 and 1.

property img

Image array.

property length

Length of the bar in pixel.

property margin

Margin in pixel between the bar and its filled content.

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).