import random
def rand_color():
return hex(random.randrange(16, 256))[2:]
def draw_something(f, x, y, r, n):
if n == 0:
return
color = '#' + rand_color() + rand_color() + rand_color()
for dx in (-1, 1):
for dy in (-1, 1):
draw_something(f, x + dx * r, y + dy * r, r / 2.5, n - 1)
print('<circle cx="' + str(x) + 'px" cy="' + str(y) + 'px" r="' + str(r) + 'px" fill="' + color + '"/>', file=f)
f = open("generated.svg", "w")
print("<!-- Generated -->", file=f)
#os.system("generated.svg")
hei = 400
wid = 400
print('<svg xmlns="http://www.w3.org/2000/svg" height="' + str(hei) + 'px" width="' + str(wid) + 'px">', file=f)
draw_something(f, 200, 200, 104, 5)
print('</svg>', file=f)
f.close()
Comments