def clock(size=(256,256),angle=0,sharpEdge=False):
    """
    :param sharpEdge: if true, 100% black ends at 100% white for a difinitive angle -- otherwise gives more of a lighting effect
    """
    angle=0.75-angle/360.0
    dc=deltaC(size)
    img=np.arctan2(dc[:,:,0],dc[:,:,1])/math.pi
    img=(normalize(img)+angle)%1.0
    if not sharpEdge:
        img=deltaFromGray(img)
    return img
def clock2(size=(256,256),waveform="sine",frequency=(10,10),noise=0.2,noiseBasis="perlin",
    noiseOctaves=4,noiseSoften=0.0,direction=0,invert=False,seed=None):
    """
    a rotary clockface gradient
    """
    noiseSize=max(size)/8 # TODO: pass this value in somehow
    turb=turbulence(size,noiseSize,seed=seed)*noise
    #points=np.ndarray((int(size[0]),int(size[1])))
    angle=0.75-direction/360.0
    dc=deltaC(size)
    img=np.arctan2(dc[:,:,0],dc[:,:,1])/math.pi
    img=np.abs(np.sin((((normalize(img)+angle)%1.0)+turb)*math.pi))
    img=normalize(img)
    if invert:
        img=1.0-img
    return img
def logpolar2cartesian(polar_data):
    """
    From:
        https://stackoverflow.com/questions/2164570/reprojecting-polar-to-cartesian-grid
    """

    from scipy.ndimage.interpolation import map_coordinates

    theta_step=1
    range_step=500
    x=np.arange(-100000, 100000, 1000)
    y=x
    order=3

    # "x" and "y" are numpy arrays with the desired cartesian coordinates
    # we make a meshgrid with them
    X, Y = np.meshgrid(x, y)

    # Now that we have the X and Y coordinates of each point in the output plane
    # we can calculate their corresponding theta and range
    Tc = np.degrees(np.arctan2(Y, X)).ravel()
    Rc = np.ln(np.sqrt(X**2 + Y**2)).ravel()

    # Negative angles are corrected
    Tc[Tc < 0] = 360 + Tc[Tc < 0]

    # Using the known theta and range steps, the coordinates are mapped to
    # those of the data grid
    Tc = Tc / theta_step
    Rc = Rc / range_step

    # An array of polar coordinates is created stacking the previous arrays
    #coords = np.vstack((Ac, Sc))
    coords = np.vstack((Tc, Rc))

    # To avoid holes in the 360º - 0º boundary, the last column of the data
    # copied in the begining
    polar_data = np.vstack((polar_data, polar_data[-1,:]))

    # The data is mapped to the new coordinates
    # Values outside range are substituted with nans
    cart_data = map_coordinates(polar_data, coords, order=order, mode='constant', cval=np.nan)

    # The data is reshaped and returned
    return cart_data.reshape(len(Y), len(X)).T
Пример #4
0
fig = plt.figure()
plt.xticks([])
plt.yticks([])

k = 5  # number of plane waves
stripes = 37  # number of stripes per wave
N = 512  # image size in pixels
ite = 30  # iterations
phases = np.arange(0, 2 * pi, 2 * pi / ite)

image = np.empty((N, N))

d = np.arange(-N / 2, N / 2, dtype=np.float64)

xv, yv = np.meshgrid(d, d)
theta = np.arctan2(yv, xv)
r = np.log(np.sqrt(xv * xv + yv * yv))
r[np.isinf(r) == True] = 0

tcos = theta * np.cos(np.arange(0, pi, pi / k))[:, np.newaxis, np.newaxis]
rsin = r * np.sin(np.arange(0, pi, pi / k))[:, np.newaxis, np.newaxis]
inner = (tcos - rsin) * stripes

cinner = np.cos(inner)
sinner = np.sin(inner)

i = 0
for phase in phases:
    image[:] = np.sum(cinner * np.cos(phase) - sinner * np.sin(phase),
                      axis=0) + k
    plt.imshow(image.copy2numpy(), cmap="RdGy")