From 6e0dedb1fbe99931ac4fca8298a0a310565011e3 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 19 May 2022 05:04:48 +0200 Subject: [PATCH] Colour hour name plates based on their season --- src/main.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index aad43df..38fcdc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,12 +33,16 @@ enum Season { impl fmt::Display for Season { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", match self { - Season::Spring => "spring", - Season::Summer => "summer", - Season::Autumn => "autumn", - Season::Winter => "winter", - }) + write!( + f, + "{}", + match self { + Season::Spring => "spring", + Season::Summer => "summer", + Season::Autumn => "autumn", + Season::Winter => "winter", + } + ) } } @@ -79,6 +83,13 @@ fn hour_marker( hour_name_font_size: f32, utc_hour_font_size: f32, ) -> Group { + let season = match hour { + 0..=5 => Season::Winter, + 6..=11 => Season::Spring, + 12..=17 => Season::Summer, + 18..=23 => Season::Autumn, + _ => panic!("Hour out of range"), + }; let rotation = hour * 15; let delta_x = outer_r * (15f32.to_radians() / 2.0).sin(); @@ -133,7 +144,7 @@ fn hour_marker( .add(TextNode::new(format!("U {:02}", hour))); Group::new() - .set("class", "hour") + .set("class", format!("hour {season}")) .set( "transform", format!( @@ -298,6 +309,10 @@ fn gen_svg() -> Document { .hour path {stroke: rgb(0, 0, 0); stroke-width: 2px;} .hour text {stroke: none; fill: rgb(238, 187, 85);} .hour text.utc {stroke: none; fill: rgb(91, 68, 38);} + .winter path {fill: rgb(70, 62, 108);} + .spring path {fill: rgb(55, 87, 55);} + .summer path {fill: rgb(113, 92, 43);} + .autumn path {fill: rgb(108, 68, 44);} .local-hour {stroke: none; fill: rgb(238, 187, 85);} .night-time {stroke: none; fill: rgb(19, 17, 30);} .blue-hour {stroke: none; fill: rgb(9, 1, 119);}