def test_gamma(): source = path('gamma_dalai_lama_gray.jpg') dalai_lama = snowy.load(source) snowy.show(dalai_lama) small = snowy.resize(dalai_lama, height=32) snowy.export(small, path('small_dalai_lama.png')) snowy.show(small)
def draw_quad(): verts = np.array([[-0.67608007, 0.38439575, 3.70544936, 0., 0. ], [-0.10726266, 0.38439575, 2.57742041, 1., 0. ], [-0.10726266, -0.96069041, 2.57742041, 1., 1. ], [-0.67608007, -0.96069041, 3.70544936, 0., 1. ]]) texture = snowy.load(qualify('../tests/texture.png')) target = np.full((1080, 1920, 4), (0.54, 0.54, 0.78, 1.00), dtype=np.float32) snowy.draw_polygon(target, texture, verts) target = snowy.resize(target[400:770, 700:1000], height = 256) texture = snowy.resize(texture, height = 256) quad = snowy.hstack([texture, target]) snowy.export(quad, qualify('quad.png')) snowy.show(quad)
def test_range(): source = path('../docs/ground.jpg') ground = snowy.load(source) assert np.amin(ground) >= 0 and np.amax(ground) <= 1 with tempfile.NamedTemporaryFile() as fp: target = fp.name + '.png' snowy.export(ground, target) show_filename(target) show_filename(source) show_array(ground, True) blurred = snowy.blur(ground, radius=10) snowy.show(blurred)
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'))
heading.contents[0].replace_with(anchor) open(resultfile, 'w').write(str(soup)) generate_page(qualify('index.md'), qualify('index.html'), False) generate_page(qualify('reference.md'), qualify('reference.html'), 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)
import snowy import os import re HEIGHT = 2250 WIDTH = 3000 def func(arg): pattern = r'(.*\.jpg)$' return re.match(pattern, string=arg) print(func('123.jpg')) path = os.path.abspath(u'D:/周日敬拜/2017-9-24') files = os.listdir(path) imagefile_paths = [os.path.join(path, file).lower() for file in files] print(imagefile_paths) for file in imagefile_paths: source = snowy.load(file) height, width = source.shape[:2] if (height != HEIGHT or width != WIDTH): new_imagine = snowy.resize(source, width=WIDTH, height=HEIGHT) snowy.export(new_imagine, file) # source = snowy.load(imagefile_paths[0]) # height, width = source.shape[:2] # newImagine = snowy.resize(source, width=100, height=100) # snowy.export(newImagine, os.path.join(path, '8.jpg')) # print(height, width)
def clumpy(cmd): print(f"clumpy {cmd}") result = system(f".release/clumpy {cmd}") if result: raise Exception("clumpy failed") friction = 0.9 spacing = 20 step_size = 2.5 kernel_size = 5 decay = 0.99 nframes = 400 res = 4000, 2000 scalex = 2 scaley = 5 dim = "x".join(map(str, res)) clumpy(f"pendulum_phase {dim} {friction} {scalex} {scaley} field.npy") clumpy(f"bridson_points {dim} {spacing} 0 pts.npy") clumpy( f"advect_points pts.npy field.npy {step_size} {kernel_size} {decay} {nframes} phase.npy" ) im = snowy.reshape(1.0 - np.load("000phase.npy") / 255.0) im = snowy.resize(im, 500, 250) snowy.export(im, "extras/example6.png") snowy.show(im) system("rm *.npy") print("Generated extras/example6.png")