#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstring>
int main( int argc, char *argv[] )
{
if ( argc == 2 && !strcmp(argv[1],"-h") ) {
cout << "Usage: arithmetic [word] \n\n"
" Where letters of word are in {a, b, c, d, e}\n\n";
exit(0);
}
char the_string[1024] = "cccccccbb";
if ( argc == 2 ) {
Tools::secured_strncpy( the_string, argv[1], 1024 );
}
double proba[100] = { 0.2, 0.1, 0.6, 0.05, 0.05 };
double lefts[100] = { 0, 0.2, 0.3, 0.9, 0.95 };
char *pc = the_string;
int h = 0;
double thickness = 0.5 / strlen( the_string );
double left = 0;
double width = 1.0;
double w = 1.0;
double n = 1;
char str[20];
while ( *pc ) {
int i = *pc - 'a';
left += width * lefts[ i ];
width *= proba[i];
w /= 2.0;
n *= 2;
for ( int k = 0; k < n; k++ )
board.
drawRectangle( left, -h * thickness, width, 0.9*thickness );
secured_sprintf( str, 20, "%c", *pc );
board.
drawText( (left + width/2.0 ), -(h+0.5) * thickness, str );
++h;
++pc;
}
for ( int k = 0; k < 5; k++ ) {
board.
drawRectangle( lefts[k], thickness, proba[k], 0.9*thickness );
}
board.
save(
"arithmetic_A4.eps", Board::A4, 0.5, Board::UCentimeter );
board.
save(
"arithmetic.eps", Board::BoundingBox, 0.5, Board::UCentimeter );
board.
save(
"arithmetic_A4.svg", Board::A4, 2, Board::UCentimeter );
board.
save(
"arithmetic.fig", Board::A4 );
board.
save(
"arithmetic.svg", Board::BoundingBox, 0.0, Board::UCentimeter );
}