Rotating a rectangular area in PsychoPy

Hello there,

I have created a PsychoPy experiment that generates a bunch of lines, with a certain rectangular region having a different orientation to the rest. Example:

I have done this using ElementArrayStim:

elements = visual.ElementArrayStim(win, nElements=nEls,
                                sizes=sizes, sfs=sfs, units='pix',
                                elementTex=tex, elementMask=mask,

I started by creating a grid:

#selecting the positional coordinates for the nxXny grid
xaxis = np.linspace(X_min, X_max, nx)
yaxis = np.linspace(Y_min, Y_max, ny)
xys = np.dstack(np.meshgrid(xaxis, yaxis)).reshape(-1, 2)

Then to define the rectangular area which will have a different orientation, I split the xy-coordinates into x-coordinates and y-coordinates:

#split the xy-coordinates into x-coordinates and y-coordinates
X = xys[:,0]
Y = xys[:,1]

And then define an area which I call ‘patch’, which I subsequently change the orientation for

patch = (X >= 90) * (X <= 282) * (Y >= 45) * (Y <=285)
oris[patch] = oris[patch] + 90

#setting the xys-positions, and oris-orientation for stimuli

All that has worked out fine. But, I am having difficulty rotating this rectangular patch area. I am hoping that it would look like this (this was done via photo editing, not PsychoPy):

Even if it would be an inefficient way, I did consider getting all the xy-coordinates which were part of ‘patch’ and rotating each and every one of them - using for example something like:

p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox
p'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy

Unfortunately, ‘patch’ returns an array of true and false (true are elements which will have an orientation change), so I am not sure how to proceed.

I would really appreciate some insight into how PsychoPy could handle something like this.