MCPcopy Index your code
hub / github.com/arrayfire/arrayfire-rust / conways_game_of_life

Function conways_game_of_life

examples/conway.rs:13–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11}
12
13fn 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}

Callers 1

mainFunction · 0.85

Calls 3

is_closedMethod · 0.80
draw_imageMethod · 0.80
normaliseFunction · 0.70

Tested by

no test coverage detected