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 test_udf(): c0 = create_circle(200, 200, 0.3) c1 = create_circle(200, 200, 0.08, 0.8, 0.8) c0 = np.clip(c0 + c1, 0, 1) circles = snowy.add_border(c0, value=1) mask = circles != 0.0 udf = snowy.unitize(snowy.generate_udf(mask)) nx, ny = snowy.gradient(udf) grad = snowy.unitize(nx + ny) snowy.show(snowy.hstack([circles, udf, grad]))
def test_gdf(): "This is a (failed) effort to create a smoother distance field." c0 = create_circle(200, 200, 0.3) c1 = create_circle(200, 200, 0.08, 0.8, 0.8) c0 = np.clip(c0 + c1, 0, 1) circles = snowy.add_border(c0, value=1) circles = np.clip(snowy.blur(circles, radius=2), 0, 1) circles = np.clip(snowy.blur(circles, radius=2), 0, 1) source = (1.0 - circles) * 2000.0 gdf = np.sqrt(snowy.generate_gdf(source)) gdf = snowy.unitize(gdf) nx, ny = snowy.gradient(gdf) grad = snowy.unitize(nx + ny) snowy.show(snowy.hstack([circles, gdf, grad]))
yvals = gradient_image[0] apply_lut = interpolate.interp1d(xvals, yvals, axis=0) return apply_lut(snowy.unshape(np.clip(elevation_image, 0, 255))) def create_falloff(w, h, radius=0.4, cx=0.5, cy=0.5): hw, hh = 0.5 / w, 0.5 / h x = np.linspace(hw, 1 - hw, w) y = np.linspace(hh, 1 - hh, h) u, v = np.meshgrid(x, y, sparse=True) d2 = (u-cx)**2 + (v-cy)**2 return 1-snowy.unitize(snowy.reshape(d2)) c0 = create_circle(200, 200, 0.3) c1 = create_circle(200, 200, 0.08, 0.8, 0.8) c0 = np.clip(c0 + c1, 0, 1) circles = snowy.add_border(c0, value=1) sdf = snowy.unitize(snowy.generate_sdf(circles != 0.0)) stack = snowy.hstack([circles, sdf]) snowy.export(stack, qualify('sdf.png')) snowy.show(stack) # Islands 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