def iadd_test(self): """ iadd_test: Add two animations together, check if the duration is twice as long. """ A1 = ph.Animation() A2 = ph.Animation() A3 = A1.blank() A3 += A2 assert_equal(A3.duration, A1.duration + A2.duration)
def simple_all_frames_the_same_test(self): """ simple_all_frames_the_same_test: Draw a circle and make sure all frames are the same """ canvas = ph.Animation() canvas += ph.circle() canvas.render_all() for rhs in canvas.frames[1:]: assert_true((rhs.img == canvas.frames[0].img).all())
def layer_test(self): """ layer_test: Tests ONLY if the API is working, not a complete test. """ A = ph.Animation() A += ph.circle(color="r") with A.layer() as AX: AX += ph.circle(y=1, color="b") AX += ph.transform.translate(x=1) A.render_all()
def something_moved_test(self): """ something_moved_test: Draw a circle and make sure it moved """ canvas = ph.Animation() x = np.linspace(0, 1, 10) canvas += ph.circle(x=x) canvas.render_all() for rhs in canvas.frames[1:]: assert_true((rhs.img != canvas.frames[0].img).any())
def check_extent_test(self): """ check_extent_test: Check the extent/sides and make sure the properties function """ A = ph.Animation(200, 100, extent=2.0) assert_equal(A.xmin, -2) assert_equal(A.xmax, 2) assert_equal(A.ymax, -1) assert_equal(A.ymin, 1) assert_equal(A.aspect_ratio, 2)
def logo_animation(logo_text): pal = ph.palette(3) A = ph.Animation(fps=24, duration=1.5, width=800, height=800, bg=pal[2]) lg = ph.gradient.linear([pal[0], pal[1]], theta=-np.pi / 4) A += ph.circle(color=pal[3]) A += ph.filters.gaussian_blur() A += ph.circle(color=pal[3]) y = ph.motion.easeInOutQuad(0, 1, flip=True) for i in np.arange(-6, 6, 1.0): A += ph.text(logo_text, y=i * y, gradient=lg, font_size=1.0) return A
import numpy as np import pixelhouse as ph # A = ph.Canvas(width=300, height=300) # A = ph.Animation(width=300, height=300, fps=25) A = ph.Animation(width=300, height=300) # Draw grid lines dx = 4 for i in np.arange(-dx, dx, 0.5): A += ph.line(i, -dx, i, dx, thickness=0) A += ph.line(-dx, i, dx, i, thickness=0) z = ph.motion.easeInOutQuad(2, -2) x = ph.motion.easeInOutQuad(2, -2) A += ph.transform.pull(x, 0.25, alpha=z, mode="constant") A.show()
# A working file to test various aspects of the module import numpy as np import pixelhouse as ph # A = ph.Canvas(width=300, height=300) A = ph.Animation(width=400, height=400, fps=2) A += ph.circle(r=1.0, color="darkorange") A += ph.circle(r=0.8, color="w", mode="direct") z = ph.motion.easeInOutQuad(0, 2 * np.pi) A += ph.transform.motion_lines(0.4, theta=z) A += ph.transform.motion_lines(0.4) A += ph.transform.rotate(z) A.show()
dx = dist * (-acc[0]) dy = 0 * (dist * acc[1]) # print(c0,c1,c2) print(t, acc[1]) # print(dx.max()) self.transform(cvs, dy, dx, coords, "nearest", order=0) """ import pylab as plt plt.imshow(dx[:,:,0]) plt.colorbar() plt.show() exit() print(acc) """ C = ph.Animation(400, 200, fps=20) b = ph.motion.easeInOutQuad(-2, 2, flip=True) q = ph.circle(x=b, y=0, r=0.5, gradient=g) C += q C += squish(q) C.show()
def resize_animation_test(self): """ resize_animation_test: Check that resizing an animation doesn't fail """ C = ph.Animation() C.resize(2.0)
import numpy as np import pixelhouse as ph from pixelhouse.filters import gaussian_blur import pixelhouse.transform.elastic as el pal = ph.palette(8) f_font = "../pixelhouse/fonts/Montserrat-Medium.otf" C = ph.Canvas(500, 100, bg=pal[2]) C = ph.Animation(500, 100, bg=pal[2]) # , fps=10) lg = ph.gradient.linear([pal[0], pal[1]]) C += ph.text("pixelhouse", font_size=2 * 0.78, font=f_font, color="w") C += ph.text("pixelhouse", font_size=2 * 0.75, font=f_font, gradient=lg) a = ph.motion.easeInOutQuad(0, 0.12, True) z = np.linspace(2 * np.pi, 0) C += el.wave(amplitude=3 * a, wavelength=1.5, offset=z) z = np.linspace(0, 2 * np.pi) C += el.wave(amplitude=a, wavelength=0.3, offset=z) z = np.linspace(0, 2 * np.pi) C += el.wave(amplitude=a / 2, wavelength=0.3 / 7, offset=z + 0.2) # ph.canvas2gif(C, "wave_effect.gif", duration=0.1, # palettesize=32, gifsicle=True) C.show()
import pixelhouse as ph import numpy as np C = ph.Canvas() C = ph.Animation() x = np.linspace(0.05, 0.1, 100) C += ph.circle(x=x, r=1.5) C += ph.transform.scale(4) C.show()
import numpy as np import pixelhouse as ph from pixelhouse.filter import gaussian_blur import pixelhouse.transform.elastic as el pal = ph.ColorLoversPalette()(6) f_font = "../pixelhouse/fonts/Montserrat-Medium.otf" C = ph.Canvas(500, 200, bg=pal[2]) C = ph.Animation(500, 200, bg=pal[2], fps=30) lg = ph.linear_gradient(pal[0], pal[1]) # C += ph.circle(color=pal[3]) # C += gaussian_blur() # C += ph.circle(color=pal[3]) # for i in np.arange(-6, 6, 1.0): # C += ph.text("pixelhouse", font=f_font, y=i, gradient=lg) C += ph.text("pixelhouse", font=f_font) # C += el.pull(alpha=0.05) # C += el.distort(alpha=20) z = np.logspace(-0.8, -1.5, 100) print(z) C += el.distort(sigma=z, seed=20) z2 = 0.15 - z # C += gaussian_blur(z2,z2) # C.save("logo_pixelhouse.png") C.show()
w, h = scale * 600, scale * 200 C = ph.Canvas(w, h) C += ph.text( "RESIST", x=0, y=0.5, font="TitilliumWeb-Black.ttf", vpos="center", font_size=2.50, ) dist = erosion_distance(C, kernel_size=3, decay=0.8, depth_iterations=20).tolist() C = ph.Animation(w, h, bg=pal[-1]) n, tc = 40, 0.020 lg = ph.gradient.linear([pal[0], pal[1]]) for y in np.linspace(1.25 * C.ymin, 1.25 * C.ymax, n): C += ph.line(C.xmin, y, C.xmax, y, thickness=tc, gradient=lg) C += ph.filters.gaussian_blur(0.10, 0.10) for y in np.linspace(1.25 * C.ymin, 1.25 * C.ymax, n): C += ph.line(C.xmin, y, C.xmax, y, thickness=tc, gradient=lg) z = ph.motion.easeInQuad(0, 0.030, flip=True) C += rise(dist, amplitude=z) X = C.render(len(C) // 2) X += ph.transform.scale(1.0 / scale, 1.0 / scale)
# A working file to test various aspects of the module import numpy as np import pixelhouse as ph pal = ph.palette(4) C = ph.Canvas(width=400, height=400, bg=pal[0]) C = ph.Animation(width=400, height=400, bg=pal[0]) C += ph.circle(x=1, y=-0.5, r=2, color=pal[1]) theta = np.linspace(0, 2 * np.pi) with C.layer() as CX: CX += ph.polyline(color="k") CX += ph.transform.rotate(theta) CX += ph.filters.gaussian_blur(0.25, theta / 6) C += ph.circle(x=-1, r=1.0) C.show()
def iadd_wrong_type_test(self): """ iadd_wrong_type_test: Add animation to an int, expect TypeError """ A = ph.Animation() A += 7
# Testing the distortion transform import numpy as np import pixelhouse as ph A = ph.Canvas() A = ph.Animation(duration=2, fps=15) A += ph.circle(r=2, color="w") A += ph.circle(-1, 0, 0.50, color="purple") theta = ph.motion.easeInOutQuad(0, np.pi, True) A += ph.transform.rotate(theta) z = ph.motion.easeInOutQuad(0, 20, True) A += ph.transform.distort(seed=42, sigma=0.10, alpha=z) A.show()
def resize_test(self): canvas = ph.Animation(width=200, height=150) canvas.resize(2.0) assert_true(all(f.width == 400 for f in canvas.frames)) assert_true(all(f.height == 300 for f in canvas.frames))
# Example of rotating off axis import numpy as np import pixelhouse as ph from pixelhouse.filter import gaussian_blur from pixelhouse.transform import rotate pal = ph.ColorLoversPalette()(6) # C = ph.Canvas(400, 400, bg=pal[2]) C = ph.Animation(400, 400, bg=pal[2]) lg = ph.linear_gradient(pal[0], pal[1]) theta = np.linspace(0, 2 * np.pi) C += ph.text("pixelhouse", gradient=lg) C += rotate(theta, x=-3) C.show()
y = p * np.sin(theta) if is_overlap(x, y, r): continue color = np.random.randint(1, 5) pts.append((x, y, r, color)) print(np.array(pts)) np.save(f_pts, np.array(pts)) pts = np.load(f_pts) pal = ph.palette(114) # C = ph.Canvas(600, 600, bg=pal[0]) C = ph.Animation(600, 600, bg=pal[0], fps=30) idx = np.argsort(pts[:, -2]) pts = pts[idx] for x, y, r, color in tqdm(pts): u = int(color) if u == 1: t = np.linspace(0, 100) theta = ph.motion.easeInSine(0, 2 * np.pi, flip=True)(t) tx = np.arctan2(y, x) rx = np.sqrt(x**2 + y**2) x = rx * np.cos(theta + tx) y = rx * np.sin(theta + tx)