Sunday, 29 April 2012

Program in C++ to illustrate Graphics


#include <iostream>
#include <assert.h>

const int X = 40; 
const int Y = 60; 
char g[X / 8][Y];

inline void set(const int x,const int y)
{
    assert((x >= 0) && (x < X));
    assert((y >= 0) && (y < Y));
    g[(x)/8][y] |= static_cast<char>(0x80 >>((x)%8));
}

int main(  )
{
    int   i;        
    void  print(  ); 

    for (i = 0; i < X; ++i)
        set(i, i);

    print(  );
    return (0);
}

void print(  )
{
    int x;   
    int y;    
    int bit;  

    for (y = 0; y < Y; ++y) {

        
        for (x = 0; x < X / 8; ++x) {

  
            for (bit = 0x80; bit > 0; bit = (bit >> 1)) {
                assert((x >= 0) && (x < (X/8)));
                assert((y >= 0) && (y < Y));

                if ((g[x][y] & bit) != 0)
                    std::cout << 'X';
                else
                    std::cout << '.';
            }
        }
        std::cout << '\n';
    }
}

No comments:

Post a Comment