diff --git a/seasonal_clock/svg.py b/seasonal_clock/svg.py index e06f0fc..f01c610 100644 --- a/seasonal_clock/svg.py +++ b/seasonal_clock/svg.py @@ -1,12 +1,12 @@ from datetime import datetime, time from math import ceil, cos, pi, radians, sin -from typing import Union +from typing import Optional, Union from astral import LocationInfo, moon from pytz import UTC, timezone from .config import load_config -from .times import collect_day_parts +from .times import collect_day_parts, get_rahukaalam_times HOURS_AMPM = ( 'Midnight', @@ -94,7 +94,9 @@ def hex_to_rgb(hex_color: str) -> str: g = int(hex_color[3:5], 16) b = int(hex_color[5:7], 16) - return f'rgb({r}, {g}, {b})' + ret = f'rgb({r}, {g}, {b})' + + return ret def get_utc_offset(utc_time: datetime, local_time: datetime): @@ -160,12 +162,10 @@ def hour_marker( hour_name_y = image_width / 2 - outer_r + ring_width / 2 + hour_name_font_size / 4 utc_hour_y = image_width / 2 - outer_r + ring_width + utc_font_size - ret = f''' + ret = f''' {hour_name} @@ -194,7 +194,7 @@ def local_hour( return indent_lines( f''' str: + start_deg = time_to_degrees(start) + end_deg = time_to_degrees(end) + alpha = radians(end_deg - start_deg) + + delta_x = -rahukaala_radius * sin(alpha) + delta_y = -rahukaala_radius * (1 - cos(alpha)) + + inner_delta_x = -(rahukaala_radius - rahukaala_width) * sin(alpha) + inner_delta_y = -(rahukaala_radius - rahukaala_width) * (1 - cos(alpha)) + + s_delta_x = rahukaala_width * sin(alpha) + s_delta_y = -rahukaala_width * cos(alpha) + + i_delta_x = -2 * (rahukaala_radius - rahukaala_width) * sin(alpha) + + x1 = image_width / 2 + y1 = image_width / 2 + rahukaala_radius + + x2 = x1 + delta_x + y2 = y1 + delta_y + + x4 = x1 + y4 = y1 - rahukaala_width + + x3 = x4 + inner_delta_x + y3 = y4 + inner_delta_y + + ret = f'''''' + + return indent_lines(ret, indent) + + def get_svg_data( local_time: datetime, image_width: int = 700, @@ -276,6 +325,8 @@ def get_svg_data( golden_color: str = '#aa842c', day_color: str = '#7dc5f0', moon_color: str = '#aaaaaa', + rahukaala_color: str = '#ff7777', + rahukaala_alpha: Optional[int] = None, local_hour_font_size: float = 16.5, hour_name_font_size: float = 13.37699, utc_hour_font_size: float = 15.0234, @@ -293,6 +344,7 @@ def get_svg_data( golden_rgb = hex_to_rgb(golden_color) day_rgb = hex_to_rgb(day_color) moon_rgb = hex_to_rgb(moon_color) + rahukaala_rgb = hex_to_rgb(rahukaala_color) hours = HOURS_24 if hour_24 else HOURS_AMPM outer_r = image_width / 2 - 3 * hour_name_font_size ring_width = hour_name_font_size * 3 @@ -325,6 +377,12 @@ def get_svg_data( noon = day_parts_dict.pop('noon') midnight = day_parts_dict.pop('midnight') + if rahukaala_alpha is not None: + value = rahukaala_alpha / value + rahukaala_opacity = f' fill-opacity: {value:.2f};' + else: + rahukaala_opacity = '' + ret = f''' {hour_name_path(image_width, outer_r, ring_width)} @@ -397,6 +456,12 @@ def get_svg_data( evening_blue_end.time(), ) + rahukaala_radius = outer_r / 2 + 2 * sun_radius + rahukaala_width = 2 * sun_radius + + for start, end in get_rahukaalam_times(location.observer, local_time): + ret += draw_rahukaala(image_width, rahukaala_radius, rahukaala_width, sun_radius, start, end) + ret += f''' \n'''