예제 #1
0
def simplex(shape, time=0.0, seed=None, speed=1.0, as_np=False):
    """Return simplex noise values. Lives in its own module to avoid circular dependencies."""

    tensor = np.empty(shape, dtype=np.float32)

    if seed is None:
        seed = get_seed()

    # h/t Etienne Jacob
    # https://necessarydisorder.wordpress.com/2017/11/15/drawing-from-noise-and-then-making-animated-loopy-gifs-from-there/
    two_pi_times_time = math.tau * time
    z = math.cos(two_pi_times_time) * speed
    w = math.sin(two_pi_times_time) * speed

    if len(shape) == 2:
        simplex = OpenSimplex(seed=seed)

        for y in range(shape[0]):
            for x in range(shape[1]):
                tensor[y][x] = simplex.noise4d(x, y, z, w)

    else:
        for c in range(shape[2]):
            simplex = OpenSimplex(seed=seed + c * 65535)

            for y in range(shape[0]):
                for x in range(shape[1]):
                    tensor[y][x][c] = simplex.noise4d(x, y, z, w)

    tensor = (tensor + 1.0) * .5

    if not as_np:
        tensor = tf.stack(tensor)

    return tensor
예제 #2
0
class Benchmark:
    def __init__(self):
        self.simplex = OpenSimplex(seed=0)

    def run(self, number=100000):
        for i in _range(number):
            self.simplex.noise2d(0.1, 0.1)
            self.simplex.noise3d(0.1, 0.1, 0.1)
            self.simplex.noise4d(0.1, 0.1, 0.1, 0.1)
예제 #3
0
class Benchmark:
    def __init__(self):
        self.simplex = OpenSimplex(seed=0)

    def run(self, number=100000):
        for i in _range(number):
            self.simplex.noise2d(0.1, 0.1)
            self.simplex.noise3d(0.1, 0.1, 0.1)
            self.simplex.noise4d(0.1, 0.1, 0.1, 0.1)
예제 #4
0
class Benchmark:
    def __init__(self):
        self.simplex = OpenSimplex(seed=0)
        # trigger compilation
        x = np.linspace(0, 1, 10)
        self.simplex.noise2d(x, x)
        self.simplex.noise3d(x, x, x)
        self.simplex.noise4d(x, x, x, x)

    def run(self, number=1000000):
        x = np.linspace(0, 1, number)
        self.simplex.noise2d(x, x)
        self.simplex.noise3d(x, x, x)
        self.simplex.noise4d(x, x, x, x)
예제 #5
0
def main():
    simplex = OpenSimplex()

    print('Generating 2D image...')
    im = Image.new('L', (WIDTH, HEIGHT))
    for y in range(0, HEIGHT):
        for x in range(0, WIDTH):
            value = simplex.noise2d(x / FEATURE_SIZE, y / FEATURE_SIZE)
            color = int((value + 1) * 128)
            im.putpixel((x, y), color)
    im.save('noise2d.png')

    print('Generating 2D slice of 3D...')
    im = Image.new('L', (WIDTH, HEIGHT))
    for y in range(0, HEIGHT):
        for x in range(0, WIDTH):
            value = simplex.noise3d(x / FEATURE_SIZE, y / FEATURE_SIZE, 0.0)
            color = int((value + 1) * 128)
            im.putpixel((x, y), color)
    im.save('noise3d.png')

    print('Generating 2D slice of 4D...')
    im = Image.new('L', (WIDTH, HEIGHT))
    for y in range(0, HEIGHT):
        for x in range(0, WIDTH):
            value = simplex.noise4d(x / FEATURE_SIZE, y / FEATURE_SIZE, 0.0,
                                    0.0)
            color = int((value + 1) * 128)
            im.putpixel((x, y), color)
    im.save('noise4d.png')
예제 #6
0
def main():
    simplex = OpenSimplex()

    print("Generating 2D image...")
    im = Image.new("L", (WIDTH, HEIGHT))
    for y in range(0, HEIGHT):
        for x in range(0, WIDTH):
            value = simplex.noise2d(x / FEATURE_SIZE, y / FEATURE_SIZE)
            color = int((value + 1) * 128)
            im.putpixel((x, y), color)
    im.save("noise2d.png")

    print("Generating 2D slice of 3D...")
    im = Image.new("L", (WIDTH, HEIGHT))
    for y in range(0, HEIGHT):
        for x in range(0, WIDTH):
            value = simplex.noise3d(x / FEATURE_SIZE, y / FEATURE_SIZE, 0.0)
            color = int((value + 1) * 128)
            im.putpixel((x, y), color)
    im.save("noise3d.png")

    print("Generating 2D slice of 4D...")
    im = Image.new("L", (WIDTH, HEIGHT))
    for y in range(0, HEIGHT):
        for x in range(0, WIDTH):
            value = simplex.noise4d(x / FEATURE_SIZE, y / FEATURE_SIZE, 0.0, 0.0)
            color = int((value + 1) * 128)
            im.putpixel((x, y), color)
    im.save("noise4d.png")
예제 #7
0
class OpenSimplexWrapper(NoiseLibWrapper):
    def __init__(self, seed=0):
        super().__init__(seed)
        self.corelib = OpenSimplex(seed)

    def eval2d(self, x, y):
        return self.corelib.noise2d(x, y)

    def eval3d(self, x, y, z):
        return self.corelib.noise3d(x, y, z)

    def eval4d(self, x, y, z, w):
        return self.corelib.noise4d(x, y, z, w)
