From 9a491d5f7221c23e75268226844bf5ffd4d8f086 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Wed, 11 Mar 2020 08:55:44 -0500 Subject: color based on amplitude --- src/tom.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/tom.rs') diff --git a/src/tom.rs b/src/tom.rs index d8c8c24..217bf35 100644 --- a/src/tom.rs +++ b/src/tom.rs @@ -129,16 +129,27 @@ impl Tom { let start = self.last_x; let end = start + 3000; + let mut positions = Vec::new(); + for x in start..end { + positions.push(VertexPosition::new([x as f32, self.waveform[x] as f32])); + } + + for position in positions { + let color = match position[1].abs() as u32 { + 0..=50 => VertexRGB::new(constants::C64_BLUE), + 51..=125 => VertexRGB::new(constants::C64_LIGHT_BLUE), + 126..=225 => VertexRGB::new(constants::C64_CYAN), + _ => VertexRGB::new(constants::C64_GREEN), + }; + + self.wave.push(Vertex { position, color }); + } + let max_y = *self.waveform.iter().max().unwrap() as f32; let min_y = *self.waveform.iter().min().unwrap() as f32; - for x in start..end { - self.wave.push(Vertex { - position: VertexPosition::new([ - relative(x as f32, start as f32, end as f32, -0.9, 0.9), - relative(self.waveform[x] as f32, min_y, max_y, -0.9, 0.9), - ]), - color: VertexRGB::new(constants::C64_GREEN), - }); + for vertex in self.wave.iter_mut() { + vertex.position[0] = relative(vertex.position[0], start as f32, end as f32, -0.9, 0.9); + vertex.position[1] = relative(vertex.position[1], max_y, min_y, -0.9, 0.9); } self.wave.reverse(); -- cgit v1.2.3