def main(args):
    screen = display.Display().screen()
    swidth = screen["width_in_pixels"]
    sheight = screen["height_in_pixels"]
    target = liblo.Address(args.host, args.port)
    N = int(args.dims)
    p = int(args.bits)
    tbits = N * p
    fp = 2.0**p
    screen_max = 2**11
    total_screen_max = 2**(2 * 11)
    dim_max = 2**tbits
    last_h = -1
    while True:
        x, y = getXY()
        x = screen_max * x / swidth
        y = screen_max * y / sheight
        h = hilbert.distance_from_coordinates([x, y], 11, 2)  # 2048x2048
        new_h = dim_max * h / total_screen_max
        new_x = hilbert.coordinates_from_distance(new_h, p, N)
        if last_h != new_h:
            print(h, new_h, new_x)
            new_xf = map(lambda x: x / fp, new_x)
            liblo.send(target, "/mouse", *new_xf)
        last_h = new_h
        time.sleep(1.0 / 30.0)
Пример #2
0
 def test_reversibility(self):
     """Assert coordinates_from_distance and distance_from_coordinates
     are inverse operations."""
     N = 3
     p = 5
     n_h = 2**(N * p)
     for h in range(n_h):
         x = hilbert.coordinates_from_distance(h, p, N)
         h_test = hilbert.distance_from_coordinates(x, p, N)
         self.assertEqual(h, h_test)
Пример #3
0
 def test_reversibility(self):
     """Assert coordinates_from_distance and distance_from_coordinates
     are inverse operations."""
     N = 3
     p = 5
     n_h = 2 ** (N * p)
     for h in range(n_h):
         x = hilbert.coordinates_from_distance(h, p, N)
         h_test = hilbert.distance_from_coordinates(x, p, N)
         self.assertEqual(h, h_test)
Пример #4
0
def location():
    x = min(180.0, max(-180.0, float(request.args.get("x"))))
    y = min(85.0, max(-85.0, float(request.args.get("y"))))
    x = int(screen_max * (x + 180.0) / 360.0)
    y = int(screen_max * (y + 85.0) / (2 * 85.0))
    h = hilbert.distance_from_coordinates([x, y], 11, 2)  # 2048x2048
    for i in range(1, N + 1):
        dim_max = 2**(i * p)
        new_h = dim_max * h / total_screen_max
        new_x = hilbert.coordinates_from_distance(new_h, p, i)
        print(new_x)
        new_xf = map(lambda x: x / fp, new_x)
        liblo.send(target, "/mouse" + str(i), *new_xf)
    return ('', 204)
Пример #5
0
import matplotlib.pyplot as plt
import hilbert

plt.figure(figsize=(10,10))
N = 2 # number of dimensions

p = 3 # number of iterations
npts = 2**(N*p)
pts = []
for i in range(npts):
    pts.append(hilbert.coordinates_from_distance(i, p, N))

connectors = range(3, npts, 4)
for i in range(npts-1):
    if i in connectors:
        color='grey'
        linestyle='--'
    else:
        color='black'
        linestyle='-'
    plt.plot( (pts[i][0], pts[i+1][0]), (pts[i][1], pts[i+1][1]),
              color=color, linewidth=3, linestyle=linestyle)

for i in range(npts):
    plt.scatter(pts[i][0], pts[i][1], 60, color='red')
    plt.text(pts[i][0] + 0.1, pts[i][1] + 0.1, str(i))

side = 2**p - 1
cmin = -0.5
cmax = side + 0.5
plt.grid()