def simple_rectangles(): C = Canvas(**canvas_args) C += rectangle(-1, -1, 1, 1, color="lightcoral") C += rectangle(0, 0, 2, -2, color="lime") C += rectangle(-3, -3, 0.5, 0.5, color="royalblue") return C
def gridstack_test(self): """ dstack_test: Draw an image, stack it, and make sure it's the same as the numpy operation. """ C1 = ph.Canvas() C2 = ph.Canvas() C3 = ph.Canvas() C1 += ph.circle() C2 += ph.rectangle() C3 += ph.circle(x=1) # Make sure something was drawn assert_true(C1.img.sum() != 0) assert_true(C2.img.sum() != 0) assert_true(C3.img.sum() != 0) X = ph.gridstack([[C1, C2], [C2, C3]]) img_stack = np.vstack( [np.hstack([C1.img, C2.img]), np.hstack([C2.img, C3.img])]) assert_true(np.isclose(img_stack, X.img).all())
def resize_exact_test(self): """ resize_exact_test: After scaling, it should have these exact dimensions """ C = ph.Canvas(width=200, height=200) C += ph.rectangle(x=0.5, y=0.25, x1=0.75, y1=0.75) C.resize(output_size=(100, 50)) assert_true(C.width == 100) assert_true(C.height == 50)
def draw_with_gradient_test(self): """ draw_with_gradient_test: Draw discrete gradient and check both colors are present in the corners. """ C = ph.Canvas() g = ph.gradient.linear(["r", "b"], interpolation="discrete") C += ph.rectangle(C.xmin, C.ymin, C.xmax, C.ymax, gradient=g) assert_true((C.transform_color("r") == C.img[0, 0]).all()) assert_true((C.transform_color("b") == C.img[-1, -1]).all())
def setup(self): kwargs = { "width": 200, "height": 200, "extent": 4.0, "bg": "black", "shift": 8, } self.source = ph.Canvas(**kwargs) self.source += ph.circle(x=1, y=-0.5, color=[50, 75, 100, 100]) self.source += ph.rectangle(x=-1, y=0.5, color=[70, 75, 100, 100]) self.target = self.source.copy()
def resize_up_test(self): """ resize_up_test: After scaling by 2x, it should be 400 pixels. """ C = ph.Canvas(width=200, height=200) C += ph.rectangle(x=0.5, y=0.25, x1=0.75, y1=0.75) assert_true(C.width == 200) assert_true(C.height == 200) C.resize(fx=2) assert_true(C.width == 400) assert_true(C.height == 400)
def rectange_test(self): C = Canvas() C += rectangle() assert_true(C._img.sum() > 0)
def setup(self): self.canvas = ph.Canvas(width=200, height=200) self.canvas += rectangle(x=0.5, y=0.25, x1=0.75, y1=0.75)
# 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()
# Experimenting with hstack, vstack, and dstack import numpy as np import pixelhouse as ph import cv2 pal = ph.palette(2) C = ph.Canvas(height=50, width=400, bg="w") lg = ph.gradient.linear(pal, interpolation="discrete") C += ph.rectangle(C.xmin, C.ymin, C.xmax, C.ymax, gradient=lg) C2 = ph.Canvas(height=50, width=400, bg="w") lg = ph.gradient.linear(pal[::-1], interpolation="discrete") C2 += ph.rectangle(C.xmin, C.ymin, C.xmax, C.ymax, gradient=lg) CX = ph.vstack([C, C2]) CX.show() grid = [] for i in range(3): row = [] for j in range(5): C = ph.Canvas(height=200, width=200) C += ph.circle(r=4, color=pal[(i + j) % 5]) row.append(C) grid.append(row) ph.canvas.gridstack(grid).show() # C.show()
def rectange_test(self): self.canvas += ph.rectangle()
# Testing gradients of all kinds import pixelhouse as ph import numpy as np C = ph.Canvas(height=200, width=800, bg="w") # C = ph.Animation(height=200,width=800, bg='w') pal = ph.palette(2) lg = ph.gradient.linear(pal, interpolation="discrete") C += ph.rectangle(C.xmin, -1, C.xmax, 0, gradient=lg) lg = ph.gradient.linear(pal) C += ph.rectangle(C.xmin, 1, C.xmax, 0, gradient=lg) C.show()