def level_indicator(value, text, scaling, width=20, text_size=14, text_gap=20, position=(0, 0), thresholds=None, colour=constants.C_EXPYRIMENT_ORANGE): """make an level indicator in for of an Expyriment stimulus text_gap: gap between indicator and text scaling: Scaling object Returns -------- expyriment.Canvas """ value = scaling.trim(value) # indicator height = scaling.pixel_max - scaling.pixel_min indicator = Canvas(size=[width + 2, height + 2], colour=(30, 30, 30)) zero = scaling.data2pixel(0) px_bar_height = scaling.data2pixel(value) - zero bar = Rectangle(size=(width, abs(px_bar_height)), position=(0, zero + int((px_bar_height + 1) / 2)), colour=colour) bar.plot(indicator) # levels & horizontal lines try: px_horizontal_lines = scaling.data2pixel( values=np.array(thresholds.thresholds)) except: px_horizontal_lines = None if px_horizontal_lines is not None: for px in px_horizontal_lines: level = Rectangle(size=(width + 6, 2), position=(0, px), colour=constants.C_WHITE) level.plot(indicator) # text labels txt = TextLine(text=text, text_size=text_size, position=(0, -1 * (int(height / 2.0) + text_gap)), text_colour=constants.C_YELLOW) # make return canvas w = max(txt.surface_size[0], indicator.size[0]) h = height + 2 * (txt.surface_size[1]) + text_gap rtn = Canvas(size=(w, h), colour=(0, 0, 0), position=position) indicator.plot(rtn) txt.plot(rtn) return rtn
def __init__(self, area_radius, n_dots, target_direction, target_dot_ratio, position=None, dot_speed=None, dot_lifetime=None, dot_radius=None, dot_colour=None, background_colour=None, north_up_clockwise=None): """Create a Random Dot Kinematogram Parameters: ----------- area_radius : int the radius of the stimulus area n_dots : int number of moving dots target_direction : int, float (0-360) movement target direction in degrees target_dot_ratio : float (0-1) ratio of dots that move consistently in the same target direction (the rest of the target moves in a random direction) can be sometimes only approximated! self.target_dot_ratio returns the precise actual target dot ratio position : (int, int), optional position of the stimulus dot_speed : int, optional the moving speed in pixel per second (default=100) dot_lifetime : int, optional the time the object lives in milliseconds (default 400) dot_radius : int, optional radius of the dots (default = 3) dot_colour : (int, int, int), optional colour (RGB) of the dots (default=experiment.foreground_colour) background_colour : (int, int, int), optional colour (RGB) of the background (default=experiment.background_colour) north_up_clockwise : bool, optional if true (default) all directional information refer to an north up and clockwise system otherwise 0 is right, counterclockwise (default=True) Notes: ------ Logging is switch off per default """ if dot_speed is None: dot_speed = defaults.randomdotkinematogram_dot_speed if dot_lifetime is None: dot_lifetime = defaults.randomdotkinematogram_dot_lifetime if dot_radius is None: dot_radius = defaults.randomdotkinematogram_dot_radius if dot_colour is None: dot_colour = defaults.randomdotkinematogram_dot_colour if north_up_clockwise is None: north_up_clockwise = defaults.randomdotkinematogram_north_up_clockwise if position is None: position = defaults.randomdotkinematogram_position if background_colour is None: background_colour = defaults.randomdotkinematogram_background_colour self.area_radius = area_radius self.dot_speed = dot_speed self.dot_lifetime = dot_lifetime self.dot_radius = dot_radius self.dot_colour = dot_colour self.north_up_clockwise = north_up_clockwise self._canvas = Canvas(size=(2 * (self.area_radius + self.dot_radius), 2 * (self.area_radius + self.dot_radius)), position=position, colour=background_colour) self.reset(n_dots=n_dots, target_direction=target_direction, target_dot_ratio=target_dot_ratio) self.set_logging(False)