Created
December 22, 2024 16:46
-
-
Save ungeskriptet/137c8b3489d6dbafe6d8785cf4eb6fc0 to your computer and use it in GitHub Desktop.
Pixel pitch calculator (for Android)
This file contains 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 | |
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