def check_len_test(self): """ check_len_test: Make sure that we load at least one color palette. Pull a color first to fix lazy loading. """ ph.palette(5) assert_true(len(ph.palette) > 5)
def draw_circles(C): """ This function draws the shaded circles to the screen. We are drawing them in a function so we can reuse them quickly for blending. """ # Palette #19 is a good predefined palette with whites and blues pal = ph.palette(19) # The base radius of our circles. Everything will scale from this radius = 1.60 offset = 0.50 tc = 0.2 # Base thickness # All the circles will have a linear gradient from top to bottom, # or bottom to top (we use theta for that). The second parameter [1, 0] # controls the alpha (the transparency). The sizing and thickness was # choosen by hand to get a nice effect. lg = ph.gradient.linear([pal[0], pal[1]], [1, 0], theta=-np.pi / 2) C += circle(0, 0, radius + offset, thickness=tc, gradient=lg) lg = ph.gradient.linear([pal[0], pal[1]], [1, 0], theta=np.pi / 2) C += circle(0, 0, radius - 2 * offset, thickness=tc / 2, gradient=lg) lg = ph.gradient.linear([pal[2], pal[1]], [1, 0], theta=-np.pi / 2) C += circle(0, 0, radius - offset, thickness=tc / 2, gradient=lg) lg = ph.gradient.linear([pal[2], pal[1]], [1, 0], theta=np.pi / 2) C += circle(0, 0, radius + 1.5 * offset, thickness=tc / 2, gradient=lg)
def teyleen_982(): C = Canvas(**canvas_args) pi = np.pi pal = [matplotlib_colors("lavender")] + ph.palette(96) tc = 0.025 dx = pi / 8 t0 = dx t1 = 2 * pi - dx r = 1.8 for n in range(6): ellipse( a=r, b=r, rotation=pi / 2, angle_start=t0, angle_end=t1, color=pal[n], thickness=tc, )(C) dx *= 1.4 t0 = dx t1 = 2 * pi - dx r -= 0.2 return C
def load_palette_test(self): """ load_palette_test: Load up a fixed palette and check the colors """ pal = ph.palette(5) known_color = [232, 221, 203, 255] assert_true(all([c0 == c1 for c0, c1 in zip(pal[0], known_color)]))
def teyleen_116(): C = Canvas(**canvas_args) pal = ph.palette(152) x = 0.25 C += circle(x, x, r=x / 2, color=pal[0]) C += circle(-x, x, r=x / 2, color=pal[1]) C += circle(x, -x, r=x / 2, color=pal[2]) C += circle(-x, -x, r=x / 2, color=pal[3]) C += circle(y=x / 2, r=2 - x, color=pal[4], thickness=x / 20) C += circle(y=-x / 2, r=2 - x, color=pal[4], thickness=x / 20) return C
def text_gradient_test(self): pal = ph.palette(15) C0 = ph.Canvas() C0 += ph.text(color=pal[0]) C1 = ph.Canvas() C1 += ph.text(color=pal[1]) g = ph.gradient.linear([pal[0], pal[1]]) C2 = ph.Canvas() C2 += ph.text(gradient=g) # Now check that none of them are equal for x, y in itertools.combinations([C0, C1, C2], r=2): assert_false((x.img == y.img).all())
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
# 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()
import random import numpy as np import pixelhouse as ph # Start with a good predefined color palette. # I like palette 20 since it has a bunch of muted reds and blues. pal = ph.palette(20) # Split the colors into our primary and background colors. background_color, primary_colors = pal[0], pal[1:] # Since we are coloring the circles, let's set a seed so we get # the same result each time. random.seed(44) # Setup our canvas! Make it 400 by 400 pixels, # and use the first palette color as the background. canvas = ph.Canvas(400, 400, bg=background_color) # Now draw some circles on the screen. We want to loop over this twice, # once for the vertical direction and the other for the horizontal. # To give it a wavy feel, we want every other circle to be offset a bit. radius = 0.40 for k, y in enumerate(np.arange(-6, 6, radius)): for x in np.arange(-6, 6, radius * 2.5): # If k is odd (eg. every other one), offset it! if k % 2:
# Testing chained animation import numpy as np import random import pixelhouse as ph from pixelhouse.filters import gaussian_blur pal = ph.palette(0) random.seed(44) x = np.linspace(0, 2, 100) C = ph.Animation(400, 400, bg=pal[0]) C += ph.rectangle(x=x, x1=x + 1, color=pal[3]) C2 = C.blank(duration=1) C2 += ph.circle(x=x, color=pal[2]) C2 += gaussian_blur() C += C2 C.show()
import pixelhouse as ph import numpy as np from scipy.ndimage.measurements import center_of_mass pal = ph.palette(3) g = ph.gradient.linear([pal[2], pal[3]]) class squish(ph.transform.elastic.ElasticTransform): def __init__(self, art): self.art = art self.dt = 0.01 def measure_CoM(self, cvs, t): bg = cvs.copy() self.art.draw(bg, t) mask = bg.alpha / 255 y, x = center_of_mass(mask) cx = cvs.inverse_transform_x(x) cy = cvs.inverse_transform_y(y) return np.array([cx, cy]) def draw(self, cvs, t=0.0): gravity = 5.0 # c0 = self.measure_CoM(cvs, t-self.dt) # c1 = self.measure_CoM(cvs, t) # c2 = self.measure_CoM(cvs, t+self.dt)
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 numpy as np import pixelhouse as ph # Palette #6 looks like the beach pal = ph.palette(6) canvas = ph.Canvas(400, 400, bg=pal[2]) # Draw a circle, fuzz it, then draw it again canvas += ph.circle(color=pal[3]) canvas += ph.filters.gaussian_blur() canvas += ph.circle(color=pal[3]) # Build a nice but subtle linear gradient for the text # Angle it at -45 degress (-pi/4) lg = ph.gradient.linear([pal[0], pal[1]], theta=-np.pi / 4) # Draw the text and repeat it vertically for i in np.arange(-6, 6, 1.0): canvas += ph.text("pixelhouse", y=i, gradient=lg) canvas.save("figures/logo_pixelhouse.png") canvas.show()
def out_of_bounds_test(self): """ out_of_bounds_test: Try to access a palette that doesn't exist. """ ph.palette(100000)
dy = np.zeros_like(coords[1]).astype(np.float) dist = np.array(dist) theta = self.theta(t) amplitude = cvs.transform_length(self.amplitude(t), is_discrete=False) dy += amplitude * np.cos(theta) * dist[:, :, np.newaxis] dx += amplitude * np.sin(theta) * dist[:, :, np.newaxis] dy[:, :, 0] *= 0 self.transform(cvs, dy, dx, coords, self.mode(t), order=0) pal = ph.palette(13) # w,h = 3*600, 3*200 scale = 4 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,
x = p * np.cos(theta) 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)