()
| 11 | } |
| 12 | |
| 13 | fn conways_game_of_life() { |
| 14 | let h_kernel = [1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0]; |
| 15 | let kernel = Array::new(&h_kernel, Dim4::new(&[3, 3, 1, 1])); |
| 16 | let s = constant::<f32>(0.5, Dim4::new(&[1, 1, 1, 1])); |
| 17 | let mut state = gt(&randu::<f32>(Dim4::new(&[256, 256, 3, 1])), &s, false); |
| 18 | let c0 = constant::<f32>(2.0, Dim4::new(&[1, 1, 1, 1])); |
| 19 | let c1 = constant::<f32>(3.0, Dim4::new(&[1, 1, 1, 1])); |
| 20 | |
| 21 | let win = Window::new(512, 512, "Game of Life".to_string()); |
| 22 | while !win.is_closed() { |
| 23 | let n_hood = convolve2(&state, &kernel, ConvMode::DEFAULT, ConvDomain::SPATIAL); |
| 24 | let c0 = &eq(&n_hood, &c0, false); |
| 25 | let c1 = &eq(&n_hood, &c1, false); |
| 26 | state = state * c0 + c1; |
| 27 | win.draw_image(&normalise(&state.cast::<f32>()), None); |
| 28 | } |
| 29 | } |
no test coverage detected