Skip to content

Commit

Permalink
account for the last row being not full
Browse files Browse the repository at this point in the history
  • Loading branch information
kronicka committed Dec 22, 2018
1 parent 1092743 commit e2f229b
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,6 @@ def calculate_days(*dob: int) -> int:
return days_left


# def generate_calendar_days(days: int):
# """ Generate a calendar based on the number of days """
# days += 1
# square_path = 'img/square.jpg'
# background_path = 'img/background.png'
# square_size = (50, 50)
# cols = 48
# rows = int(days / cols)
#
# with Image.open(square_path) as square, Image.open(background_path) as background:
# print(background.format, background.size, background.mode)
# print(square.format, square.size)
# square = square.resize(square_size)
#
# for row in range(0, rows):
# for col in range(0, cols):
# box = (square.size[0] * col + 20, square_size[1] * row + 20)
# background.paste(square, box)
#
# background.show()


# Actually relevant code starts here
def calculate_weeks(*dob: int) -> int:
average_life_expectancy = 3726 # actually about half a week above the average human life expectancy (71.5 yrs)
Expand All @@ -52,21 +30,24 @@ def calculate_weeks(*dob: int) -> int:
def generate_calendar(weeks: int):
""" Generate a calendar based on the number of weeks """
# TODO: scale square pics based on the number of weeks
weeks += 1
square_path = 'img/square.jpg'
background_path = 'img/background.png'

square_size = (50, 50)
cols = 48
padding = 40
rows = int(weeks / cols)
rows, leftover = divmod(weeks / cols, 1)
rows = int(rows) + 1

with Image.open(square_path) as square, Image.open(background_path) as background:
print(background.format, background.size, background.mode)
print(square.format, square.size)
square = square.resize(square_size)

for row in range(0, rows):
if row == rows - 1 and leftover != 0:
cols *= leftover
cols = int(cols)
for col in range(0, cols):
box = (square.size[0] * col + padding, square_size[1] * row + padding)
background.paste(square, box)
Expand All @@ -75,5 +56,5 @@ def generate_calendar(weeks: int):


if __name__ == '__main__':
weeks = calculate_weeks(1995, 4, 10)
weeks = calculate_weeks(1948, 1, 10)
generate_calendar(weeks)

0 comments on commit e2f229b

Please sign in to comment.