Created
February 23, 2016 22:34
-
-
Save darktrojan/07c8e2656c15eba6dbf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import argparse, math | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument(dest='width', type=int) | |
| parser.add_argument(dest='height', type=int) | |
| parser.add_argument('-s', dest='spacing', type=int, nargs='?', default=20) | |
| parser.add_argument('-b', dest='blackness', type=float, nargs='?', default=0.75) | |
| args = parser.parse_args() | |
| max_distance = max(args.width, args.height) | |
| half_width = args.width / 2 | |
| half_height = args.height / 2 | |
| half_max = max_distance / 2 | |
| circles = '' | |
| scale_x = float(max_distance) / args.width | |
| scale_y = float(max_distance) / args.height | |
| x = args.spacing / 2 | |
| while (x < args.width): | |
| y = args.spacing / 2 | |
| while (y < args.height): | |
| distance_x = abs(x * scale_x - half_max) | |
| distance_y = abs(y * scale_y - half_max) | |
| radius = math.sqrt(pow(distance_x, 2) + pow(distance_y, 2)) | |
| size = (1 - (radius / half_max)) * args.spacing * args.blackness | |
| if size > 0: | |
| circles += '\t\t<circle cx="%s" cy="%s" r="%.2f" />\n' % (x, y, size) | |
| y += args.spacing | |
| x += args.spacing | |
| print '<svg width="%d" height="%d">\n\t<g>\n%s\t</g>\n</svg>' % (args.width, args.height, circles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment