Commit 6743cf29851398107d818eb87aaa2431d938e894

Authored by Georg Hopp
1 parent f06b6259

Move drawing to separate thread

Showing 1 changed file with 21 additions and 22 deletions
@@ -339,8 +339,6 @@ fn main() { @@ -339,8 +339,6 @@ fn main() {
339 canvas.init_events(); 339 canvas.init_events();
340 340
341 let (tx, rx) = mpsc::channel(); 341 let (tx, rx) = mpsc::channel();
342 - let tx1 = mpsc::Sender::clone(&tx);  
343 - canvas.start_events(tx);  
344 342
345 let i = Vector(Fractional( 0,1), Fractional(-35,1), Fractional(0,1)); 343 let i = Vector(Fractional( 0,1), Fractional(-35,1), Fractional(0,1));
346 let j = Vector(Fractional( 30,1), Fractional( 17,1), Fractional(0,1)); 344 let j = Vector(Fractional( 30,1), Fractional( 17,1), Fractional(0,1));
@@ -351,34 +349,35 @@ fn main() { @@ -351,34 +349,35 @@ fn main() {
351 (n / d + if (n % d).abs() < (n / 2).abs() { 0 } else { 1 }) as i32 349 (n / d + if (n % d).abs() < (n / 2).abs() { 0 } else { 1 }) as i32
352 } 350 }
353 351
  352 + canvas.start_events(tx);
  353 +
354 thread::spawn(move || { 354 thread::spawn(move || {
  355 + let mut deg :i32 = 0;
355 loop { 356 loop {
356 - tx1.send(0).unwrap();  
357 - thread::sleep(time::Duration::from_millis(10)); 357 + let rot :TMatrix<Fractional> = rotate_z(deg) * rotate_x(-deg);
  358 +
  359 + let Vector(ix, iy, _) = rot.apply(&i);
  360 + let Vector(jx, jy, _) = rot.apply(&j);
  361 + let Vector(kx, ky, _) = rot.apply(&k);
  362 +
  363 + let pg = Polygon(
  364 + Coordinates(vec!( Coordinate(to_i32(ix), to_i32(iy))
  365 + , Coordinate(to_i32(jx), to_i32(jy))
  366 + , Coordinate(to_i32(kx), to_i32(ky)) )));
  367 + canvas.clear();
  368 + canvas.draw(&pg, Coordinate(75,75));
  369 + canvas.show();
  370 +
  371 + deg = (deg + 1) % 360;
  372 +
  373 + thread::sleep(time::Duration::from_millis(5));
358 } 374 }
359 }); 375 });
360 376
361 - let mut deg :i32 = 0;  
362 -  
363 for x in rx { 377 for x in rx {
364 match x { 378 match x {
365 1 => break, 379 1 => break,
366 - _ => {  
367 - let rot :TMatrix<Fractional> = rotate_z(deg);  
368 - let Vector(ix, iy, _) = rot.apply(&i);  
369 - let Vector(jx, jy, _) = rot.apply(&j);  
370 - let Vector(kx, ky, _) = rot.apply(&k);  
371 -  
372 - let pg = Polygon(  
373 - Coordinates(vec!( Coordinate(to_i32(ix), to_i32(iy))  
374 - , Coordinate(to_i32(jx), to_i32(jy))  
375 - , Coordinate(to_i32(kx), to_i32(ky)) )));  
376 -  
377 - canvas.clear();  
378 - canvas.draw(&pg, Coordinate(75,75));  
379 - canvas.show();  
380 - deg = (deg + 3) % 359;  
381 - }, 380 + _ => {},
382 } 381 }
383 } 382 }
384 } 383 }
Please register or login to post a comment