pub fn multicolor_stippled_line(
        &mut self,
        a: Vec2<f32>, b: Vec2<f32>, 
        width: f32, stipple_length: f32, stipple_spacing: f32, 
        color_a: Color, color_b: Color,
    ) {
        self.push_state_cmd(StateCmd::TextureChange(SamplerId::Solid));

        let len = (b - a).len(); // The length of the line
        let dir = (b - a) / len; // Unit vector from a to b

        // Just draw a single, slightly extended, segment
        if stipple_length + stipple_spacing > len {
            self.multicolor_line(a, b, width, color_a, color_b);

        // Create a bunch of line segments, starting at the middle
        } else {
            let mut start = 0.0;
            while start < len/2.0 {
                let end = if start == 0.0 {
                    stipple_length/2.0
                } else {
                    (start + stipple_length).min(len/2.0)
                };

                let t0 = start / len;
                let t1 = end / len;

                self.multicolor_line(
                    a + dir*(len/2.0 + start), 
                    a + dir*(len/2.0 + end), 
                    width, 
                    Color::lerp(color_a, color_b, 0.5 + t0),
                    Color::lerp(color_a, color_b, 0.5 + t1),
                );

                self.multicolor_line(
                    a + dir*(len/2.0 - start),
                    a + dir*(len/2.0 - end),
                    width, 
                    Color::lerp(color_a, color_b, 0.5 - t0),
                    Color::lerp(color_a, color_b, 0.5 - t1),
                );

                start = end + stipple_spacing;
            }
        } 
    }
/// Generate the vertices for a stippled line which starts with one color and transitions to
/// another color.
Generate the vertices for a stippled line which starts with one color and transitions to
another color.
Generate the vertices for a stippled line which starts with one color and transitions to another color .
pub fn multicolor_stippled_line(
        &mut self,
        a: Vec2<f32>, b: Vec2<f32>, 
        width: f32, stipple_length: f32, stipple_spacing: f32, 
        color_a: Color, color_b: Color,
    ) {
        self.push_state_cmd(StateCmd::TextureChange(SamplerId::Solid));
        let len = (b - a).len(); // The length of the line
        let dir = (b - a) / len; // Unit vector from a to b
        // Just draw a single, slightly extended, segment
        if stipple_length + stipple_spacing > len {
            self.multicolor_line(a, b, width, color_a, color_b);
        // Create a bunch of line segments, starting at the middle
        } else {
            let mut start = 0.0;
            while start < len/2.0 {
                let end = if start == 0.0 {
                    stipple_length/2.0
                } else {
                    (start + stipple_length).min(len/2.0)
                };
                let t0 = start / len;
                let t1 = end / len;
                self.multicolor_line(
                    a + dir*(len/2.0 + start), 
                    a + dir*(len/2.0 + end), 
                    width, 
                    Color::lerp(color_a, color_b, 0.5 + t0),
                    Color::lerp(color_a, color_b, 0.5 + t1),
                );
                self.multicolor_line(
                    a + dir*(len/2.0 - start),
                    a + dir*(len/2.0 - end),
                    width, 
                    Color::lerp(color_a, color_b, 0.5 - t0),
                    Color::lerp(color_a, color_b, 0.5 - t1),
                );
                start = end + stipple_spacing;
            }
        } 
    }
pub fn multicolor_stippled_line ( & mut self , a : Vec2 < f32 > , b : Vec2 < f32 > , width : f32 , stipple_length : f32 , stipple_spacing : f32 , color_a : Color , color_b : Color , ) { self . push_state_cmd ( StateCmd :: TextureChange ( SamplerId :: Solid ) ) ; let len = ( b - a ) . len ( ) ; // The length of the line let dir = ( b - a ) / len ; // Unit vector from a to b // Just draw a single, slightly extended, segment if stipple_length + stipple_spacing > len { self . multicolor_line ( a , b , width , color_a , color_b ) ; // Create a bunch of line segments, starting at the middle } else { let mut start = 0.0 ; while start < len / 2.0 { let end = if start == 0.0 { stipple_length / 2.0 } else { ( start + stipple_length ) . min ( len / 2.0 ) } ; let t0 = start / len ; let t1 = end / len ; self . multicolor_line ( a + dir * ( len / 2.0 + start ) , a + dir * ( len / 2.0 + end ) , width , Color :: lerp ( color_a , color_b , 0.5 + t0 ) , Color :: lerp ( color_a , color_b , 0.5 + t1 ) , ) ; self . multicolor_line ( a + dir * ( len / 2.0 - start ) , a + dir * ( len / 2.0 - end ) , width , Color :: lerp ( color_a , color_b , 0.5 - t0 ) , Color :: lerp ( color_a , color_b , 0.5 - t1 ) , ) ; start = end + stipple_spacing ; } } }
Generate the vertices for a stippled line which starts with one color and transitions to
another color.
Generate the vertices for a stippled line which starts with one color and transitions to another color .
&mut self
a
Vec2<f32>
b
Vec2<f32>
width
f32
stipple_length
f32
stipple_spacing
f32
color_a
Color
color_b
Color
&mut self
a
Vec2<f32>
b
Vec2<f32>
width
f32
stipple_length
f32
stipple_spacing
f32
color_a
Color
color_b
Color