Skip to content

Instantly share code, notes, and snippets.

@iiviigames
Created October 9, 2019 19:35
Show Gist options
  • Save iiviigames/ac2c28941ebf7102f43a087b4b796c8c to your computer and use it in GitHub Desktop.
Save iiviigames/ac2c28941ebf7102f43a087b4b796c8c to your computer and use it in GitHub Desktop.
Find a the missing value in a width/height by providing either the width or height, and any aspect ratio you'd like. This console app does the rest!
# usr/bin/env python
# MODULE: aspector.py
# INFO: Enter a width or height value, then the ratio you'd like to find for
# the missing value. This will give it to you!
# CODED BY: iivii
# EMAIL: thelibrarian@odd.codes
# LICENSE: Just throw me a bone and let people know I helped out okay?
# NOTE: Send me anything you may use this code for! I'm just curious to see
# if anything I did was able to help you.
###########################################################################################
#################
# IMPORTS #
#################
import sys
#################
# GLOBALS #
#################
count = 0
#################
# FUNCS #
#################
# Gets the aspect ratio calculations
def aspect(width=1920, height=1080):
w = width
h = height
wratio, hratio = aspect_enter()
if width is 0 or width < 0:
find = h
else:
find = w
if find == h:
fwidth = wratio * find
fheight = hratio
final = fwidth/fheight
else:
fwidth = wratio
fheight = hratio * find
final = fheight/fwidth
return final
# Greets the user
def greet():
print("\nTo find a width, press 1. To find height, 2.\nAnything else exits.\n")
res = raw_input("::: ")
if res.isalnum():
res = int(res)
if res is 1:
print("\nPlease enter a width:")
get = raw_input("::: ")
if get.isalnum():
get = int(get)
outcome = aspect(int(get))
print("\nWith a width of " + str(get) + ", the height should be: ")
print("::: " + str(outcome))
else:
print("Please only enter values and not letters.")
greet()
elif res is 2:
print("\nPlease enter a height:")
get = raw_input("::: ")
if get.isalnum():
get = int(get)
outcome = aspect(0, int(get))
print("\nWith a height of " + str(get) + ", the width should be: ")
print("::: " + str(outcome))
else:
print("Please only enter values and not letters.")
greet()
else:
print("EXITING")
raise(sys.exit())
# Requests values to determine aspect ratio
def aspect_enter():
global count
print("Enter the first value for the ratio:")
wr = raw_input("::: ")
if not wr.isalnum():
print("\nOnly enter numbers.\n")
count += 1
if count >= 3:
print("Exiting, dumbass")
raise sys.exit()
aspect_enter()
print("Enter the second value for the ratio:")
hr = raw_input("::: ")
if not hr.isalnum():
print("\nOnly enter numbers.\n")
count += 1
if count >= 3:
print("Exiting, dumbass")
raise sys.exit()
aspect_enter()
wr = int(wr)
hr = int(hr)
count = 0
return wr, hr
#################
# MAINLOOP #
#################
greet()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment