black formatting

main
Felix Pankratz 2 months ago
parent 0282fa1123
commit 82c19b690b

@ -6,7 +6,6 @@ from datetime import datetime
import calendar import calendar
import random import random
import colorsys import colorsys
from utils import random_color
# dimensions of the output image # dimensions of the output image
@ -17,8 +16,9 @@ DARK_BG = True
# precision of the calculation # precision of the calculation
PRECISION = 10000 PRECISION = 10000
def get_color_from_date(date: datetime) -> tuple[float, float, float]: def get_color_from_date(date: datetime) -> tuple[float, float, float]:
'''Return a color based on the progress through the year.''' """Return a color based on the progress through the year."""
# a day between 1 and 365 (inclusive) # a day between 1 and 365 (inclusive)
today = date.timetuple().tm_yday today = date.timetuple().tm_yday
days_in_year = 365 + calendar.isleap(date.year) days_in_year = 365 + calendar.isleap(date.year)
@ -26,13 +26,17 @@ def get_color_from_date(date: datetime) -> tuple[float, float, float]:
progress = today / days_in_year progress = today / days_in_year
return colorsys.hsv_to_rgb(progress, 1, 0.9) return colorsys.hsv_to_rgb(progress, 1, 0.9)
def get_amplitude_from_date(date: datetime, waves) -> float: def get_amplitude_from_date(date: datetime, waves) -> float:
'''Return the amplitude of waves, based on progress through the month.''' """Return the amplitude of waves, based on progress through the month."""
days_in_month = calendar.monthrange(date.year, date.month)[1] days_in_month = calendar.monthrange(date.year, date.month)[1]
max_amp = 1 / waves / 2 max_amp = 1 / waves / 2
return date.day / days_in_month * max_amp return date.day / days_in_month * max_amp
def create_wpotd(width: int, height: int, date: datetime = datetime.now(), dark: bool = True) -> cairo.ImageSurface:
def create_wpotd(
width: int, height: int, date: datetime = datetime.now(), dark: bool = True
) -> cairo.ImageSurface:
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
ctx = cairo.Context(surface) ctx = cairo.Context(surface)
@ -48,12 +52,12 @@ def create_wpotd(width: int, height: int, date: datetime = datetime.now(), dark:
r, g, b = get_color_from_date(date) r, g, b = get_color_from_date(date)
alpha_step = 1 / waves alpha_step = 1 / waves
ctx.rectangle(0, 0, 1, 1) # background color
if dark: if dark:
# make bg black
ctx.set_source_rgb(0, 0, 0) ctx.set_source_rgb(0, 0, 0)
else: else:
ctx.set_source_rgb(255, 255, 255) ctx.set_source_rgb(255, 255, 255)
ctx.rectangle(0, 0, 1, 1)
ctx.fill() ctx.fill()
wave_height = 1 / waves wave_height = 1 / waves
@ -85,9 +89,11 @@ def create_wpotd(width: int, height: int, date: datetime = datetime.now(), dark:
return surface return surface
# surface.write_to_png(output) # Output to PNG # surface.write_to_png(output) # Output to PNG
def main(): def main():
output = create_wpotd(1920, 1080, dark=False) output = create_wpotd(1920, 1080, dark=False)
output.write_to_png('out/waves.png') output.write_to_png("out/waves.png")
if __name__ == '__main__': if __name__ == "__main__":
main() main()

Loading…
Cancel
Save