def create_island(seed, freq=3.5): w, h = 750, 512 falloff = create_falloff(w, h) n1 = 1.000 * sn.generate_noise(w, h, freq * 1, seed + 0) n2 = 0.500 * sn.generate_noise(w, h, freq * 2, seed + 1) n3 = 0.250 * sn.generate_noise(w, h, freq * 4, seed + 2) n4 = 0.125 * sn.generate_noise(w, h, freq * 8, seed + 3) elevation = falloff * (falloff / 2 + n1 + n2 + n3 + n4) elevation = sn.generate_sdf(elevation < 0.4) elmax = max(abs(np.amin(elevation)), abs(np.amax(elevation))) return elevation / elmax
def create_wrap_figures(): ground = snowy.load(qualify('ground.jpg')) hground = np.hstack([ground, ground]) ground2x2 = np.vstack([hground, hground]) snowy.export(ground2x2, qualify('ground2x2.jpg')) ground = snowy.blur(ground, radius=14, filter=snowy.LANCZOS) snowy.export(ground, qualify('blurry_ground_bad.jpg')) hground = np.hstack([ground, ground]) ground2x2 = np.vstack([hground, hground]) snowy.export(ground2x2, qualify('blurry_ground2x2_bad.jpg')) ground = snowy.load(qualify('ground.jpg')) ground = snowy.blur(ground, radius=14, wrapx=True, wrapy=True, filter=snowy.LANCZOS) snowy.export(ground, qualify('blurry_ground_good.jpg')) hground = np.hstack([ground, ground]) ground2x2 = np.vstack([hground, hground]) snowy.export(ground2x2, qualify('blurry_ground2x2_good.jpg')) n = snowy.generate_noise(256, 512, frequency=4, seed=42, wrapx=False) n = 0.5 + 0.5 * np.sign(n) - n n = np.hstack([n, n]) n = snowy.add_border(n, width=4) snowy.export(n, qualify('tiled_noise_bad.png')) n = snowy.generate_noise(256, 512, frequency=4, seed=42, wrapx=True) n = 0.5 + 0.5 * np.sign(n) - n n = np.hstack([n, n]) n = snowy.add_border(n, width=4) snowy.export(n, qualify('tiled_noise_good.png')) c0 = create_circle(400, 200, 0.3) c1 = create_circle(400, 200, 0.08, 0.8, 0.8) circles = np.clip(c0 + c1, 0, 1) mask = circles != 0.0 sdf = snowy.unitize(snowy.generate_sdf(mask, wrapx=True, wrapy=True)) sdf = np.hstack([sdf, sdf, sdf, sdf]) sdf = snowy.resize(np.vstack([sdf, sdf]), width=512) sdf = snowy.add_border(sdf) snowy.export(sdf, qualify('tiled_sdf_good.png')) sdf = snowy.unitize(snowy.generate_sdf(mask, wrapx=False, wrapy=False)) sdf = np.hstack([sdf, sdf, sdf, sdf]) sdf = snowy.resize(np.vstack([sdf, sdf]), width=512) sdf = snowy.add_border(sdf) snowy.export(sdf, qualify('tiled_sdf_bad.png'))
def create_island(seed, gradient, freq=3.5): w, h = 750, 512 falloff = create_falloff(w, h) n1 = 1.000 * snowy.generate_noise(w, h, freq*1, seed+0) n2 = 0.500 * snowy.generate_noise(w, h, freq*2, seed+1) n3 = 0.250 * snowy.generate_noise(w, h, freq*4, seed+2) n4 = 0.125 * snowy.generate_noise(w, h, freq*8, seed+3) elevation = falloff * (falloff / 2 + n1 + n2 + n3 + n4) mask = elevation < 0.4 elevation = snowy.unitize(snowy.generate_sdf(mask)) if GRAY_ISLAND: return (1 - mask) * np.power(elevation, 3.0) elevation = snowy.generate_sdf(mask) - 100 * n4 mask = np.where(elevation < 0, 1, 0) el = 128 + 127 * elevation / np.amax(elevation) return applyColorGradient(el, gradient)
def test_tileable(): n = snowy.generate_noise(200, 400, frequency=4, seed=42, wrapx=True) n = 0.5 + 0.5 * np.sign(n) - n n = np.hstack([n, n]) gold = snowy.resize(n, 200, 200) n = snowy.generate_noise(20, 40, frequency=4, seed=42, wrapx=True) n = 0.5 + 0.5 * np.sign(n) - n n = snowy.resize(n, 100, 200) bad = np.hstack([n, n]) n = snowy.generate_noise(20, 40, frequency=4, seed=42, wrapx=True) n = 0.5 + 0.5 * np.sign(n) - n n = snowy.resize(n, 100, 200, wrapx=True) good = np.hstack([n, n]) snowy.show(snowy.hstack([gold, bad, good], 2, .7))
def test_minification(): n = snowy.generate_noise(1000, 1000, frequency=5, seed=42) n = 0.5 + 0.5 * np.sign(n) a = snowy.resize(n, 100, 100) b = snowy.resize(n, 100, 100, snowy.MITCHELL) c = snowy.resize(n, 100, 100, snowy.GAUSSIAN) d = snowy.resize(n, 100, 100, snowy.NEAREST) x = [a, b, c, d] + [create_circle(100, 100)] snowy.show(np.hstack(x))
def test_tweet(): import snowy as sn, numpy as np im = sn.generate_noise(2000, 500, 5, seed=2, wrapx=True) df = sn.generate_sdf(im < 0.0, wrapx=True) im = 0.5 + 0.5 * np.sign(im) - im cl = lambda L, U: np.where(np.logical_and(df > L, df < U), -im, 0) im += cl(20, 30) + cl(60, 70) + cl(100, 110) sn.show(sn.resize(im, height=100, wrapx=True)) sn.show(sn.resize(np.hstack([im, im]), height=200, wrapx=True))
# Test rotations and flips gibbons = snowy.load(qualify('gibbons.jpg')) gibbons = snowy.resize(gibbons, width=gibbons.shape[1] // 5) gibbons90 = snowy.rotate(gibbons, 90) gibbons180 = snowy.rotate(gibbons, 180) gibbons270 = snowy.rotate(gibbons, 270) hflipped = snowy.hflip(gibbons) vflipped = snowy.vflip(gibbons) snowy.export(snowy.hstack([gibbons, gibbons180, vflipped], border_width=4, border_value=[0.5,0,0]), qualify("xforms.png")) # Test noise generation n = snowy.generate_noise(100, 100, frequency=4, seed=42, wrapx=True) n = np.hstack([n, n]) n = 0.5 + 0.5 * n snowy.show(n) snowy.export(n, qualify('noise.png')) # First try minifying grayscale gibbons = snowy.load(qualify('snowy.jpg')) gibbons = np.swapaxes(gibbons, 0, 2) gibbons = np.swapaxes(gibbons[0], 0, 1) gibbons = snowy.reshape(gibbons) source = snowy.resize(gibbons, height=200) blurry = snowy.blur(source, radius=4.0) diptych_filename = qualify('diptych.png') snowy.export(snowy.hstack([source, blurry]), diptych_filename)
def test_noise_smoothness(): noise = 0.5 + 0.5 * snowy.generate_noise(300, 150, 4, seed=42) grad = snowy.gradient(noise) grad = grad[0] + grad[1] grad = snowy.unitize(grad) snowy.show(grad)