diff --git a/kglobe.py b/kglobe.py index 0c49b0d..1c4914a 100644 --- a/kglobe.py +++ b/kglobe.py @@ -10,6 +10,7 @@ import math import subprocess import re import requests +import argparse # Convert lat/lon to Cartesian coordinates def latlon_to_xyz(lat, lon, radius=1.0): @@ -60,9 +61,18 @@ def traceroute(target): return coords def main(): - #globe = pv.examples.load_globe() - locations = traceroute('news.ycombinator.com') + parser = argparse.ArgumentParser( + prog='kglobe', + description='Traceroute on a globe', + epilog='Requires kitty graphics protocol support in terminal') + + parser.add_argument('target') + parser.add_argument('-e', '--external', action='store_true') + + args = parser.parse_args() + + locations = traceroute(args.target) globe = pv.Sphere(radius=1.0, theta_resolution=120, phi_resolution=120, start_theta=270.001, end_theta=270) @@ -74,25 +84,17 @@ def main(): globe.active_texture_coordinates[:, 0] = 0.5 + np.arctan2(globe.points[:, 1], globe.points[:, 0]) / (2 * math.pi) globe.active_texture_coordinates[:, 1] = 0.5 + np.arcsin(globe.points[:, 2]) / math.pi - #locations = [ - # (37.7749, -122.4194), # San Francisco - # (51.5074, -0.1278), # London - # (35.6895, 139.6917), # Tokyo - # (-33.8688, 151.2093), # Sydney - # (40.7128, -74.0060), # New York - #] - # Convert to 3D coordinates points_3d = [latlon_to_xyz(lat, lon) for lat, lon in locations] - pl=pv.Plotter(off_screen=True) + pl=pv.Plotter(off_screen=(not args.external)) pl.add_mesh(globe, color='tan', smooth_shading=True, texture=tex, show_edges=False) for pt in points_3d: city_marker = pv.Sphere(center=pt, radius=0.02) pl.add_mesh(city_marker, color='blue') for i in range(len(points_3d[:-1])): - arch = generate_arch(points_3d[i], points_3d[i+1], height_factor=0.5) + arch = generate_arch(points_3d[i], points_3d[i+1], height_factor=0.2) line = pv.lines_from_points(arch, close=False) pl.add_mesh(line, color='red', line_width=2) @@ -102,13 +104,15 @@ def main(): frames = [] try: - while True: - pl.camera.Azimuth(1) - image = pl.screenshot(transparent_background=True, window_size=(512, 512)) - frames.append(Image.fromarray(image)) - set_position(y-25, x) - draw_to_terminal(Image.fromarray(image)) - #pl.show() + if not args.external: + while True: + pl.camera.Azimuth(1) + image = pl.screenshot(transparent_background=True, window_size=(512, 512)) + frames.append(Image.fromarray(image)) + set_position(y-25, x) + draw_to_terminal(Image.fromarray(image)) + else: + pl.show() finally: show_cursor()