#include <iostream>
#include <cstdio>
int main(int argc, char *argv[])
{
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
;
std::cout << "The conway_pretty example visualizes all the states in Conway" << std::endl
<< "Red : Cells that have died due to under population" << std::endl
<< "Yellow: Cells that continue to live from previous state" << std::endl
<< "Green : Cells that are new as a result of reproduction" << std::endl
<< "Blue : Cells that have died due to over population" << std::endl
;
std::cout << "This examples is throttled so as to be a better visualization" << std::endl;
af::Window simpleWindow(512, 512,
"Conway's Game Of Life - Current State");
af::Window prettyWindow(512, 512,
"Conway's Game Of Life - Visualizing States");
int frame_count = 0;
while(!simpleWindow.
close() && !prettyWindow.
close()) {
if(!simpleWindow.
close()) simpleWindow.
image(state);
if(!prettyWindow.
close()) prettyWindow.
image(display);
frame_count++;
if(frame_count % reset == 0)
array a0 = (state == 1) && (nHood < 2);
array a1 = (state != 0) && (C0 || C1);
array a2 = (state == 0) && C1;
array a3 = (state == 1) && (nHood > 3);
display =
join(2, a0 + a1, a1 + a2, a3).
as(
f32);
state = state * C0 + C1;
double fps = 30;
while(timer::stop(delay) < (1 / fps)) { }
}
fprintf(stderr,
"%s\n", e.
what());
throw;
}
return 0;
}
Window object to render af::arrays.
Definition: graphics.h:37
A multi dimensional data container.
Definition: array.h:27
Definition: exception.h:20
virtual const char * what() const
Definition: exception.h:34
@ f32
32-bit floating point values
Definition: defines.h:196
@ afHost
Host pointer.
Definition: defines.h:216
AFAPI array randu(const dim4 &dims, const dtype ty=f32)
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.
void setPos(const unsigned x, const unsigned y)
Set the start position where the window will appear.
AFAPI array join(const int dim, const array &first, const array &second)
Join 2 arrays along dim.
AFAPI array tile(const array &in, const unsigned x, const unsigned y=1, const unsigned z=1, const unsigned w=1)
const array as(dtype type) const
Converts the array into another type.
AFAPI array convolve(const array &signal, const array &filter, const convMode mode=AF_CONV_DEFAULT, const convDomain domain=AF_CONV_AUTO)
C++ Interface for convolution any(one through three) dimensional signals.
Definition: algorithm.h:15
Internal timer object.
Definition: timing.h:29