예제 #8
0
def simplex_noise():
    FEATURE_SIZE = 4.0
    freq_sine = 36

    simplex = OpenSimplex()

    print('Generating 2D image...')
    noise_color = []
    noise = Image.new('L', (32, 32))
    for y in range(0, 32):
        for x in range(0, 32):
            value = simplex.noise4d(x / FEATURE_SIZE, y / FEATURE_SIZE, 0.0,
                                    0.0)
            color = int((value + 1) * 128)
            noise.putpixel((x, y), color)
    noise = normalize(np.array(noise))
    noise = np.sin(noise * freq_sine * np.pi)
    noise_color = colorize(normalize(noise))
    return noise_color
예제 #9
0
def plot_arrow(x, y, dir):
    plt.plot([x, x + dir[0]], [y, y + dir[1]], c='b')


simp = OpenSimplex()
n = 16
T_MAX = 2 * np.pi
NUM_FRAMES = 180
x = np.linspace(0, 1, n)
y = np.linspace(0, 1, n)
z = np.linspace(0, T_MAX, NUM_FRAMES)
t = np.linspace(0, T_MAX, NUM_FRAMES)
canvas = np.zeros((len(x), len(y)))
for k in range(len(t)):
    print(k)
    for i in range(len(x)):
        for j in range(len(y)):
            dirX = simp.noise4d(x[i], y[j], np.cos(t[k]), np.sin(z[k]))
            dirY = simp.noise4d(x[i], y[j], np.cos(t[k]) + 3, np.sin(z[k]) + 3)
            plot_arrow(10 * x[i], 10 * y[j], [dirX, dirY])
    plt.axis('equal')
    plt.axis('off')
    plt.xlim(-1, 11)
    plt.ylim(-1, 11)
    #plt.show(block=False)
    #plt.pause(0.1)
    plt.savefig('ADFrames/' + str(k) + '.png')
    plt.clf()

gif.gifFolder('ADFrames', 'arrows2D.gif')
예제 #10
0

model = VGG19(weights = 'imagenet')
size = 224
j = 0
FEATURE_SIZE = 40.0

simplex = OpenSimplex()

print('Generating 2D image...')
noise_color = []
freq_sine = 36
noise = Image.new('L', (size, size))
for y in range(0, size):
    for x in range(0, size):
        value = simplex.noise4d(x / FEATURE_SIZE, y / FEATURE_SIZE, 0.0)
        color = int((value + 1) * 128)
        noise.putpixel((x, y), color)
noise = normalize(np.array(noise))
noise = np.sin(noise * freq_sine * np.pi)
noise_color = colorize(normalize(noise))  
max_norm = 12
i = 0 
for filename in os.listdir(img_dir):
    if not filename.startswith('.'):
        index = (int)(filename.split(".JPEG")[0].split("_")[2])
        #print(index)
        img = image.load_img(img_dir + filename, target_size = (size, size)) # We assume all images have the same dimensions
        img = image.img_to_array(img)
        label = val_annotations_map[index-1]
        i = i + 1
예제 #11
0
#setup

background_colour = (0, 0, 0)
(width, height) = (300, 300)

screen = pygame.display.set_mode((width, height))  #,pygame.FULLSCREEN)
screen.fill(background_colour)
pygame.display.set_caption('Simplex Noise')
pygame.font.init()

myfont = pygame.font.SysFont("monospace", 20)

clock = pygame.time.Clock()

simp = OpenSimplex()
print(simp.noise4d(x=10, y=10, z=5, w=2))

screen.fill(background_colour)

maxv = 0
minv = 255
values = []

for i in range(width):
    values.append([])
    for j in range(height):
        s = i / width
        t = j / height

        nx = 5 + 2 * math.cos(2 * math.pi * s)
        ny = 5.5 + 2 * math.cos(2 * math.pi * t)
예제 #12
0
palette = {
    0: [73, 89, 103],
    1: [189, 213, 234],
    2: [87, 115, 153],
    3: [255, 79, 121]
}

frames = []
fig = plt.Figure(figsize=(5, 4), dpi=100)
imData = io.BytesIO()
for k in range(len(t)):
    print(k, end='\r')
    for i in range(len(x)):
        for j in range(len(y)):
            for h in range(NUM_SAMPLE_LAYERS):
                samples[i][j][h] = int(
                    simp.noise4d(x[i], y[j], t[k] + 2 * h, z[k]) + 1)
            canvas[i][j] = palette[samples[i][j][0] + 2 * samples[i][j][1]]
    plt.axis('off')
    plt.imshow(canvas, interpolation="bicubic")
    # plt.show(block=False)
    # plt.pause(0.001)
    plt.savefig(imData, format='png')
    plt.clf()
    imData.seek(0)
    frames.append((255 * mpimg.imread(imData)).astype(np.uint8))
    imData.seek(0)

print('Done, Saving gif...')
imageio.mimsave('lamp.gif', frames, duration=0.05)
예제 #13
0
                     fill='-',
                     zfill=' ')

    print("Your animation is in process : ")

    for step in range(NB_FRAMES):
        stepPercent = step / NB_FRAMES
        pb.print_progress_bar(step)

        tx = dT * math.cos(stepPercent * 2 * math.pi)
        ty = dT * math.sin(stepPercent * 2 * math.pi)

        # Create the noise plane
        for x in range(noise.shape[0]):
            for y in range(noise.shape[1]):
                n = simplex.noise4d(x * dX, y * dY, tx, ty)
                noise[x, y] = n

        # Resize it to fit the image
        resized_noise = cv2.resize(noise, (img.shape[1], img.shape[0]))

        # apply the effect to the hue
        hue_effect = h + resized_noise * EFFECT_STRENGTH
        np.clip(hue_effect, 0, 255, out=hue_effect)
        hue_effect = hue_effect.astype('uint8')

        # create the image back to be displayed
        effect = cv2.merge((hue_effect, s, v))
        effect = cv2.cvtColor(effect, cv2.COLOR_HSV2BGR)

        if SAVE: