argument parser
This commit is contained in:
parent
7916ddf888
commit
770f9c077c
30
kglobe.py
30
kglobe.py
@ -10,6 +10,7 @@ import math
|
|||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
import argparse
|
||||||
|
|
||||||
# Convert lat/lon to Cartesian coordinates
|
# Convert lat/lon to Cartesian coordinates
|
||||||
def latlon_to_xyz(lat, lon, radius=1.0):
|
def latlon_to_xyz(lat, lon, radius=1.0):
|
||||||
@ -60,9 +61,18 @@ def traceroute(target):
|
|||||||
return coords
|
return coords
|
||||||
|
|
||||||
def main():
|
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,
|
globe = pv.Sphere(radius=1.0, theta_resolution=120, phi_resolution=120,
|
||||||
start_theta=270.001, end_theta=270)
|
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[:, 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
|
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
|
# Convert to 3D coordinates
|
||||||
points_3d = [latlon_to_xyz(lat, lon) for lat, lon in locations]
|
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)
|
pl.add_mesh(globe, color='tan', smooth_shading=True, texture=tex, show_edges=False)
|
||||||
|
|
||||||
for pt in points_3d:
|
for pt in points_3d:
|
||||||
city_marker = pv.Sphere(center=pt, radius=0.02)
|
city_marker = pv.Sphere(center=pt, radius=0.02)
|
||||||
pl.add_mesh(city_marker, color='blue')
|
pl.add_mesh(city_marker, color='blue')
|
||||||
for i in range(len(points_3d[:-1])):
|
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)
|
line = pv.lines_from_points(arch, close=False)
|
||||||
pl.add_mesh(line, color='red', line_width=2)
|
pl.add_mesh(line, color='red', line_width=2)
|
||||||
|
|
||||||
@ -102,13 +104,15 @@ def main():
|
|||||||
|
|
||||||
frames = []
|
frames = []
|
||||||
try:
|
try:
|
||||||
|
if not args.external:
|
||||||
while True:
|
while True:
|
||||||
pl.camera.Azimuth(1)
|
pl.camera.Azimuth(1)
|
||||||
image = pl.screenshot(transparent_background=True, window_size=(512, 512))
|
image = pl.screenshot(transparent_background=True, window_size=(512, 512))
|
||||||
frames.append(Image.fromarray(image))
|
frames.append(Image.fromarray(image))
|
||||||
set_position(y-25, x)
|
set_position(y-25, x)
|
||||||
draw_to_terminal(Image.fromarray(image))
|
draw_to_terminal(Image.fromarray(image))
|
||||||
#pl.show()
|
else:
|
||||||
|
pl.show()
|
||||||
finally:
|
finally:
|
||||||
show_cursor()
|
show_cursor()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user