From 5513510ad1d3cf151f33f46de2365b27e09fc40e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 18 May 2022 05:23:44 +0200 Subject: [PATCH] Add markers with the solar noon and nadir (solar midnight) --- src/main.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 83c993b..c6b8572 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ extern crate smithay_client_toolkit as sctk; use std::time::SystemTime; use chrono::prelude::Local; +use chrono::TimeZone; use chrono::Timelike; use sctk::reexports::client::protocol::{wl_shm, wl_surface}; use sctk::shm::AutoMemPool; @@ -101,11 +102,14 @@ fn get_moon_path(image_width: u32, radius: f32, moon_phase: f64) -> Path { } fn gen_svg() -> Document { - // These should be calculated let local_timestamp = Local::now(); let utc_offset = local_timestamp.offset().local_minus_utc(); let local_time = local_timestamp.time().num_seconds_from_midnight() as i32; + // TODO: Make these configurable + let lat = 47.655235; + let long = 19.2868815; + // TODO: These should be calculated instead of hardcoded let image_width = 700u32; @@ -115,11 +119,23 @@ fn gen_svg() -> Document { let moon_radius = image_width as f32 * 0.071428571; let moon_phase = moon_illumination.phase * 28.0; + let sun_times = suncalc::get_times(unixtime, lat, long, None); + let noon = Local + .timestamp_millis(sun_times.solar_noon.0) + .time() + .num_seconds_from_midnight() as i32; + let midnight = Local + .timestamp_millis(sun_times.nadir.0) + .time() + .num_seconds_from_midnight() as i32; + let local_hour_font_size = 16.5; - let utc_hour_font_size = image_width as f32 * 0.021462; let hour_name_font_size = 13.37699; + let utc_hour_font_size = image_width as f32 * 0.021462; let outer_r = (image_width as f32) / 2.0 - 3.0 * hour_name_font_size; let ring_width = hour_name_font_size * 3.0; + let sun_radius = image_width as f32 * 0.0142871; + let marker_radius = outer_r - ring_width - 2.0 * utc_hour_font_size; let border = Rectangle::new() .set("x", 0i32) .set("y", 0i32) @@ -133,6 +149,7 @@ fn gen_svg() -> Document { .local-hour {stroke: none; fill: rgb(238, 187, 85);} .moon-background {stroke: rgb(170, 170, 170); stroke-width: 2px; fill: rgb(19, 17, 30);} .moon {stroke: none; fill: rgb(170, 170, 170);} + .mid-marker {stroke: red;} .dial {stroke-width: 2px; stroke: rgb(238, 187, 85);}", ); let mut local_clock = Group::new().set("id", "local-clock"); @@ -190,6 +207,42 @@ fn gen_svg() -> Document { .add(moon_circle) .add(get_moon_path(image_width, moon_radius, moon_phase)); + let noon_marker = Line::new() + .set("class", "mid-marker") + .set( + "transform", + format!( + "rotate({}, {}, {})", + time_to_degrees(noon), + image_width / 2, + image_width / 2 + ), + ) + .set("x1", image_width / 2) + .set( + "y1", + image_width as f32 / 2.0 + marker_radius - sun_radius as f32, + ) + .set("x2", image_width / 2) + .set("y2", image_width as f32 / 2.0 + marker_radius); + let midnight_marker = Line::new() + .set("class", "mid-marker") + .set( + "transform", + format!( + "rotate({}, {}, {})", + time_to_degrees(midnight), + image_width / 2, + image_width / 2 + ), + ) + .set("x1", image_width / 2) + .set( + "y1", + image_width as f32 / 2.0 + marker_radius - sun_radius as f32, + ) + .set("x2", image_width / 2) + .set("y2", image_width as f32 / 2.0 + marker_radius); let dial = Line::new() .set("id", "dial") .set("class", "dial") @@ -220,6 +273,8 @@ fn gen_svg() -> Document { .add(local_clock) .add(seasonal_clock) .add(moon_group) + .add(noon_marker) + .add(midnight_marker) .add(dial) }