用图形处理可视化

2024-04-18 23:10:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用python处理图的邻接列表表示法(其中还包含每个顶点的坐标)来可视化一个图。代码如下:

add_library('peasycam')
graph_floor = [('A', (0, 0), [(0, 200), (200, 0)]),
               ('B', (200, 0), [(200, 200)]),
               ('C', (200, 200), [(0, 200)]),
               ('D', (0, 200), [])]
def setup():
    size(800, 800, P3D)
    cam = PeasyCam(this, 800)
    cam.setMinimumDistance(50)
    cam.setMaximumDistance(800)

def draw():
    background(0)
    stroke(255)
    strokeWeight(5)
    for i in graph_floor:
        lights()
        translate(i[1][0], i[1][1], 0)
        sphere(10)
        for j in i[2]:
            line(i[1][0], i[1][1], 0, j[0], j[1], 0)

当我渲染代码时,顶点似乎从它们的位置发生了移动。以下是截图: enter image description here


Tags: 代码inadd列表for可视化deflibrary