#include <iostream>
#include <cmath>  // for std::abs

const int PLANE_WIDTH = 11;
const int PLANE_HEIGHT = 10;

void point( int x1, int y1, char plane[PLANE_HEIGHT][PLANE_WIDTH] );
void tessellate( int x1, int y1, int x2, int y2, char plane[PLANE_HEIGHT][PLANE_WIDTH] );
void display( char plane[PLANE_HEIGHT][PLANE_WIDTH] );

void main()
{
    static char plane[PLANE_HEIGHT][PLANE_WIDTH] = {
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' }
    };

    int x1;
    int y1;
    int x2;
    int y2;

    for(;;) {
        std::cout << "segment points: ";   // prompt for input
        std::cin >> x1 >> y1 >> x2 >> y2;  // get segment coordinates
        point( x1, y1, plane );            // draw first point
        point( x2, y2, plane );            // draw second point
        tessellate( x1, y1, x2, y2, plane ); // connect points
        display( plane );                  // display results
    }
}

// Mark point on the plane
void point( int xx, int yy, char plane[PLANE_HEIGHT][PLANE_WIDTH] )
{
    plane[yy][xx] = 'X';
}

// Connect two points
void tessellate( int x1, int y1, int x2, int y2, char plane[PLANE_HEIGHT][PLANE_WIDTH] )
{
    if ( std::abs( x1 - x2 ) < 2 && std::abs( y1 - y2 ) < 2 )
        // Nothing else left to do, two points are next to each other:
        return;

    // find center
    int cx = ( x1 + x2 )/2;
    int cy = ( y1 + y2 )/2;

    // mark center
    plane[cy][cx] = '*';

    // recurse and repeat
    tessellate( x1, y1, cx, cy, plane );
    tessellate( x2, y2, cx, cy, plane );
}

// Print content of the plane array
void display( char plane[PLANE_HEIGHT][PLANE_WIDTH] )
{
    for ( int yy = 0; yy < PLANE_HEIGHT; ++yy )
        for ( int xx = 0; xx < PLANE_WIDTH; ++xx )
            std::cout << plane[yy][xx];
}