Skip to content

Instantly share code, notes, and snippets.

@LegionMammal978
Last active December 25, 2023 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LegionMammal978/9769ea851dd38f84f2696139b960a254 to your computer and use it in GitHub Desktop.
Save LegionMammal978/9769ea851dd38f84f2696139b960a254 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
def emit(order, unit):
matrix = ('1 '*(order*order))[:-1]
attrs = [
f'order="{order}"',
f'kernelMatrix="{matrix}"',
'targetX="0"',
'targetY="0"',
f'kernelUnitLength="{unit}"',
]
if unit == 1:
attrs.insert(0, 'in="SourceGraphic"')
print(f'<feConvolveMatrix {" ".join(attrs)}/>')
n = int(sys.argv[1])
unit = 1
fours = 0
while n % 4 == 0:
n //= 4
fours += 1
if n % 2 == 0:
emit(2, unit)
n //= 2
unit *= 2
while n % 3 == 0:
emit(3, unit)
n //= 3
unit *= 3
for _ in range(fours):
emit(4, unit)
unit *= 4
order = 5
while order*order <= n:
if n % order == 0:
emit(order, unit)
n //= order
unit *= order
else:
order += 2
if n != 1:
emit(n, unit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment