Skip to content

Instantly share code, notes, and snippets.

@leikind
Last active October 1, 2015 16:58
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 leikind/2027773 to your computer and use it in GitHub Desktop.
Save leikind/2027773 to your computer and use it in GitHub Desktop.
def screen_density diagonal_size_inches, width_pixels, height_pixels
Math.sqrt(width_pixels * width_pixels + height_pixels * height_pixels) / diagonal_size_inches
end
[
['iPhone 3GS', 3.5, 320, 480],
['Galaxy S3', 4.8, 720, 1280],
['Galaxy 7', 7, 800, 1280],
['Kindle Fire', 7, 600, 1024],
['Asus Transformer Pad Infinity 700 Series', 10, 1920, 1200],
['iPad 3rd generation', 9.7, 2048, 1536],
['iPhone 4S', 3.5, 640, 960],
['HTC Legend', 3.2, 320, 480],
['HTC ChaCha', 2.6, 320, 480],
['Galaxy S2', 4.3, 480, 800],
['Galaxy S4', 5, 1080, 1920],
['HTC One', 4.7, 1080, 1920],
['Galaxy Nexus', 4.7, 720, 1280],
['Nexus 4', 4.7, 768, 1280],
['Nexus 7', 7, 800, 1280],
['Nexus 10', 10.05, 2560, 1600],
['Nokia Asha 501', 3, 320, 240],
['Nokia Asha 210', 2.4, 320, 240],
['Kindle Fire HD', 7, 1280, 800],
['Asus Transformer Pad Infinity 700 Series', 10.1, 1920, 1200],
['Asus Transformer Pad TF300', 10.1, 1280, 800],
['iPad 2', 9.7, 1024, 768],
['iPad 3d or 4th gen', 9.7, 2048, 1536],
['iPad mini', 7.9, 1024, 768],
['Galaxy Tab 7.7', 7.7, 1280, 800],
['iPad mini', 7.9, 1224, 768],
['Nokia Lumia', 3.7, 480, 800],
['HTC One X', 4.7, 720, 1280],
['HTC Desire', 3.7, 480, 800],
['HTC One V', 3.7, 480, 800],
['Sony Xperia P', 4, 960, 540]
].map do |phone, diagonal_size_inches, width_pixels, height_pixels|
[phone, screen_density(diagonal_size_inches, width_pixels, height_pixels)]
end.sort{|a,b| a[1] <=> b[1] }.each do |phone, density|
puts "#{phone}\t#{density}"
end
__END__
Results:
iPad 2 131.958762886598
Nokia Asha 501 133.333333333333
Asus Transformer Pad TF300 149.449206052382
iPad mini 162.025316455696
iPhone 3GS 164.825201164068
Nokia Asha 210 166.666666666667
Kindle Fire 169.547777866865
HTC Legend 180.277563773199
iPad mini 182.910297399377
Galaxy Tab 7.7 196.030776770007
Galaxy 7 215.633854447008
Kindle Fire HD 215.633854447008
Nexus 7 215.633854447008
Galaxy S2 216.96565190122
HTC ChaCha 221.880078490092
Asus Transformer Pad Infinity 700 Series 224.173809078573
Asus Transformer Pad Infinity 700 Series 226.415547169358
Nokia Lumia 252.149271128445
HTC One V 252.149271128445
HTC Desire 252.149271128445
iPad 3d or 4th gen 263.917525773196
iPad 3rd generation 263.917525773196
Sony Xperia P 275.363396260287
Nexus 10 300.385468881404
Galaxy S3 305.959329178097
Galaxy Nexus 312.469102139333
HTC One X 312.469102139333
Nexus 4 317.600784059659
iPhone 4S 329.650402328136
Galaxy S4 440.58143401646
HTC One 468.703653209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment