1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Drawing
{
vector<string> canvas;
int ROWS, COLS;
public:
Drawing( int r, int c ) : ROWS( r ), COLS( c ) { canvas = vector<string>( r, string( c, ' ' ) ); }
void print() { for ( string s : canvas ) cout << s << '\n'; }
void rectangle( int i0, int j0, int ni, int nj, char c )
{
for ( int i = max( i0, 0); i < min( i0 + ni, ROWS ); i++ )
{
for ( int j = max( j0, 0 ); j < min( j0 + nj, COLS ); j++ ) canvas[i][j] = c;
}
}
void lookRight( int i0, int j0, int right, char c )
{
for ( int j = j0, i1 = i0 - right + 1, i2 = i0 + right - 1; j < j0 + right; j++, i1++, i2-- )
{
for ( int i = i1; i <= i2; i++ )
{
if ( i >= 0 && i < ROWS && j >= 0 && j < COLS ) canvas[i][j] = c;
}
}
}
};
void arrow( int L, int W, int I, int O, int X, char c ) // W must be odd
{
int rref = max( X, I - O + 1 );
int mid = rref + ( W - 1 ) / 2;
int height = W + 2 * rref;
int width = I + L + X + ( W + 1 ) / 2;
Drawing drawing( height, width );
// Feathers
drawing.rectangle( rref - ( I - O + 1 ), 0, W + 2 * ( I - O + 1 ), O, c );
drawing.lookRight( mid, O, I - O + ( W + 1 ) / 2, c );
// Shaft
drawing.rectangle( rref, I, W, L, c );
// Head
drawing.lookRight( mid, I + L, X + ( W + 1 ) / 2, c );
drawing.print();
}
int main()
{
arrow( 10, 3, 7, 3, 4, '*' );
}
|