0

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

albus_c
  • 6,292
  • 14
  • 36
  • 77

2 Answers2

1

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.

Romeo
  • 521
  • 5
  • 20
1

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')
CpILL
  • 6,169
  • 5
  • 38
  • 37