Skip to content

Instantly share code, notes, and snippets.

@tobchen
Last active May 12, 2024 09:53
Show Gist options
  • Save tobchen/0cf255b49a07152b35e161ac58a10229 to your computer and use it in GitHub Desktop.
Save tobchen/0cf255b49a07152b35e161ac58a10229 to your computer and use it in GitHub Desktop.
A python script for generating a dither SVG in any size
import sys
import math
size = int(sys.argv[1]) if len(sys.argv) > 1 else 4
# https://www.wolframalpha.com/input?i=solve+s*s%2F2+%3D+%28pi*r%5E2%29*2+for+r
radius = size / (2 * math.sqrt(math.pi))
print(f"""<svg version="1.1" width="{size}" height="{size}" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="white" />
<circle cx="0" cy="0" r="{radius}" fill="black" />
<circle cx="{size}" cy="0" r="{radius}" fill="black" />
<circle cx="0" cy="{size}" r="{radius}" fill="black" />
<circle cx="{size}" cy="{size}" r="{radius}" fill="black" />
<circle cx="{size / 2}" cy="{size / 2}" r="{radius}" fill="black" />
</svg>""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment