add script for vis via osc

master
loooph 2023-03-01 00:06:26 +01:00
parent d39eda420e
commit a44e739b49
1 changed files with 36 additions and 0 deletions

36
osc/main.py Normal file
View File

@ -0,0 +1,36 @@
from graphviz import Digraph
from pythonosc.dispatcher import Dispatcher
from pythonosc.osc_server import BlockingOSCUDPServer
g = Digraph('G', filename='graph.gv', format='png')
# last vertex received
v = -1
# last edge target received
w = -1
# last edge type received
t = ""
def print_vertex(address, *args):
global v
v = args[args.index('vertex') + 1]
print(v)
def print_edge(address, *args):
global v
global w
global t
w = args[args.index('w') + 1]
t = args[args.index('edge_type') + 1]
print((v,w,t))
dispatcher = Dispatcher()
dispatcher.map("/edge", print_edge)
dispatcher.map("/vertex", print_vertex)
ip = "127.0.0.1"
port = 5050
server = BlockingOSCUDPServer((ip, port), dispatcher)
server.serve_forever() # Blocks forever