-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateSVG.py
35 lines (28 loc) · 1.01 KB
/
generateSVG.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import random
import xml.etree.ElementTree as ET
def generate_star_svg(width=4500, height=1080, star_count=1000, star_size=1, star_color='#fff'):
svg = ET.Element('svg', {
'xmlns': 'http://www.w3.org/2000/svg',
'width': str(width),
'height': str(height),
'viewBox': f'0 0 {width} {height}'
})
background = ET.SubElement(svg, 'rect', {
'width': str(width),
'height': str(height),
'fill': 'transparent'
})
star_group = ET.SubElement(svg, 'g', {'fill': star_color})
for _ in range(star_count):
x = random.randint(0, width)
y = random.randint(0, height)
ET.SubElement(star_group, 'rect', {
'x': str(x),
'y': str(y),
'width': str(star_size),
'height': str(star_size)
})
tree = ET.ElementTree(svg)
tree.write('star_background.svg', encoding='utf-8', xml_declaration=True)
print(f"Generated SVG with {star_count} 1px stars")
generate_star_svg()