forge
Explore
Log in

Don't you dare go Hollow

Voice/share lines draw the spectrum like a bar visualizer: one zigzag point per band (alternating up/down = mirrored bars as one stroke), merged to fit narrow lines, instead of a sine carrier that hid the band shape

Browse files at this commit

c23db228125789c2e86a9f59a2d6ab54e2fcbfa6Ahmet Kaan GümüşParent: b97ed6c
  • style
    • voice/share lines draw the spectrum like a bar visualizer: one zigzag point per band (alternating up/down = mirrored bars as one stroke), merged to fit narrow lines, instead of a sine carrier that hid the band shape
Show full message
🎨 style: voice/share lines draw the spectrum like a bar visualizer: one zigzag point per band (alternating up/down = mirrored bars as one stroke), merged to fit narrow lines, instead of a sine carrier that hid the band shape
crates/client/src/gui/parts.rsmodified+19 -20
@@ -368,6 +368,8 @@ pub enum Voice {
368 368
369 const STILL: f32 = 0.02;369 const STILL: f32 = 0.02;
370 const EDGE: f32 = 16.;370 const EDGE: f32 = 16.;
371+const PEAK_SPACING: f32 = 3.;
372+const MIN_PEAKS: usize = 6;
371 373
372 pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> AnyElement {374 pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> AnyElement {
373 let levels: Vec<f32> = bands375 let levels: Vec<f32> = bands
@@ -394,24 +396,21 @@ pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> Any
394 let width = f32::from(bounds.size.width);396 let width = f32::from(bounds.size.width);
395 let middle = bounds.origin.y + bounds.size.height / 2.;397 let middle = bounds.origin.y + bounds.size.height / 2.;
396 let half = f32::from(bounds.size.height) / 2.;398 let half = f32::from(bounds.size.height) / 2.;
397- let steps = (width / 4.).max(8.) as usize;399+ let peaks = merge(&levels, (width / PEAK_SPACING) as usize);
400+ let count = peaks.len() as f32;
398 let mut path = PathBuilder::stroke(px(stroke::LINE));401 let mut path = PathBuilder::stroke(px(stroke::LINE));
399 if frayed {402 if frayed {
400 path = path.dash_array(&[px(4.), px(3.)]);403 path = path.dash_array(&[px(4.), px(3.)]);
401 }404 }
402- for step in 0..=steps {405+ path.move_to(point(bounds.origin.x, middle));
403- let along = step as f32 / steps as f32;406+ for (index, level) in peaks.iter().enumerate() {
404- let level = sample(&levels, along);407+ let along = (index as f32 + 0.5) / count;
405 let edge = (along.min(1. - along) * EDGE).min(1.);408 let edge = (along.min(1. - along) * EDGE).min(1.);
406- let swing = (step as f32 * 0.9).sin();409+ let side = if index % 2 == 0 { -1. } else { 1. };
407 let x = bounds.origin.x + bounds.size.width * along;410 let x = bounds.origin.x + bounds.size.width * along;
408- let y = middle + px(swing * level * edge * half);411+ path.line_to(point(x, middle + px(side * level * edge * half)));
409- if step == 0 {
410- path.move_to(point(x, y));
411- } else {
412- path.line_to(point(x, y));
413- }
414 }412 }
413+ path.line_to(point(bounds.origin.x + bounds.size.width, middle));
415 if let Ok(path) = path.build() {414 if let Ok(path) = path.build() {
416 window.paint_path(path, color);415 window.paint_path(path, color);
417 }416 }
@@ -421,15 +420,15 @@ pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> Any
421 .into_any_element()420 .into_any_element()
422 }421 }
423 422
424-fn sample(levels: &[f32], along: f32) -> f32 {423+fn merge(levels: &[f32], count: usize) -> Vec<f32> {
425- if levels.is_empty() {424+ let count = count.clamp(MIN_PEAKS, levels.len().max(MIN_PEAKS));
426- return 0.;425+ (0..count)
427- }426+ .map(|index| {
428- let at = along * (levels.len() - 1) as f32;427+ let from = index * levels.len() / count;
429- let low = at.floor() as usize;428+ let to = ((index + 1) * levels.len() / count).max(from + 1).min(levels.len());
430- let high = (low + 1).min(levels.len() - 1);429+ levels.get(from..to).map_or(0., |part| part.iter().copied().fold(0., f32::max))
431- let mix = at - low as f32;430+ })
432- levels[low] * (1. - mix) + levels[high] * mix431+ .collect()
433 }432 }
434 433
435 pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement {434 pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement {