Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilim committed Jan 10, 2020
2 parents f4e059f + 2f35fa0 commit 88f8a63
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions stytra/stimulation/stimuli/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,6 @@ def get_unit_dims(self, w, h):
def get_transform(self, w, h, x, y):
return QTransform().rotate(self.theta * 180 / np.pi).translate(x, y)

@staticmethod
def negceil(x):
""" negative ceiling function (e.g -0.2 gets rounded to -1, while 0.2 gets rounded to 1)
"""
return int(-np.ceil(-x) if x < 0 else np.ceil(x))

def get_tile_ranges(self, imw, imh, w, h, tr: QTransform):
""" Calculates the number of tiles depending on the transform.
Expand Down Expand Up @@ -304,13 +298,14 @@ def get_tile_ranges(self, imw, imh, w, h, tr: QTransform):
[tr.inverted()[0].map(*cp) for cp in corner_points]
)

# calculate the rectangle covering the trnasformed display surface
# calculate the rectangle covering the transformed display surface
min_x, min_y = np.min(points_transformed, 0)
max_x, max_y = np.max(points_transformed, 0)

# count which tiles need to be drawn
x_start, x_end = (self.negceil(x / imw) for x in [min_x, max_x])
y_start, y_end = (self.negceil(y / imh) for y in [min_y, max_y])
x_start, x_end = (int(np.floor(min_x / imw)), int(np.ceil(max_x / imw)))
y_start, y_end = (int(np.floor(min_y / imh)), int(np.ceil(max_y / imh)))

return range(x_start, x_end + 1), range(y_start, y_end + 1)

def paint(self, p, w, h):
Expand Down Expand Up @@ -698,7 +693,7 @@ def z_func_windmill(x, y, arms):
) * (y >= 0).astype(int)


class WindmillStimulus(BackgroundStimulus):
class WindmillStimulus(CenteredBackgroundStimulus):
""" Class for drawing a rotating windmill (radial wedges in alternating colors).
For moving gratings use subclass
Expand Down Expand Up @@ -763,7 +758,7 @@ def __init__(self, *args, **kwargs):
self.dynamic_parameters.append("theta")


class HighResWindmillStimulus(BackgroundStimulus):
class HighResWindmillStimulus(CenteredBackgroundStimulus):
"""Class for drawing a rotating windmill with sharp edges.
Instead of rotating an image, this class use a painter to draw triangles
of the windmill at every timestep.
Expand Down

0 comments on commit 88f8a63

Please sign in to comment.