Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Make main thread open the window.
Browse files Browse the repository at this point in the history
Fixes #56. Exercises need to be rebuild.
  • Loading branch information
Martin Brösamle committed Sep 23, 2016
1 parent c0e2de8 commit 3d09a99
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions workshops/mondrian-pattern/codebase/mondpaint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,36 @@ const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];
fn main() {
let (paintsend, paintrecv) = mpsc::channel();

let serverthread = thread::spawn(move || {
// Change this to OpenGL::V2_1 if not working.
let opengl = OpenGL::V3_2;

// Construct the window.
let mut window: PistonWindow =
WindowSettings::new("RustBridge / Mondrian Pattern Generator", [400, 720])
.opengl(opengl).samples(4).exit_on_esc(true).build().unwrap();
window.set_ups(60);

let mut canvas: Vec<(types::Rectangle, types::Color)> = Vec::new();
while let Some(e) = window.next() {
if let Ok( tobepainted ) = paintrecv.try_recv() {
canvas.push( tobepainted );
println!("Painter received: {:?}", tobepainted );
}
window.draw_2d(&e, |c, gl| {
clear(WHITE, gl);
let redrect = graphics::Rectangle::new(WHITE).border(graphics::rectangle::Border{color :BLACK, radius :2.0});
for item in (&canvas).iter() {
let (rct, col) = *item;
redrect.color(col).draw(rct, &c.draw_state, c.transform, gl);
}
});
}
});
let chn = paintsend.clone();
let painterthread = thread::spawn(move ||
paint_rectangle(20.0, 20.0, 300.0, 250.0, chn)
);

// Change this to OpenGL::V2_1 if not working.
let opengl = OpenGL::V3_2;

// Construct the window.
let mut window: PistonWindow =
WindowSettings::new("RustBridge / Mondrian Pattern Generator", [400, 720])
.opengl(opengl).samples(4).exit_on_esc(true).build().unwrap();
window.set_ups(60);

let mut canvas: Vec<(types::Rectangle, types::Color)> = Vec::new();
while let Some(e) = window.next() {
if let Ok( tobepainted ) = paintrecv.try_recv() {
canvas.push( tobepainted );
println!("Painter received: {:?}", tobepainted );
}
window.draw_2d(&e, |c, gl| {
clear(WHITE, gl);
let redrect = graphics::Rectangle::new(WHITE).border(graphics::rectangle::Border{color :BLACK, radius :2.0});
for item in (&canvas).iter() {
let (rct, col) = *item;
redrect.color(col).draw(rct, &c.draw_state, c.transform, gl);
}
});
}
painterthread.join().unwrap();
serverthread.join().unwrap();
}


Expand Down

0 comments on commit 3d09a99

Please sign in to comment.