add example data
This commit is contained in:
parent
d5a9ad9a19
commit
5748917acf
28
kglobe.py
28
kglobe.py
@ -15,10 +15,20 @@ from terminalplotter import TerminalPlotter
|
|||||||
|
|
||||||
# TODO: Color arches based on latency
|
# TODO: Color arches based on latency
|
||||||
# TODO: Text info (num hops etc.)
|
# TODO: Text info (num hops etc.)
|
||||||
|
# TODO: Mouse support
|
||||||
# DONE: Interactive globe (spin w/ keys)
|
# DONE: Interactive globe (spin w/ keys)
|
||||||
# DONE: Image spacing
|
# DONE: Image spacing
|
||||||
# DONE: Async rendering?
|
# DONE: Async rendering?
|
||||||
|
|
||||||
|
EXAMPLE_ROUTE = [
|
||||||
|
(47.996, 7.849), # freiburg
|
||||||
|
(50.110, 8.682), # ffm
|
||||||
|
(52.231, 21.006), # warsaw
|
||||||
|
(12.988, 77.622), # bangalore
|
||||||
|
(22.350, 114.184), # hong kong
|
||||||
|
(-33.869, 151.208) # sydney
|
||||||
|
]
|
||||||
|
|
||||||
# Convert lat/lon to Cartesian coordinates
|
# Convert lat/lon to Cartesian coordinates
|
||||||
def latlon_to_xyz(lat: float, lon: float, radius=1.0):
|
def latlon_to_xyz(lat: float, lon: float, radius=1.0):
|
||||||
lat_rad = np.radians(lat)
|
lat_rad = np.radians(lat)
|
||||||
@ -83,6 +93,7 @@ def main():
|
|||||||
epilog="Requires kitty graphics protocol support in terminal",
|
epilog="Requires kitty graphics protocol support in terminal",
|
||||||
)
|
)
|
||||||
parser.add_argument("-t", "--traceroute", default=None)
|
parser.add_argument("-t", "--traceroute", default=None)
|
||||||
|
parser.add_argument("--example", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
locations = []
|
locations = []
|
||||||
@ -91,8 +102,8 @@ def main():
|
|||||||
|
|
||||||
globe = pv.Sphere(
|
globe = pv.Sphere(
|
||||||
radius=1.0,
|
radius=1.0,
|
||||||
theta_resolution=120,
|
theta_resolution=60,
|
||||||
phi_resolution=120,
|
phi_resolution=60,
|
||||||
start_theta=270.001,
|
start_theta=270.001,
|
||||||
end_theta=270,
|
end_theta=270,
|
||||||
)
|
)
|
||||||
@ -107,10 +118,14 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Convert to 3D coordinates
|
# Convert to 3D coordinates
|
||||||
points_3d = [latlon_to_xyz(lat, lon) for lat, lon in locations]
|
if args.example:
|
||||||
|
points_3d = [latlon_to_xyz(lat, lon) for lat, lon in EXAMPLE_ROUTE]
|
||||||
|
else:
|
||||||
|
points_3d = [latlon_to_xyz(lat, lon) for lat, lon in locations]
|
||||||
|
|
||||||
plotter = TerminalPlotter(450, 450)
|
height, width = kitty.get_terminal_size_pixel()
|
||||||
plotter.add_mesh(globe, color="tan", smooth_shading=True, texture=tex, show_edges=False)
|
plotter = TerminalPlotter(width, height)
|
||||||
|
plotter.add_mesh(globe, color="tan", smooth_shading=False, texture=tex, show_edges=False)
|
||||||
|
|
||||||
for point in points_3d:
|
for point in points_3d:
|
||||||
city_marker = pv.Sphere(center=point, radius=0.02)
|
city_marker = pv.Sphere(center=point, radius=0.02)
|
||||||
@ -120,7 +135,8 @@ def main():
|
|||||||
line = pv.lines_from_points(arch, close=False)
|
line = pv.lines_from_points(arch, close=False)
|
||||||
plotter.add_mesh(line, color="red", line_width=2)
|
plotter.add_mesh(line, color="red", line_width=2)
|
||||||
|
|
||||||
kitty.hide_cursor()
|
|
||||||
|
#kitty.hide_cursor()
|
||||||
try:
|
try:
|
||||||
asyncio.run(plotter.run())
|
asyncio.run(plotter.run())
|
||||||
finally:
|
finally:
|
||||||
|
@ -13,17 +13,18 @@ import kitty
|
|||||||
|
|
||||||
class TerminalPlotter(pv.Plotter):
|
class TerminalPlotter(pv.Plotter):
|
||||||
def __init__(self, width, height, **kwargs):
|
def __init__(self, width, height, **kwargs):
|
||||||
super().__init__(off_screen=True, window_size=(height, width), **kwargs)
|
super().__init__(off_screen=True, window_size=(width, height), **kwargs)
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
self._running = True
|
self._running = True
|
||||||
h_pix, _ = kitty.get_terminal_cell_size()
|
h_pix, _ = kitty.get_terminal_cell_size()
|
||||||
self.rows, _ = kitty.get_terminal_size()
|
self.rows, _ = kitty.get_terminal_size()
|
||||||
self.start_y, self.start_x = kitty.get_position()
|
self.start_y, self.start_x = kitty.get_position()
|
||||||
# the image requires height/cell_height lines
|
# the image requires height/cell_height lines
|
||||||
self.needed_lines = math.ceil(height / h_pix)
|
self.needed_lines = math.ceil(height / h_pix)
|
||||||
self.set_background([0.0, 1.0, 0.0])
|
self.set_background([0.0, 0.0, 0.0])
|
||||||
# if we are too close to the bottom of the terminal, create some space.
|
# if we are too close to the bottom of the terminal, create some space.
|
||||||
if self.rows - self.start_y < self.needed_lines:
|
if self.rows - self.start_y < self.needed_lines:
|
||||||
self.set_background([1.0, 0.0, 0.0])
|
|
||||||
missing = self.needed_lines - (self.rows - self.start_y)
|
missing = self.needed_lines - (self.rows - self.start_y)
|
||||||
self.start_y -= missing
|
self.start_y -= missing
|
||||||
print("\n" * self.needed_lines, end="")
|
print("\n" * self.needed_lines, end="")
|
||||||
@ -32,7 +33,7 @@ class TerminalPlotter(pv.Plotter):
|
|||||||
def render_to_kitty(self):
|
def render_to_kitty(self):
|
||||||
self.render()
|
self.render()
|
||||||
buf = io.BytesIO()
|
buf = io.BytesIO()
|
||||||
self.screenshot(buf, transparent_background=True)
|
self.screenshot(buf, transparent_background=True, window_size=(self.width, self.height))
|
||||||
kitty.draw_to_terminal(buf)
|
kitty.draw_to_terminal(buf)
|
||||||
# print("y:", self.start_y, "rows:", self.rows, end="")
|
# print("y:", self.start_y, "rows:", self.rows, end="")
|
||||||
kitty.set_position(self.start_y, self.start_x)
|
kitty.set_position(self.start_y, self.start_x)
|
||||||
|
Loading…
Reference in New Issue
Block a user