Last active
February 23, 2018 05:26
-
-
Save cversek/5294515d280335de5381de3d482fea5f to your computer and use it in GitHub Desktop.
Simple python script to generate polar checked stimuli patterns.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.misc import imsave | |
PIXELS_X = 256 | |
PIXELS_Y = PIXELS_X | |
COLOR_SOLID_WHITE = (255,255,255,255) | |
COLOR_SOLID_BLACK = (0,0,0,255) | |
COLOR_FULLY_TRANSPARENT_BLACK = (0,0,0,0) | |
def draw_sector(A,r1,r2, a1, a2, | |
color = COLOR_SOLID_WHITE, | |
): | |
xdim = A.shape[0] | |
ydim = A.shape[1] | |
x0 = xdim/2.0 | |
y0 = ydim/2.0 | |
x11 = r1*np.cos(a1) + x0 | |
y11 = r1*np.sin(a1) + y0 | |
x12 = r1*np.cos(a2) + x0 | |
y12 = r1*np.sin(a2) + y0 | |
x21 = r2*np.cos(a1) + x0 | |
y21 = r2*np.sin(a1) + y0 | |
x22 = r2*np.cos(a2) + x0 | |
y22 = r2*np.sin(a2) + y0 | |
xmin = int(min(x11,x12,x21,x22) - 0.5) | |
xmax = int(max(x11,x12,x21,x22) + 0.5) | |
ymin = int(min(y11,y12,y21,y22) - 0.5) | |
ymax = int(max(y11,y12,y21,y22) + 0.5) | |
for x in range(xmin,xmax): | |
for y in range(ymin,ymax): | |
x_c = x - x0 | |
y_c = y - y0 | |
a_c = np.arctan2(y_c,x_c) | |
d_sq = x_c*x_c + y_c*y_c | |
if d_sq >= r1*r1 and\ | |
d_sq <= r2*r2 and\ | |
a_c >= a1 and\ | |
a_c <= a2: | |
#solid | |
A[x,y,0] = color[0] | |
A[x,y,1] = color[1] | |
A[x,y,2] = color[2] | |
A[x,y,3] = color[3] | |
if __name__ == "__main__": | |
S = np.zeros((PIXELS_X, PIXELS_Y, 4), dtype=np.uint8) | |
R_COUNT = 20 | |
Rsectors = np.linspace(0,1.0,R_COUNT)*PIXELS_X/2.0 | |
A_COUNT = 51 | |
Asectors = np.linspace(-np.pi,np.pi,A_COUNT) | |
c1 = COLOR_SOLID_WHITE | |
c2 = COLOR_SOLID_BLACK | |
for i in range(len(Rsectors)-1): | |
r1 = Rsectors[i] | |
r2 = Rsectors[i+1] | |
for j in range(len(Asectors)-1): | |
a1 = Asectors[j] | |
a2 = Asectors[j+1] | |
draw_sector(S,r1=r1,r2=r2,a1=a1,a2=a2, color = c1) | |
c1, c2 = (c2, c1) #swap color | |
c1, c2 = (c2, c1) #swap color | |
imsave("./stim.png", S) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment