albusdemens
albusdemens

Reputation: 6614

Simplex noise to generate a set of images

I need to generate a set of images using simplex noise. Below you can find the code I developed and an output image.

How can make the code to generate different images every time I run it? At the moment I get the same image every time I run the code. And how can I tune the size of the features in the image? I would like to get something less salt-and-peppery.

import matplotlib.pyplot as plt
import numpy as np
import opensimplex
from opensimplex import OpenSimplex

simplex = OpenSimplex()
A = np.zeros([pix, pix])
for y in range(0, pix):
    for x in range(0, pix):
        value = simplex.noise2d(x,y)
        color = int((value + 1) * 128)
        A[x, y] = color

plt.imshow(A)
plt.show()

Output image:

enter image description here

Upvotes: 0

Views: 1602

Answers (2)

CpILL
CpILL

Reputation: 6999

From the examples if you want it more fuzzy then you need to divide your x, y cords by a "feature size" i.e.

from PIL import Image # Depends on the Pillow lib

import opensimplex as simplex

WIDTH = 256
HEIGHT = 256
FEATURE_SIZE = 24.0

print('Generating 2D image...')

im = Image.new('L', (WIDTH, HEIGHT))
for y in range(0, HEIGHT):
    for x in range(0, WIDTH):
        value = simplex.noise2(x / FEATURE_SIZE, y / FEATURE_SIZE)
        color = int((value + 1) * 128)
        im.putpixel((x, y), color)

im.save('noise2d.png')

Upvotes: 1

Romeo
Romeo

Reputation: 531

From this github page I can see you are actually able to pass a seed as an argument to the OpenSimplex class. Like this:

simplex = OpenSimplex(seed=1234)

That seed is used to generate the noise arrays.

Upvotes: 1

Related Questions