expyriment.stimuli.Frame

class expyriment.stimuli.Frame(size, position=None, frame_line_width=None, colour=None, anti_aliasing=None, line_width=None)

A class implementing a frame stimulus.

Methods

__init__(size, position=None, frame_line_width=None, colour=None, anti_aliasing=None, line_width=None)

Create a frame.

Parameters :

size : (int, int)

size of the frame (xy)

position : (int, int), optional

position of the stimulus

frame_line_width : int, optional

width of the frame lines

colour : (int, int, int), optional

colour of the frame

anti_aliasing : int, optional

anti aliasing parameter

Notes

DEPRECATED CLASS: Please use ‘Rectangle’ with a line_width > 0!

absolute_position

Getter for absolute_position.

add_noise(grain_size, percentage, colour)

Add visual noise on top of the stimulus.

This function might take very long for large stimuli.

Parameters :

grain_size : int

size of the grains for the noise

percentage : int

percentage of covered area

colour : (int, int, int)

colour (RGB) of the noise

Returns :

time : int

the time it took to execute this method

Notes

Depending on the size of the stimulus, this method may take some time to compute!

add_vertex(xy)

Add a vertex to the shape.

Parameters :

xy : (int, int)

vertex as tuple

add_vertices(vertex_list)

Add a list of vertices to the shape.

Parameters :

vertex_list : (int, int)

list of vertices (int, int)

anti_aliasing

Getter for anti_aliasing.

blur(level)

Blur the shape.

This blurs the stimulus, by scaling it down and up by the factor of ‘level’. Notes —– Depending on the blur level and the size of your stimulus, this method may take some time!

Parameters :

level : int

level of bluring

Returns :

time : int

the time it took to execute this method

clear_surface()

Clear the stimulus surface.

Surfaces are automatically created after any surface operation (presenting, plotting, rotating, scaling, flipping etc.) and preloading. If the stimulus was preloaded, this method unloads the stimulus. This method is functionally equivalent with unload(keep_surface=False).

Returns :

time : int

the time it took to execute this method

Notes

Depending on the size of the stimulus, this method may take some time to compute!

colour

Getter for colour.

compress()

“Compress the stimulus.

This will create a temporary file on the disk where the surface of the stimululs is written to. The surface will now be read from the disk to free memory. Compressed stimuli cannot do surface operations! Preloading comressed stimuli is possible and highly recommended. Depending on the size of the stimulus, this method may take some time to compute!

Returns :

time : int

the time it took to execute this method

convert_expyriment_xy_to_surface_xy(point_xy)

Convert a point from shape coordinates to surface coordinates.

Parameters :

point_xy : (int, int)

Expyriment screen coordinates (tuple)

copy()

Deep copy of the visual stimulus.

Returns :copy : deep copy of self

Notes

Depending on the size of the stimulus, this method may take some time to compute!

decompress()

Decompress the stimulus.

This will decompress the stimulus. The surface will now be read from memory again. Depending on the size of the stimulus, this method may take some time to compute!

Returns :

time : int

the time it took to execute this method

distance(other)

Surface center distance.

This method computes the distance between the surface center of this and another visual stimulus.

Parameters :

other : stimulus

the other visual stimulus

Returns :

dist : float

distance between surface centers

erase_vertices()

Removes all vertices.

flip(booleans)

Flip the stimulus.

This is a surface operation. After this, a surface will be present!

Parameters :

booleans : (bool, bool)

booleans to flip or not

Returns :

time : int

the time it took to execute this method

Notes

Depending on the size of the stimulus, this method may take some time to compute!

flipping

“Getter for the total native flipping.

frame_line_width

Getter for frame_line_width.

frame_size

Getter for frame_size.

has_surface

Getter for has_surface.

id

Getter for id.

inside_stimulus(stimulus, mode='visible')

Check if stimulus is inside another stimulus.

Parameters :

stimulus : expyriment stimulus

the other stimulus

mode : mode (str), optional

“visible”: based on non-transparent pixels or “rectangle”: based on pixels in pygame surface (default = visible”)

Returns :

out : bool

Notes

Depending on the size of the stimulus, this method may take some time to compute!

is_compressed

Getter for is_compressed.

