The color of each pixel is calculated as X OP Y, where X is the X coordinate of the pixel and Y is the Y coordinate of the pixel, and OP represents the boolean function that's being implemented. The code follows the images...
















The main generation loop:
for(int b = 0; b < 16; b++)
{
sprintf(filename, "out%d.bmp", b);
Renderer *r = new BMPRenderer(g, filename);
TruthTable *tt = new TruthTable(b);
for(int y = 0; y < g->getHeight(); y++)
{
for(int x = 0; x < g->getWidth(); x++)
{
int color = tt->getResultByte(x, y);
int R = (color & 0x00FF0000) >> 16;
int G = (color & 0x0000FF00) >> 8;
int B = (color & 0x000000FF);
g->putPixel(x, y,
(unsigned char)R,
(unsigned char)G,
(unsigned char)B);
}
}
r->render();
}
The TruthTable class:
#include <iostream>
using namespace std;
#define TABLE_SIZE 4
class TruthTable
{
int theTable[TABLE_SIZE];
public:
TruthTable(int table);
virtual ~TruthTable();
int getResultBit(int x, int y);
unsigned char getResultByte(unsigned char x, unsigned char y);
};
TruthTable::TruthTable(int table)
{
int mask = 0x01;
for(int i = 0; i < TABLE_SIZE; i++)
{
int result = (table & mask) >> i;
this->theTable[i] = result;
mask = mask << 1;
}
}
TruthTable::~TruthTable()
{
}
int TruthTable::getResultBit(int x, int y)
{
int mask = 0x01;
int index = ((x & mask) << 1) | (y & mask);
return this->theTable[index];
}
unsigned char TruthTable::getResultByte(unsigned char x, unsigned char y)
{
int mask = 0x01;
int result = 0;
for(int i = 0; i < 8; i++)
{
int bit_x = (x & mask) >> i;
int bit_y = (y & mask) >> i;
int bit_result = this->getResultBit(bit_x, bit_y);
result = result | (bit_result << i);
mask = mask << 1;
}
return result;
}