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 {
368368
369369 const STILL: f32 = 0.02;
370370 const EDGE: f32 = 16.;
371+const PEAK_SPACING: f32 = 3.;
372+const MIN_PEAKS: usize = 6;
371373
372374 pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> AnyElement {
373375 let levels: Vec<f32> = bands
@@ -394,24 +396,21 @@ pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> Any
394396 let width = f32::from(bounds.size.width);
395397 let middle = bounds.origin.y + bounds.size.height / 2.;
396398 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;
398401 let mut path = PathBuilder::stroke(px(stroke::LINE));
399402 if frayed {
400403 path = path.dash_array(&[px(4.), px(3.)]);
401404 }
402- for step in 0..=steps {
403- let along = step as f32 / steps as f32;
404- let level = sample(&levels, along);
405+ path.move_to(point(bounds.origin.x, middle));
406+ for (index, level) in peaks.iter().enumerate() {
407+ let along = (index as f32 + 0.5) / count;
405408 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. };
407410 let x = bounds.origin.x + bounds.size.width * along;
408- let y = middle + px(swing * level * edge * half);
409- if step == 0 {
410- path.move_to(point(x, y));
411- } else {
412- path.line_to(point(x, y));
413- }
411+ path.line_to(point(x, middle + px(side * level * edge * half)));
414412 }
413+ path.line_to(point(bounds.origin.x + bounds.size.width, middle));
415414 if let Ok(path) = path.build() {
416415 window.paint_path(path, color);
417416 }
@@ -421,15 +420,15 @@ pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> Any
421420 .into_any_element()
422421 }
423422
424-fn sample(levels: &[f32], along: f32) -> f32 {
425- if levels.is_empty() {
426- return 0.;
427- }
428- let at = along * (levels.len() - 1) as f32;
429- let low = at.floor() as usize;
430- let high = (low + 1).min(levels.len() - 1);
431- let mix = at - low as f32;
432- levels[low] * (1. - mix) + levels[high] * mix
423+fn merge(levels: &[f32], count: usize) -> Vec<f32> {
424+ let count = count.clamp(MIN_PEAKS, levels.len().max(MIN_PEAKS));
425+ (0..count)
426+ .map(|index| {
427+ let from = index * levels.len() / count;
428+ let to = ((index + 1) * levels.len() / count).max(from + 1).min(levels.len());
429+ levels.get(from..to).map_or(0., |part| part.iter().copied().fold(0., f32::max))
430+ })
431+ .collect()
433432 }
434433
435434 pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement {