From 9d2da3249ad23958b4c53e462376b4362856875b Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 31 Oct 2019 19:59:40 +1100 Subject: [PATCH] colour faces --- server/src/img.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/server/src/img.rs b/server/src/img.rs index 7065832f..259ce6ae 100644 --- a/server/src/img.rs +++ b/server/src/img.rs @@ -270,6 +270,16 @@ pub fn smiley(id: Uuid) -> Result { // let stroke_width = rng.gen_range(1, 3); let stroke_width = 3; + let h = rng.gen_range(0, 360); + let s = s_dist.sample(&mut rng) as usize; + let l = l_dist.sample(&mut rng) as usize; + let eye_colour = format!("hsl({:}, {:}%, {:}%)", h, s, l); + + let h = rng.gen_range(0, 360); + let s = s_dist.sample(&mut rng) as usize; + let l = l_dist.sample(&mut rng) as usize; + let mouth_colour = format!("hsl({:}, {:}%, {:}%)", h, s, l); + // basic layout is 200x200 box w/ 100 padding // 2:1 for each x,y @@ -307,6 +317,7 @@ pub fn smiley(id: Uuid) -> Result { ("M50,75 L75,100 L100,75 L125,100 L150,75", 1), // w ("M50,75 L75,75 L75,87.5 M75,75 L125,75 L125,87.5 M125,75 L150,75", 1), // vamp ("M75,75 L125,75 L125,100 L75,100 L75,75", 1), // o + ("M50,75 L150,100 M150,75 L50,100", 1), // x ]; let mouth_dist = WeightedIndex::new(mouths.iter().map(|v| v.1))?; @@ -316,20 +327,20 @@ pub fn smiley(id: Uuid) -> Result { // left eye write!(&mut svg, - "", - stroke_width, left_eye_path)?; + "", + eye_colour, stroke_width, left_eye_path)?; let right_eye_path = eyes_right[eye_right_dist.sample(&mut rng)].0; // right eye write!(&mut svg, - "", - stroke_width, right_eye_path)?; + "", + eye_colour, stroke_width, right_eye_path)?; let mouth_path = mouths[mouth_dist.sample(&mut rng)].0; // mouth write!(&mut svg, - "", - stroke_width, mouth_path)?; + "", + mouth_colour, stroke_width, mouth_path)?; write!(&mut svg, "")?;