|
|
|
@ -6,7 +6,6 @@ from datetime import datetime
|
|
|
|
|
import calendar
|
|
|
|
|
import random
|
|
|
|
|
import colorsys
|
|
|
|
|
from utils import random_color
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# dimensions of the output image
|
|
|
|
@ -17,8 +16,9 @@ DARK_BG = True
|
|
|
|
|
# precision of the calculation
|
|
|
|
|
PRECISION = 10000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
today = date.timetuple().tm_yday
|
|
|
|
|
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
|
|
|
|
|
return colorsys.hsv_to_rgb(progress, 1, 0.9)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
max_amp = 1 / waves / 2
|
|
|
|
|
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)
|
|
|
|
|
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)
|
|
|
|
|
alpha_step = 1 / waves
|
|
|
|
|
|
|
|
|
|
ctx.rectangle(0, 0, 1, 1)
|
|
|
|
|
# background color
|
|
|
|
|
if dark:
|
|
|
|
|
# make bg black
|
|
|
|
|
ctx.set_source_rgb(0, 0, 0)
|
|
|
|
|
else:
|
|
|
|
|
ctx.set_source_rgb(255, 255, 255)
|
|
|
|
|
ctx.rectangle(0, 0, 1, 1)
|
|
|
|
|
ctx.fill()
|
|
|
|
|
|
|
|
|
|
wave_height = 1 / waves
|
|
|
|
@ -85,9 +89,11 @@ def create_wpotd(width: int, height: int, date: datetime = datetime.now(), dark:
|
|
|
|
|
return surface
|
|
|
|
|
# surface.write_to_png(output) # Output to PNG
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
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()
|
|
|
|
|