/*
Patricks tree creator.
Draws a tree in the console window!
Patrick O'Grady 09.22.2012.1949
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <windows.h>
usingnamespace std;
//create a pseuodo random tree for the amusment of the user.
constchar* RandomTree(int Seed)
{
srand(Seed);
int RandomTreeType = rand() % 10 + 1;
switch(RandomTreeType)
{
case 0:
return"Pinus Armandii";
case 1:
return"Saylix Babylonica";
case 2:
return"Abies Firma";
case 3:
return"Cornus Kousa";
case 4:
return"Davidia Involucrata";
case 5:
return"Evodia Damiellii";
case 6:
return"Betula Grossa";
case 7:
return"Cercidiphyllum Japonicium";
case 8:
return"Betula Papyrifera";
case 9:
return"Clerodendrum Trichotomum";
default:
return"Corylorsis Glabrescens";
};
return"No Tree";
};
int main()
{
//the height of the tree
int h = 0;
char Answer = 'y';
//get a handle to the console
HANDLE Console = 0;
Console = GetStdHandle(STD_OUTPUT_HANDLE);
//brighten the console up a little
SetConsoleTextAttribute(Console, 15);
cout<<"Welcome to Patricks Tree Creator!\n"<<endl;
while(Answer == 'y')
{
cout<<"Please enter the height of your tree: ";
cin>>h;
cout<<endl;
//set the color of the text to green to draw the tree
SetConsoleTextAttribute(Console, 2);
//draw the tree
cout<<setw(h)<<"^"<<endl;
for(int i = 1; i <= h-1; i++)
{
cout<<setw(h-i);
for(int y = 0; y <= i+(i*1); y++)
{
cout<<"^";
}
cout<<endl;
}
SetConsoleTextAttribute(Console, 6);
//draw the trunk and base.
cout<<setw(h)<<"#"<<endl;
cout<<setw(h)<<"#"<<endl;
cout<<setw(h)<<"#"<<endl;
cout<<setw(h)<<"#"<<endl;
cout<<setfill('_')<<setw(h*2)<<"______"<<endl;
cout<<setfill(' ');
SetConsoleTextAttribute(Console, 15);
cout<<"\nNice tree! Is that a "<<RandomTree(time(0))<<"?"<<"\nWant to make another one (y/n)?";
cin>>Answer;
if(Answer == 'y')
cout<<"Need more bark for your bite huh?"<<endl;
}
cout<<"\nThanks for playing the tree creator!\n"<<endl;
cout<<"Tree names taken from http://www.ces.ncsu.edu/depts/hort/consumer/factsheets/trees-new/scientific_namesa_e.html. Thanks!\n"<<endl;
cout<<"Press 'e' to exit: ";
cin>>h;
return 0;
}
/*
Patricks tree creator.
Draws a tree in the console window!
Patrick O'Grady 09.22.2012.1949
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <windows.h>
#include <time.h>
usingnamespace std;
//create a pseuodo random tree for the amusment of the user.
constchar* RandomTree(int Seed)
{
srand(Seed);
int RandomTreeType = rand() % 10 + 1;
switch(RandomTreeType)
{
case 0:
return"Pinus Armandii";
case 1:
return"Saylix Babylonica";
case 2:
return"Abies Firma";
case 3:
return"Cornus Kousa";
case 4:
return"Davidia Involucrata";
case 5:
return"Evodia Damiellii";
case 6:
return"Betula Grossa";
case 7:
return"Cercidiphyllum Japonicium";
case 8:
return"Betula Papyrifera";
case 9:
return"Clerodendrum Trichotomum";
default:
return"Corylorsis Glabrescens";
};
return"No Tree";
};
int main()
{
//the height of the tree
int h = 0;
char Answer = 'y';
//get a handle to the console
HANDLE Console = 0;
Console = GetStdHandle(STD_OUTPUT_HANDLE);
//brighten the console up a little
SetConsoleTextAttribute(Console, 15);
cout<<"Welcome to Patricks Tree Creator!\n"<<endl;
while(Answer == 'y')
{
cout<<"Please enter the height of your tree (10-20 is a good size): ";
//check if input is valid
if(!(cin>>h))
{
cin.clear();
cin.ignore(100, '\n');
continue;
}
cout<<endl;
//set the color of the text to green to draw the tree
SetConsoleTextAttribute(Console, 2);
//draw the tree
cout<<setw(h)<<"^"<<endl;
for(int i = 1; i <= h-1; i++)
{
cout<<setw(h-i);
for(int y = 0; y <= i+(i*1); y++)
{
cout<<"^";
}
cout<<endl;
}
SetConsoleTextAttribute(Console, 6);
//draw the trunk and base.
cout<<setw(h)<<"#"<<endl;
cout<<setw(h)<<"#"<<endl;
cout<<setw(h)<<"#"<<endl;
cout<<setw(h)<<"#"<<endl;
cout<<setfill('_')<<setw(h*2)<<"______"<<endl;
cout<<setfill(' ');
SetConsoleTextAttribute(Console, 15);
cout<<"\nNice tree! Is that a "<<RandomTree(time(0))<<"?"<<"\nWant to make another one (y/n)?";
cin>>Answer;
if(Answer == 'y')
cout<<"Need more bark for your bite huh?"<<endl;
}
cout<<"\nThanks for playing the tree creator!\n"<<endl;
cout<<"Tree names taken from http://www.ces.ncsu.edu/depts/hort/consumer/factsheets/trees-new/scientific_namesa_e.html. Thanks!\n"<<endl;
cout<<"Press 'e' to exit: ";
cin>>h;
return 0;
}