Beispiel #1
0
def test_scale():

    surface = NumpySurface(width=200, height=100, fill=[0, 0, 0])
    red_box = NumpySurface(width=100, height=50, fill=[255, 0, 0])
    surface.blit(red_box, location=(0, 0), blend=False)

    surf = surface.copy()
    surf.scale(width=300)
    assert surf.height == 150
    assert surf.content[0][149][0] > 128 and surf.content[74][0][0] > 128
    assert surf.content[0][150][0] < 64 and surf.content[75][0][0] < 64

    surf = surface.copy()
    surf.scale(height=50)
    assert surf.width == 100
    assert surf.content[0][49][0] > 128 and surf.content[24][0][0] > 128
    assert surf.content[0][50][0] < 64 and surf.content[25][0][0] < 64

    surf = surface.copy()
    surf.scale(width=500, height=500)
    assert surf.height == 500 and surf.width == 500
    assert surf.content[0][249][0] > 128 and surf.content[249][0][0] > 128
    assert surf.content[0][250][0] < 128 and surf.content[250][0][0] < 128

    with pytest.raises(ValueError):
        surf.scale()
Beispiel #2
0
def test_avg_colour():

    surf1 = NumpySurface(width=100, height=100, fill=[200, 0, 0])
    surf2 = NumpySurface(width=50, height=100, fill=[0, 200, 0])
    surf1.blit(surf2)
    assert surf1.average_color == (100, 100, 0, 255)