Ticket #25696: onion_circles_pattern.py

File onion_circles_pattern.py, 2.3 KB (added by antonela, 13 months ago)
Line 
1import random
2import math
3import sys
4
5# constants
6size = 400
7blueish = "#5058ad"
8limeGreen = "#42d3bc"
9violet = "#bd10e0"
10colorList = [limeGreen, blueish, violet]
11fillColor = "#272755"
12fillOpacity = 0.0
13innerDots = [12, 11, 10, 9, 8, 7, 6, 5]
14
15svg_fmt ="""<svg width="{size}" height="{size}">
16  <rect x="0" y="0" width="{size}" height="{size}" fill="{fillColor}" fill-opacity="{fillOpacity}"/>
17  <circle cx="{center}" cy="{center}" r="{radius1}" stroke="{stroke}" stroke-width="{strokeWidth}" stroke-linecap="round" stroke-dasharray="{dashArray}" fill-opacity="0.0" />
18  <circle cx="{center}" cy="{center}" r="{radius2}" stroke="{stroke}" stroke-width="{strokeWidth}" stroke-linecap="round" stroke-dasharray="{dashArray}" fill-opacity="0.0" />
19  <circle cx="{center}" cy="{center}" r="{radius3}" stroke="{stroke}" stroke-width="{strokeWidth}" stroke-linecap="round" stroke-dasharray="{dashArray}" fill-opacity="0.0" />
20  <circle cx="{center}" cy="{center}" r="{radius4}" stroke="{stroke}" stroke-width="{strokeWidth}" stroke-linecap="round" stroke-dasharray="{dashArray}" fill-opacity="0.0" />
21</svg>"""
22
23# generated
24strokeWidth = size * 1.0 / 30.0
25center = size/2
26radius = size/2 - strokeWidth/2
27width = 2*radius
28height = 2*radius
29color = random.choice(colorList)
30innerCircumference = 1.0/2.0 * math.pi * radius
31
32strokeSpaceLength = innerCircumference / random.choice(innerDots)
33spaceLength = (1.5 + random.random()) * strokeWidth
34strokeLength = strokeSpaceLength - spaceLength
35
36# dumb way to avoid invalid stroke string
37while strokeLength < 0.0:
38    strokeSpaceLength = innerCircumference / random.choice(innerDots)
39    spaceLength = (1.5 + random.random()) * strokeWidth
40    strokeLength = strokeSpaceLength - spaceLength
41
42dashArray = "{strokeLength}, {spaceLength}".format(
43    strokeLength = strokeLength,
44    spaceLength = spaceLength)
45
46svg = svg_fmt.format(
47        size = size,
48        center = center,
49        radius1 = radius,
50        radius2 = radius * 0.75,
51        radius3 = radius * 0.5,
52        radius4 = radius * 0.25,
53        stroke = color,
54        strokeWidth = strokeWidth,
55        dashArray = dashArray,
56        fillColor = fillColor,
57        fillOpacity = fillOpacity)
58
59if len(sys.argv) > 1:
60    file = open(sys.argv[1], "w")
61    file.write(svg)
62    file.close()
63
64print(svg)