# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Week 08, Worksheet 1: More Functions
#
# <div class="alert alert-block alert-danger">
#     If you're looking at this worksheet and thinking "WHAT THE WHAT?!" -- we'll be covering this on the week's video. Given our current knowledge, you can complete Worksheet 0 independently. To find the corresponding weekly video, visit the <a href = "">course schedule</a>.
# </div>
#
# ## Dig, if you will, some pictures
#
# Just like last week, we often come upon some requirement for functionality which necessitates creating a function. Perhaps we want to organize our code. Maybe we're looking at doing something many, many times and only want to write the procedure for a _very specific_ operation once. In any event, functions will become part of our regular vocabulary from here to the end of this course (and likely your entire career in Python).
#
# I'll propose a problem perfect for a functional solution, one that you might have come across in your digital life: resizing pictures. But -- not just _any_ pictures: we're going to resize some very interesting vintage computer ads.
#
# ### Of course, a detour
#
# ![A football player _and_ a librarian like bar charts? No way!](ads/ti_disaster.jpg)
#
# Aside: for a long time, no one had any idea who the real market for a computer would be, so companies tried to advertise to _everybody_ long before computers were really interoperable or easy to access. The prevailing attitude in some quarters shows:
#
# > There is no reason anyone would want a computer in their home
# >
# > —<NAME>, Digital Equipment Corporation (DEC), 1977
#
# For context: DEC made mainframes (i.e. _very large_ computers). These were the holy grail until the '70s.
#
# ## Resizing images
#
# All 2D pictures have two dimensions: width and height. To properly resize an image, getting these dimensions right requires a bit of math -- but, no fear, like the last worksheet, we're going to do this all together. In the end, we should have a nice collage. Well, at least _a_ collage.
#
# Let's get started.
#
# ## Loading image files
#
# We'll revisit a familiar data structure: `list`s. I've provided a bit of code for you to scan your folder and collect the names of the images in the `ads` folder, but we still need to:
#
# * `print` the original size of the images (both width and height)
# * resize each of the images _proportionally_ by a random "scale" percentage
# * add them to our collage at random places (who doesn't like a bit of variety?)
# * save our image as `worksheet_1_final_collage.png`

# +
import os # <-- a built-in module
import random
from PIL import Image, ImageDraw

def generate_random_position():
    # TODO: Finish function
    pass

def add_to_collage(img):
    # TODO: Finish function
    pass

def calculate_final_size(w, h):
    # TODO: Finish function
    pass

def batch_resize(img):
    img = Image.open(img,"r")
   # TODO: Finish function

vintage_ads = []
resized_images = []
#                                            R G B A
final_collage = Image.new("RGBA",(1024,768),(0,0,0,0))

for file in os.listdir("ads"): # <-- a handy method to look at our "ads" directory
    if file.endswith(".jpg"):
        vintage_ads.append(f"ads/{file}")

# TODO: Finish "collaging"
# -

# ### Finishing this exercise
#
# In the cell below, write the Markdown necessary to display the image, `worksheet_1_final_collage.png`.

# `TODO`

StarcoderdataJupyterScriptsDedupFiltered