diff --git a/fractional/src/main.rs b/fractional/src/main.rs index 29cdcad..0c6a7bc 100644 --- a/fractional/src/main.rs +++ b/fractional/src/main.rs @@ -339,8 +339,6 @@ fn main() { canvas.init_events(); let (tx, rx) = mpsc::channel(); - let tx1 = mpsc::Sender::clone(&tx); - canvas.start_events(tx); let i = Vector(Fractional( 0,1), Fractional(-35,1), Fractional(0,1)); let j = Vector(Fractional( 30,1), Fractional( 17,1), Fractional(0,1)); @@ -351,34 +349,35 @@ fn main() { (n / d + if (n % d).abs() < (n / 2).abs() { 0 } else { 1 }) as i32 } + canvas.start_events(tx); + thread::spawn(move || { + let mut deg :i32 = 0; loop { - tx1.send(0).unwrap(); - thread::sleep(time::Duration::from_millis(10)); + let rot :TMatrix = rotate_z(deg) * rotate_x(-deg); + + let Vector(ix, iy, _) = rot.apply(&i); + let Vector(jx, jy, _) = rot.apply(&j); + let Vector(kx, ky, _) = rot.apply(&k); + + let pg = Polygon( + Coordinates(vec!( Coordinate(to_i32(ix), to_i32(iy)) + , Coordinate(to_i32(jx), to_i32(jy)) + , Coordinate(to_i32(kx), to_i32(ky)) ))); + canvas.clear(); + canvas.draw(&pg, Coordinate(75,75)); + canvas.show(); + + deg = (deg + 1) % 360; + + thread::sleep(time::Duration::from_millis(5)); } }); - let mut deg :i32 = 0; - for x in rx { match x { 1 => break, - _ => { - let rot :TMatrix = rotate_z(deg); - let Vector(ix, iy, _) = rot.apply(&i); - let Vector(jx, jy, _) = rot.apply(&j); - let Vector(kx, ky, _) = rot.apply(&k); - - let pg = Polygon( - Coordinates(vec!( Coordinate(to_i32(ix), to_i32(iy)) - , Coordinate(to_i32(jx), to_i32(jy)) - , Coordinate(to_i32(kx), to_i32(ky)) ))); - - canvas.clear(); - canvas.draw(&pg, Coordinate(75,75)); - canvas.show(); - deg = (deg + 3) % 359; - }, + _ => {}, } } }