def retino_grid(cr, N_rho=34, N_phi=233, N_H, N_V, offset,
size_mag, ecc_max, alpha, c1, c2, power):
# https://laurentperrinet.github.io/sciblog/posts/2020-04-16-creating-an-hexagonal-grid.html
phi_v, rho_v = np.meshgrid(np.linspace(0, 2*np.pi, N_phi, endpoint=False),
np.linspace(0, ecc_max, N_rho+1, endpoint=True)[1:], sparse=False, indexing='xy')
phi_v[::2, :] += np.pi/N_phi
offsets, colors = [-offset, offset], [c1, c2]
for offset_, color in zip(offsets, colors):
# convert to cartesian coordinates
X, Y = (rho_v * np.sin(phi_v) + offset_+1)/2, (rho_v * np.cos(phi_v)+1)/2
R = size_mag * rho_v**power / N_rho
for x, y, r in zip(X.ravel(), Y.ravel(), R.ravel()):
circle(cr, x, y, r)
cr.set_source_rgba(*hue_to_rgba(color, alpha))
cr.fill()
return cr
c_blue, dc = 240, 60
opts = dict(N_rho=N_rho, N_phi=N_phi, N_H=N_H, N_V=N_V,
offset=0.07, size_mag=0.3, ecc_max=0.8, alpha=0.80,
c1=c_blue-dc, c2=c_blue+dc)
@disp
def draw(cr, N_H=N_H, N_V=N_V): cr = retino_grid(cr, **opts)