#include <cstdio>
#include <iostream>
int main(int, char**) {
try {
static const float h_kernel[] = {1, 1, 1, 1, 0, 1, 1, 1, 1};
static const int reset = 500;
static const int game_w = 128, game_h = 128;
std::cout << "This example demonstrates the Conway's Game of Life "
"using ArrayFire"
<< std::endl
<< "There are 4 simple rules of Conways's Game of Life"
<< std::endl
<< "1. Any live cell with fewer than two live neighbours "
"dies, as if caused by under-population."
<< std::endl
<< "2. Any live cell with two or three live neighbours lives "
"on to the next generation."
<< std::endl
<< "3. Any live cell with more than three live neighbours "
"dies, as if by overcrowding."
<< std::endl
<< "4. Any dead cell with exactly three live neighbours "
"becomes a live cell, as if by reproduction."
<< std::endl
<< "Each white block in the visualization represents 1 alive "
"cell, black space represents dead cells"
<< std::endl;
af::Window myWindow(512, 512,
"Conway's Game of Life using ArrayFire");
int frame_count = 0;
while (!myWindow.
close()) {
frame_count++;
if (frame_count % reset == 0)
state = state * C0 + C1;
}
fprintf(stderr,
"%s\n", e.
what());
throw;
}
return 0;
}
Window object to render af::arrays.
A multi dimensional data container.
An ArrayFire exception class.
virtual const char * what() const
Returns an error message for the exception in a string format.
@ f32
32-bit floating point values
void image(const array &in, const char *title=NULL)
Renders the input array as an image to the window.
bool close()
Check if window is marked for close.
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers uniformly distributed.