Skip to content

Instantly share code, notes, and snippets.

@ungeskriptet
Created December 22, 2024 16:46
Show Gist options
  • Save ungeskriptet/137c8b3489d6dbafe6d8785cf4eb6fc0 to your computer and use it in GitHub Desktop.
Save ungeskriptet/137c8b3489d6dbafe6d8785cf4eb6fc0 to your computer and use it in GitHub Desktop.
Pixel pitch calculator (for Android)
#!/usr/bin/python
from math import trunc
import sys
if len(sys.argv) <= 1:
print('pixelpitch.py <width> <height> <size in inch>')
quit()
width = float(sys.argv[1])
height = float(sys.argv[2])
size = float(sys.argv[3])
diagonal_pixel = (width**2 + height**2)**(1/2)
pitch = (size/diagonal_pixel) * 25.4
pitch_truncated = trunc(pitch * 1000 * 100) / 100
print(f'''Pixel pitch: {pitch}
<item name="pixel_pitch" format="float" type="dimen">{pitch_truncated}</item>''')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment