def generate_surface(): lower_left = point(64, 64, 1, 1,) upper_left = point(127,256, 1, 1) lower_right = point(256, 127, 1, 1) upper_right = point(496, 496, 1, 1) def surface(u, v): low = (1 - u) * lower_left + u * lower_right high = (1 - u) * upper_left + u * upper_right return (1 - v) * low + v * high return surface
def test_micropolygon(): m = Micropolygon( point(0, 0), point(1, 0), point(1, 1), point(2, 1), ) tests = [ [ (.5 , .5) , np.array([ 1, .5 , 1, 1 ]), ], [ (.25, .75), np.array([ 1, .75, 1, 1 ]), ], [ (0. , 0.) , np.array([ 0, 0 , 1, 1 ]), ], [ (1. , 0.) , np.array([ 1, 0 , 1, 1 ]), ], [ (0. , 1.) , np.array([ 1, 1 , 1, 1 ]), ], [ (1. , 1.) , np.array([ 2, 1 , 1, 1 ]), ], ] for input, expected in tests: actual = m(*input) np.testing.assert_array_equal(actual, expected)
def generate_surface(): lower_left = point(0, 0, 1, 1,) # up = 128 * np.array([0, 1, 0, 0], dtype=np.float32) # right = 128 * np.array([1, 0, 0, 0], dtype=np.float32) # up = np.array([256, 512, 0, 0], dtype=np.float32) # right = np.array([256, 0, 0, 0], dtype=np.float32) up = np.array([256, 512, 0, 0], dtype=np.float32) right = np.array([256, 0, 0, 0], dtype=np.float32) def surface(u, v): return lower_left + u * right + v * up return surface
def point_from_polar(u, v): return point( center[0] + radius * u * cos(v * tau), center[1] + radius * u * sin(v * tau), 1, 1 )
def surface(u, v): return point( center[0] + radius * u * cos(v * tau), center[1] + radius * u * sin(v * tau), 1, 1 )
def generate_mesh(): mesh = MicropolygonMesh((1, 1)) half = 512 / 2 center = point(half, half, 1, 1) right = point((1/2) * half, (1/6) * half, 0., 0) up = point(0, 3/4 * half, 0, 0) points = [ [ point(5, 10, 1, 1), point(20, 20, 1, 1) ], [ point(0, 0, 1, 1), point(10, 0, 1, 1) ], ] points = [ [ point(80, 160, 1, 1), point(320, 320, 1, 1) ], [ point(0, 0, 1, 1), point(160, 0, 1, 1) ], ] points = [ [ center + up - right, center + (up + right) ], [ center - (up + right), center - up + 1.5 * right ], ] colors = [ [ point(1, 0, 0, 1), point(1, 0, 1, 1) ], [ point(0, 0, 0, 1), point(0, 0, 1, 1) ] ] mesh.buffer[:,:]['position'] = points mesh.buffer[:,:]['color'] = colors return mesh