is_point_inside(point_xy)

DEPRECATED METHOD: Please use ‘native_overlapping_with_position’.

is_preloaded

Getter for is_preloaded.

is_shape_overlapping(shape2)

DEPRECATED METHOD: Please use ‘overlapping_with_shape’.

logging

Getter for logging.

move(offset)

Moves the stimulus in 2D space.

When using OpenGL, this can take longer then 1ms!

Parameters :

offset : list, optional

translation along x and y axis

Returns :

time : int

the time it took to execute this method

native_flip(booleans)

Flip the shape.

Native flipping of shapes is a native operation (not a surface operation) and does therefore not go along with a quality loss. No surface will be created.

Parameters :

booleans : (bool, bool)

booleans to flip horizontally and vertically or not

native_overlapping_with_position(position)

Return True if the position is inside the shape.

Parameters position – Expyriment screen coordinates (tuple)

Returns :

val : bool

True if the position is inside the shape

native_rotate(degree)

Rotate the shape.

Native rotation of shape is a native operation (not a surface operation) and does therefore not go along with a quality loss. No surface will be created.

Parameters :

degree : int

degree to rotate counterclockwise (int)

native_scale(factors, scale_line_width=False)

Scale the shape.

Native scaling of shapes is a native operation (not a surface operation) and does therefore not go along with a quality loss. No surface will be created.

Negative scaling values will native_flip the stimulus.

Parameters :

factors : int or (int, int)

x and y factors to scale

scale_line_width : bool, optional

if True, line_width will be scaled proportionally to the change in surface size (default=False)

overlapping_with_position(position, mode='visible', use_absolute_position=True)

Check if stimulus is overlapping with a certain position.

Parameters :

position : (int, int)

position to check for overlapping

mode : mode (str), optional

“visible”: based on non-transparent pixels or “rectangle”: based on pixels in pygame surface (default = visible”)

use_absolute_position : bool, optional

use absolute_position of stimulus (default) instead of position

Returns :

overlapping : bool

Notes

Depending on the size of the stimulus, this method may take some time to compute!

overlapping_with_shape(other)

Return true if shape overlaps with other shape.

Parameters :

other : stimuli.Shape

the other shape object

Returns :

val : bool

True if overlapping

overlapping_with_stimulus(stimulus, mode='visible', use_absolute_position=True)

Check if stimulus is overlapping with another stimulus.

Parameters :

stimulus : expyriment stimulus

the other stimulus

mode : mode (str), optional

“visible”: based on non-transparent pixels or “surface”: based on pixels in pygame surface (default = visible”)

use_absolute_position : bool, optional

use absolute_position of stimuli (default) instead of position

Returns :

overlapping : bool

are stimuli overlapping or not

overlap : (int, int)

the overlap (x, y) in pixels. If mode is ‘surface’, the argument will always be None.

Notes

Depending on the size of the stimulus, this method may take some time to compute!

picture()

Return the stimulus as Picture stimulus.

This will create a temporary file on the hard disk where the image is saved to.

Notes

Depending on the size of the stimulus, this method may take some time to compute!

plot(stimulus)

Plot the stimulus on the surface of another stimulus.

Use this to plot more than one stimulus and to present them at the same time afterwards by presenting the stimulus on which they were plotted on.

Parameters :

stimulus : expyriment stimulus

stimulus to whose surface should be plotted

Returns :

time : int

the time it took to execute this method

Notes

Depending on the size of the stimulus, this method may take some time to compute!

points

Return polygon as list of tuples (x,y) in Expyriment coordinates.

In contrast to the vertex representation, the point representation takes into all the native transformations (rotation, scaling, flipping)

Returns :

val: list of tuples :

polygon as list of tuples (x,y) in Expyriment coordinates

points_on_screen

Return polygon as list of tuples in Expyriment coordinates.

In contrast to the vertex representation, the point representation takes into all the native transformations (rotation, scaling, flipping)

Returns :

val: list of tuples :

polygon as list of tuples (x,y) in Expyriment coordinates

position

Getter for position.

preload(inhibit_ogl_compress=False)

Preload the stimulus to memory.

