diff options
Diffstat (limited to 'snakegame/utils.py')
-rw-r--r-- | snakegame/utils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/snakegame/utils.py b/snakegame/utils.py new file mode 100644 index 0000000..162c0b2 --- /dev/null +++ b/snakegame/utils.py @@ -0,0 +1,18 @@ +try: + from collections import OrderedDict as MaybeOrderedDict +except ImportError: + MaybeOrderedDict = dict + +def scale_aspect((source_width, source_height), (target_width, target_height)): + source_aspect = float(source_width) / source_height + target_aspect = float(target_width) / target_height + if source_aspect > target_aspect: + # restrict width + width = target_width + height = float(width) / source_aspect + else: + # restrict height + height = target_height + width = height * source_aspect + return (width, height) + |