Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import random, randrange
- # SVG strings
- # -----------
- SVG_HEADER = '<svg xmlns="http://www.w3.org/2000/svg" width="%f" height="%f">'
- SVG_LINE = '<path d="M %f,%f L %f,%f" style="stroke:black; stroke-width:%f; fill:none;" />'
- SVG_CIRCLE = '<circle cx="%f" cy="%f" r="%f" style="fill:black; stroke:white; stroke-width:1px;" />'
- SVG_FOOTER = '</svg>'
- # Initial settings and data
- # -------------------------
- graph_width = gw = 500
- graph_height = gh = 500
- line_width = 1
- circle_radius = cr = 10
- circle_diameter = cd = 2 * circle_radius
- nodes_count = nc = 100
- edges_count = ec = 500
- rndw = lambda: (graph_width - cd) * random() + cr
- rndh = lambda: (graph_height - cd) * random() + cr
- random_nodes = [(rndw(),rndh()) for _ in range(nodes_count)]
- random_edges = [(randrange(nc),randrange(nc)) for _ in range(edges_count)]
- # The Program
- # -----------
- print(SVG_HEADER % (graph_width, graph_height))
- for e1,e2 in random_edges:
- x1, y1 = random_nodes[e1]
- x2, y2 = random_nodes[e2]
- print(SVG_LINE % (x1, y1, x2, y2, line_width))
- for x, y in random_nodes:
- print(SVG_CIRCLE % (x, y, circle_radius))
- print(SVG_FOOTER)
- # End.
Advertisement
Add Comment
Please, Sign In to add comment