This will prepare the stimulus for a fast presentation. In OpenGL mode this method creates an OpenGL texture based on the surface of the stimulus. When OpenGL is switched off, this method will create a surface if it doesn’t exists yet. If stimuli are not preloaded manually, this will happen automatically during presentation. However, stimulus presentation will take some time then!

Always preload your stimuli when a timing acurate presentation is needed!

Parameters :

inhibit_ogl_compress : bool, optional

inhibits OpenGL stimuli to be automatically compressed (default=False)

Returns :

time : int

the time it took to execute this method

Notes

Depending on the size of the stimulus, this method may take some time to compute!

present(clear=True, update=True)

Present the stimulus on the screen.

This clears and updates the screen automatically. When not preloaded, depending on the size of the stimulus, this method can take some time to compute!

Parameters :

clear : bool, optional

if True the screen will be cleared automatically (default = True)

update : bool, optional

if False the screen will be not be updated automatically (default = True)

Returns :

time : int

the time it took to execute this method

rect

Getter for rect =(top, left, bottom, right).

remove_vertex(index)

Remove a vertex.

rotate(degree)

Rotate the stimulus.

This is a surface operation. After this, a surface will be present! Rotating goes along with a quality loss. Thus, rotating an already rotated stimulus is not a good idea.

Parameters :

degree : int

degree to rotate counterclockwise

Returns :

time : int

the time it took to execute this method

Notes

Depending on the size of the stimulus, this method may take some time to compute!

rotation

“Getter for the total native rotation.

rotation_centre

Getter for rotation_centre.

rotation_centre_display_colour

Getter for rotation_centre_display_colour.

save(filename)

Save the stimulus as image.

Parameters :

filename : str

name of the file to write (possible extensions are BMP, TGA, PNG, or JPEG with TGA being the default)

Notes

Depending on the size of the stimulus, this method may take some time to compute!

scale(factors)

Scale the stimulus.

This is a surface operation. After this, a surface will be present! Negative scaling values will flip the stimulus. Scaling goes along with a quality loss. Thus, scaling an already scaled stimulus is not a good idea.

Parameters :

factors : (int, int) or (float, float)

tuple representing the x and y factors to scale or a single number. In the case of a single number x and y scaling will be the identical (i.e., proportional scaling)

Returns :

time : int

the time it took to execute this method

Notes

Depending on the size of the stimulus, this method may take some time to compute!

scaling

“Getter for the total native scaling.

scramble(grain_size)

Scramble the stimulus.

Attention: If the surface size is not a multiple of the grain size, you may loose some pixels on the edge.

Parameters :

grain_size : int or (int, int)

size of a grain (use tuple of integers for different width & height)

Returns :

time : int

the time it took to execute this method

Notes

Depending on the size of the stimulus, this method may take some time to compute!

set_logging(onoff)

Set logging of this object on or off

Parameters :

onoff : bool

set logging on (True) or off (False)

Notes

See also design.experiment.set_log_level fur further information about event logging.

surface_size

Getter for surface_size.

unload(keep_surface=False)

Unload the stimulus from memory.

This will unload preloaded stimuli. In OpenGL mode, this method will remove the reference to the OpenGL texture and the surface (when ‘keep_surface’ is False). When OpenGL is switched off, the reference to the surface will be removed (when ‘keep_surface’ is False).

Parameters :

keep_surface : bool, optional

keep the surface after unload (default=False)

Returns :

time : int

the time it took to execute this method

See also

clear_surface.

Notes

Depending on the size of the stimulus, this method may take some time to compute!

vertices

Getter for the polygon verticies.

xy_points

Return polygon as list of XYPoints of the shape.

The representation does not take into account the position. Use xy_points_on_screen for position-depended representation.

In contrast to the vertex representation, the point representation takes into all the native transformations (rotation, scaling, flipping).

Returns :

val: list of XYPoints :

polygon as list of XYPoints of the shape

xy_points_on_screen

Return polygon as list of XYPoints in Expyriment coordinates.

In contrast to the vertex representation, the point representation takes into all the native transformations (rotation, scaling, flipping).

Returns :

val: list of XYPoints :

polygon as list of XYPoints of the shape

Previous topic

expyriment.stimuli.FixCross

Next topic

expyriment.stimuli.Line

This Page