colour faces

This commit is contained in:
ntr 2019-10-31 19:59:40 +11:00
parent 200e4b4cb7
commit 9d2da3249a

View File

@ -270,6 +270,16 @@ pub fn smiley(id: Uuid) -> Result<Uuid, Error> {
// let stroke_width = rng.gen_range(1, 3); // let stroke_width = rng.gen_range(1, 3);
let stroke_width = 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 // basic layout is 200x200 box w/ 100 padding
// 2:1 for each x,y // 2:1 for each x,y
@ -307,6 +317,7 @@ pub fn smiley(id: Uuid) -> Result<Uuid, Error> {
("M50,75 L75,100 L100,75 L125,100 L150,75", 1), // w ("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 ("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 ("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))?; let mouth_dist = WeightedIndex::new(mouths.iter().map(|v| v.1))?;
@ -316,20 +327,20 @@ pub fn smiley(id: Uuid) -> Result<Uuid, Error> {
// left eye // left eye
write!(&mut svg, write!(&mut svg,
"<path fill=\"none\" stroke=\"whitesmoke\" stroke-width=\"{:}px\" d=\"{:}\" />", "<path fill=\"none\" stroke=\"{:}\" stroke-width=\"{:}px\" d=\"{:}\" />",
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; let right_eye_path = eyes_right[eye_right_dist.sample(&mut rng)].0;
// right eye // right eye
write!(&mut svg, write!(&mut svg,
"<path fill=\"none\" stroke=\"whitesmoke\" stroke-width=\"{:}px\" d=\"{:}\" />", "<path fill=\"none\" stroke=\"{:}\" stroke-width=\"{:}px\" d=\"{:}\" />",
stroke_width, right_eye_path)?; eye_colour, stroke_width, right_eye_path)?;
let mouth_path = mouths[mouth_dist.sample(&mut rng)].0; let mouth_path = mouths[mouth_dist.sample(&mut rng)].0;
// mouth // mouth
write!(&mut svg, write!(&mut svg,
"<path fill=\"none\" stroke=\"whitesmoke\" stroke-width=\"{:}px\" d=\"{:}\" />", "<path fill=\"none\" stroke=\"{:}\" stroke-width=\"{:}px\" d=\"{:}\" />",
stroke_width, mouth_path)?; mouth_colour, stroke_width, mouth_path)?;
write!(&mut svg, "</g></svg>")?; write!(&mut svg, "</g></svg>")?;