Skip to content

Instantly share code, notes, and snippets.

@nitori
Last active December 16, 2015 21:56
Show Gist options
  • Save nitori/3edbec1dfab92c5eff0c to your computer and use it in GitHub Desktop.
Save nitori/3edbec1dfab92c5eff0c to your computer and use it in GitHub Desktop.
test
import math
import colorsys
from itertools import product
from noise import snoise2
from PIL import Image
import numpy as np
size = (500, 500)
im = Image.new('RGB', size)
data = np.zeros((size[1], size[0], 3), dtype='uint8')
hi = np.array(colorsys.rgb_to_hsv(0, 255, 0))
lo = np.array(colorsys.rgb_to_hsv(0, 0, 128))
delta = hi - lo
stretch_factor = 20
zoom = 16.0 * 32
for y, x in product(*(range(n) for n in size)):
z = snoise2(
x/zoom, y/zoom,
octaves=10,
persistence=0.6,
# lacunarity=2.0,
repeatx=1000,
repeaty=1001,
base=0.0)
# z = (-math.sqrt(abs(z)) + 1) / 2
z = (z + 1) / 2
z = max(0.0, min(1.0, 0.5 + (z - 0.5) * stretch_factor))
data[x,y] = colorsys.hsv_to_rgb(*(lo + (delta * z)))
hi = np.array([0, 255, 0], dtype='uint8')
lo = np.array([0, 0, 128], dtype='uint8')
im.frombytes(data)
im.save('test.png')
im.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment